[llvm] [OFFLOAD] Add support for indexed per-thread containers (PR #164263)
Alex Duran via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 19 05:40:12 PST 2025
================
@@ -91,24 +177,114 @@ template <typename ContainerType, typename ObjectType> struct PerThreadTable {
// Iterators to traverse objects owned by
// the current thread
iterator begin() {
- auto &Entry = getThreadEntry();
+ ContainerType &Entry = getThreadEntry();
return Entry.begin();
}
iterator end() {
- auto &Entry = getThreadEntry();
+ ContainerType &Entry = getThreadEntry();
return Entry.end();
}
- template <class F> void clear(F f) {
- std::lock_guard<std::mutex> Lock(Mtx);
- for (auto ThData : ThreadDataList) {
- if (!ThData->ThEntry || ThData->NElements == 0)
+ template <class ClearFuncTy> void clear(ClearFuncTy ClearFunc) {
+ assert(Mutex.try_lock() && (Mutex.unlock(), true) &&
+ "Clear cannot be called while other threads are adding entries");
+ for (std::shared_ptr<PerThreadData> ThreadData : ThreadDataList) {
+ if (!ThreadData->ThreadEntry || ThreadData->NElements == 0)
continue;
- ThData->ThEntry->clear(f);
- ThData->NElements = 0;
+ if constexpr (has_clearAll<ContainerType>::value) {
+ ThreadData->ThreadEntry->clearAll(ClearFunc);
----------------
adurang wrote:
It's something used for non-STL containers but none are upstream right now. I'll remove it.
https://github.com/llvm/llvm-project/pull/164263
More information about the llvm-commits
mailing list