24 #ifndef _GEMA_THREAD_LOCAL_BUFFER_H_ 25 #define _GEMA_THREAD_LOCAL_BUFFER_H_ 44 T* buffer =
new T[n * nt];
45 for(
int i = 0; i < nt; i++, buffer += n)
68 for(
int i = 0; i < nt; i++)
70 T* ptr = (T*)(rawbuffer + i*tsize);
74 GmConstructObjectsInMemory<T>(ptr, n);
84 for(
int i = 0; i<nt; i++)
85 GmDestroyObjectsInMemory<T>(tls.
localData(i), n);
105 template <
class T,
bool Align = false>
class GmTLBuffer 157 for(
int j = 0; j <
_n; j++)
#define GM_CACHE_LINE_SIZE
Cache line size. TODO: Get this from a configuration parameter.
Definition: gmMemory.h:35
void setSize(int n, const T &defVal)
Set buffer size for a default constructed buffer and initializes the contents to defVal.
Definition: gmThreadLocalBuffer.h:134
void * GmAlignedMallocThrow(size_t size, size_t align)
A version of GmAlignedMalloc that throws a bad_alloc exception on failure.
Definition: gmMemory.h:65
Declaration of the GmTLS class.
A class similar to GmTLS that creates a buffer for each possible thread in the GmThreadManager,...
Definition: gmValueSetData.h:43
GmTLBuffer(int n)
Constructor. Each thread buffer will store n entries of type T.
Definition: gmThreadLocalBuffer.h:116
int _n
The size of each buffer.
Definition: gmThreadLocalBuffer.h:171
static void alloc(int n, GmTLS< T * > &tls)
Alloc one buffer with size n for each thread, storing pointers in tls.
Definition: gmThreadLocalBuffer.h:38
void clear()
Clears the allocated buffers returning the object to a default constructed state.
Definition: gmThreadLocalBuffer.h:125
T * localBuffer(int tid)
Returns a pointer to the given thread local buffer.
Definition: gmThreadLocalBuffer.h:140
bool GmIsCacheAligned(void *ptr)
Checks if a pointer is cache aligned or not.
Definition: gmMemory.h:81
T * localBuffer()
Returns a pointer to the current thread local buffer.
Definition: gmThreadLocalBuffer.h:146
const T * localBuffer() const
Returns a const pointer to the current thread local buffer.
Definition: gmThreadLocalBuffer.h:149
~GmTLBuffer()
Destructor.
Definition: gmThreadLocalBuffer.h:122
T & localData(int tid)
Returns the given thread local data as a modifiable reference.
Definition: gmThreadLocalStorage.h:163
const T * localBuffer(int tid) const
Returns a const pointer to the given thread local buffer.
Definition: gmThreadLocalBuffer.h:143
static int currentId()
Returns the id of the current thread, which MUST be either the main thread or a thread created by the...
Definition: gmThreadManager.h:166
void init(const T &val)
Initializes the value for ALL threads with the given value.
Definition: gmThreadLocalStorage.h:153
static void alloc(int n, GmTLS< T * > &tls)
Alloc one cache aligned buffer with size n for each thread, storing pointers in tls.
Definition: gmThreadLocalBuffer.h:57
GmTLBuffer()
Default constructor. Buffer sizes MUST be initialized by a call to setSize()
Definition: gmThreadLocalBuffer.h:113
void setLocalData(int tid, const T &data)
Updates the given thread local data.
Definition: gmThreadLocalStorage.h:183
Aux structure to define the allocation strategy for GmTLBuffer.
Definition: gmThreadLocalBuffer.h:32
int size() const
Returns the buffer size.
Definition: gmThreadLocalBuffer.h:128
GmTLBuffer(int n, const T &defVal)
Constructor. Each thread buffer will store n entries of type T, initialized to defVal.
Definition: gmThreadLocalBuffer.h:119
static void free(int n, GmTLS< T * > &tls)
Releases the memory allocated by alloc.
Definition: gmThreadLocalBuffer.h:79
Implementation of the custom allocator used by Armadillo when memory is needed for matrices and vecto...
GmTLS< T * > _data
The local storage with pointers to each thread buffer. No need to align _data since worker threads wi...
Definition: gmThreadLocalBuffer.h:169
static void free(int n, GmTLS< T * > &tls)
Releases the memory allocated by alloc.
Definition: gmThreadLocalBuffer.h:50
void init(const T &defVal)
Initializes each buffer entry to defVal.
Definition: gmThreadLocalBuffer.h:152
static int maxWorkerThreads()
Returns the maximum number of allowed working threads.
Definition: gmThreadManager.h:153
void resize(int n)
Change buffer size.
Definition: gmThreadLocalBuffer.h:137
void setSize(int n)
Set buffer size for a default constructed buffer.
Definition: gmThreadLocalBuffer.h:131