20 #ifndef GALOIS_SUBSTRATE_PERTHREADSTORAGE_H
21 #define GALOIS_SUBSTRATE_PERTHREADSTORAGE_H
28 #include "galois/config.h"
39 std::atomic<unsigned int> nextLoc{0};
40 std::atomic<char*>* heads{
nullptr};
42 std::vector<std::vector<unsigned>> freeOffsets;
52 void initCommon(
unsigned maxT);
53 static unsigned nextLog2(
unsigned size);
71 void deallocOffset(
const unsigned offset,
const unsigned size);
72 void*
getRemote(
unsigned thread,
unsigned offset);
73 void*
getLocal(
unsigned offset,
char* base) {
return &base[offset]; }
76 void*
getLocal(
unsigned offset,
unsigned id) {
return &heads[id][offset]; }
79 extern thread_local
char*
ptsBase;
82 extern thread_local
char*
pssBase;
105 template <
typename... Args>
112 for (
unsigned n = 0; n < tp.getMaxThreads(); ++n)
123 std::swap(
offset, rhs.offset);
130 return reinterpret_cast<T*
>(ditem);
135 return reinterpret_cast<T*
>(ditem);
141 return reinterpret_cast<T*
>(ditem);
146 return reinterpret_cast<T*
>(ditem);
151 return reinterpret_cast<T*
>(ditem);
156 return reinterpret_cast<T*
>(ditem);
162 template <
typename T>
170 for (
unsigned n = 0; n < tp.getMaxSockets(); ++n)
176 template <
typename... Args>
184 for (
unsigned n = 0; n < tp.getMaxSockets(); ++n)
186 T(std::forward<Args>(args)...);
193 offset = std::move(o.offset);
204 return reinterpret_cast<T*
>(ditem);
209 return reinterpret_cast<T*
>(ditem);
215 return reinterpret_cast<T*
>(ditem);
220 return reinterpret_cast<T*
>(ditem);
225 return reinterpret_cast<T*
>(ditem);
230 return reinterpret_cast<T*
>(ditem);
235 return reinterpret_cast<T*
>(ditem);
240 return reinterpret_cast<T*
>(ditem);
PerSocketStorage & operator=(PerSocketStorage &&o)
Definition: PerThreadStorage.h:191
T * getLocal(unsigned int thread)
Like getLocal() but optimized for when you already know the thread id.
Definition: PerThreadStorage.h:139
PerThreadStorage(PerThreadStorage &&rhs)
Definition: PerThreadStorage.h:116
PerBackend & b
Definition: PerThreadStorage.h:166
~PerSocketStorage()
Definition: PerThreadStorage.h:200
ThreadPool & getThreadPool(void)
return a reference to system thread pool
Definition: ThreadPool.cpp:259
PerBackend & getPPSBackend()
Definition: PerThreadStorage.cpp:36
PerThreadStorage & operator=(PerThreadStorage &&rhs)
Definition: PerThreadStorage.h:122
unsigned offset
Definition: PerThreadStorage.h:91
unsigned getMaxThreads() const
return the number of threads supported by the thread pool on the current machine
Definition: ThreadPool.h:178
void destruct()
Definition: PerThreadStorage.h:168
PerSocketStorage(Args &&...args)
Definition: PerThreadStorage.h:177
void * getLocal(unsigned offset, unsigned id)
Definition: PerThreadStorage.h:76
~PerBackend()
Definition: PerThreadStorage.h:61
T * getLocal()
Definition: PerThreadStorage.h:128
void deallocOffset(const unsigned offset, const unsigned size)
Definition: PerThreadStorage.cpp:126
PerThreadStorage(Args &&...args)
Definition: PerThreadStorage.h:106
const T * getLocal() const
Definition: PerThreadStorage.h:133
Definition: PerThreadStorage.h:36
unsigned size() const
Definition: PerThreadStorage.h:243
PerBackend * b
Definition: PerThreadStorage.h:90
T * getRemoteByPkg(unsigned int pkg)
Definition: PerThreadStorage.h:233
PerBackend & operator=(const PerBackend &)=delete
unsigned offset
Definition: PerThreadStorage.h:165
const T * getLocal() const
Definition: PerThreadStorage.h:207
Definition: PerThreadStorage.h:88
Definition: PerThreadStorage.h:163
void initPTS(unsigned)
Definition: PerThreadStorage.cpp:186
const T * getRemote(unsigned int thread) const
Definition: PerThreadStorage.h:228
T * getLocal()
Definition: PerThreadStorage.h:202
PerBackend & getPTSBackend()
Definition: PerThreadStorage.cpp:29
PerSocketStorage(PerSocketStorage &&o)
Definition: PerThreadStorage.h:189
const T * getLocal(unsigned int thread) const
Definition: PerThreadStorage.h:144
thread_local char * pssBase
Definition: PerThreadStorage.cpp:34
unsigned allocOffset(const unsigned size)
Definition: PerThreadStorage.cpp:71
unsigned size() const
Definition: PerThreadStorage.h:159
const T * getRemote(unsigned int thread) const
Definition: PerThreadStorage.h:154
SimpleLock is a spinlock.
Definition: SimpleLock.h:36
PerBackend()
Definition: PerThreadStorage.cpp:58
T * getRemote(unsigned int thread)
Definition: PerThreadStorage.h:223
const T * getLocal(unsigned int thread) const
Definition: PerThreadStorage.h:218
void * getLocal(unsigned offset, char *base)
Definition: PerThreadStorage.h:73
thread_local char * ptsBase
Definition: PerThreadStorage.cpp:27
void * getRemote(unsigned thread, unsigned offset)
Definition: PerThreadStorage.cpp:147
T * getRemote(unsigned int thread)
Definition: PerThreadStorage.h:149
char * initPerThread(unsigned maxT)
Definition: PerThreadStorage.cpp:161
void destruct()
Definition: PerThreadStorage.h:93
char * initPerSocket(unsigned maxT)
Definition: PerThreadStorage.cpp:168
T * getLocal(unsigned int thread)
Like getLocal() but optimized for when you already know the thread id.
Definition: PerThreadStorage.h:213
~PerThreadStorage()
Definition: PerThreadStorage.h:120
const T * getRemoteByPkg(unsigned int pkg) const
Definition: PerThreadStorage.h:238