Skip to content

Commit 0d3d6dc

Browse files
committed
Add deinit method
1 parent e0c46a6 commit 0d3d6dc

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

offload/include/PerThreadTable.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <list>
1717
#include <llvm/ADT/SmallVector.h>
18+
#include <llvm/Support/Error.h>
1819
#include <memory>
1920
#include <mutex>
2021
#include <type_traits>
@@ -205,6 +206,24 @@ template <typename ContainerType, typename ObjectType> struct PerThreadTable {
205206
}
206207
ThreadDataList.clear();
207208
}
209+
210+
template <class F> llvm::Error deinit(F f) {
211+
std::lock_guard<std::mutex> Lock(Mtx);
212+
for (auto ThData : ThreadDataList) {
213+
if (!ThData->ThEntry || ThData->NElements == 0)
214+
continue;
215+
for (auto &Obj : *ThData->ThEntry) {
216+
if constexpr (is_associative<ContainerType>::value) {
217+
if (auto Err = f(Obj.second))
218+
return Err;
219+
} else {
220+
if (auto Err = f(Obj))
221+
return Err;
222+
}
223+
}
224+
}
225+
return llvm::Error::success();
226+
}
208227
};
209228

210229
template <typename T, typename = std::void_t<>> struct ContainerValueType {

0 commit comments

Comments
 (0)