27 #include <type_traits>
32 class managedPtr_Unit_ChunkInUse_Test;
33 class managedPtr_Unit_GetLocPointer_Test;
34 class managedPtr_Unit_SmartPointery_Test;
35 class managedFileSwap_Unit_SwapSingleIsland_Test;
36 class managedFileSwap_Unit_SwapNextAndSingleIsland_Test;
38 class adhereTo_Unit_LoadUnload_Test;
39 class adhereTo_Unit_LoadUnloadConst_Test;
40 class adhereTo_Unit_TwiceAdhered_Test;
41 class adhereTo_Unit_TwiceAdheredOnceUsed_Test;
53 #define ADHERETO(class,instance) adhereTo<class> instance##_glue(instance);\
54 class* instance = instance##_glue;
55 #define ADHERETOCONST(class,instance) const adhereTo<class> instance##_glue(instance);\
57 const class* instance = instance##_glue;
58 #define ADHERETOLOC(class,instance,locinstance) adhereTo<class> instance##_glue(instance);\
60 class* locinstance = instance##_glue;
61 #define ADHERETOLOCCONST(class,instance,locinstance) const adhereTo<class> instance##_glue(instance);\
63 const class* locinstance = instance##_glue;
79 template <
class T,
int dim = 1>
86 for (
unsigned int i = 0; i <
n_elem; ++i ) {
92 template <
typename... ctor_args>
94 for (
unsigned int i = 0; i <
n_elem; ++i ) {
112 for (
int i = 0; i <
n_elem; ++i ) {
150 rambrain_atomic_add_fetch ( tracker, 1 );
157 template <
typename... ctor_args>
160 tracker =
new unsigned int;
168 #ifdef PARENTAL_CONTROL
204 #ifdef PARENTAL_CONTROL
211 for (
unsigned int n = 0; n <
n_elem; n++ ) {
212 new ( ( ( T * ) chunk->locPtr ) + n ) T ( Args... );
215 #ifdef PARENTAL_CONTROL
227 int trackerold = rambrain_atomic_sub_fetch ( tracker, 1 );
228 if ( trackerold == 0 ) {
234 inline unsigned int size()
const {
245 bool setUse (
bool writable =
true,
bool *tracker = NULL )
const {
247 if ( !rambrain_atomic_bool_compare_and_swap ( tracker,
false,
true ) ) {
264 if ( ref.
chunk == chunk ) {
267 if ( rambrain_atomic_sub_fetch ( tracker, 1 ) == 0 ) {
274 rambrain_atomic_add_fetch ( tracker, 1 );
281 ADHERETOLOC ( T,
self, loc );
287 ADHERETOLOCCONST ( T,
self, loc );
298 return ( T * ) chunk->locPtr;
308 return ( T * ) chunk->locPtr;
318 typename std::enable_if<std::is_class<G>::value>::type
323 for (
unsigned int n = 0; n <
n_elem; n++ ) {
324 ( ( ( G * ) chunk->
locPtr ) + n )->~G();
333 typename std::enable_if < !std::is_class<G>::value >::type
363 friend class adhereToConst;
367 friend class ::managedPtr_Unit_ChunkInUse_Test;
368 friend class ::managedPtr_Unit_GetLocPointer_Test;
369 friend class ::managedPtr_Unit_SmartPointery_Test;
370 friend class ::managedFileSwap_Unit_SwapSingleIsland_Test;
371 friend class ::managedFileSwap_Unit_SwapNextAndSingleIsland_Test;
372 friend class ::adhereTo_Unit_TwiceAdheredOnceUsed_Test;
408 if ( loadImmediately && data.size() != 0 ) {
439 operator const T *() {
440 return * ( (
const adhereTo * )
this );
443 operator const T *()
const {
444 if (
data->size() == 0 ) {
450 return data->getConstLocPtr();
454 if (
data->size() == 0 ) {
460 return data->getLocPtr();
464 unsigned char loaded = 0;
466 if ( loaded > 0 &&
data->size() != 0 ) {
467 data->unsetUse ( loaded );
478 friend class ::adhereTo_Unit_LoadUnload_Test;
479 friend class ::adhereTo_Unit_LoadUnloadConst_Test;
480 friend class ::adhereTo_Unit_TwiceAdhered_Test;
481 friend class ::adhereTo_Unit_TwiceAdheredOnceUsed_Test;
505 rambrain_pthread_mutex_unlock ( &
mutex );
509 rambrain_pthread_mutex_lock ( &
mutex );
518 #define LISTOFINGREDIENTS rambrainGlobalCriticalSectionControl rambrain_section_control;
managedPtr< T, dim-1 > * subPtrs
adhereTo(const managedPtr< T > *data, bool loadImmediately=true)
Provides the same functionality as the other constructor but accepts a managedPtr pointer as argument...
Main class to allocate memory that is managed by the rambrain memory defaultManager in a multidimensi...
adhereTo< T > & operator=(const adhereTo< T > &ref)
Simple assignment operator.
memoryID id
an ID to identify the object in scheduler or elsewhere
const T * getConstLocPtr() const
returns const local pointer to object
void * locPtr
pointer to the actual data in RAM
bool setUse(memoryID id)
Convenience interface for setUse( managedMemoryChunk &chunk, bool writeAccess )
Main class to fetch memory that is managed by rambrain for actual usage.
adhereTo(const adhereTo< T > &ref)
copy constructor
bool prepareUse(rambrain::managedMemoryChunk &chunk, bool acquireLock=true)
Triggers swapin of chunk.
adhereTo(const managedPtr< T > &data, bool loadImmediately=true)
constructor fetching data
Main class to allocate memory that is managed by the rambrain memory defaultManager.
rambrainGlobalCriticalSectionControl(bool locksByUser=false)
static managedMemory * defaultManager
const managedPtr< T > * data
managedPtr< T, dim > & operator=(const managedPtr< T, dim > &ref)
assignment operator
std::enable_if< std::is_class< G >::value >::type mDelete() const
This function manages correct deallocation for array elements having a destructor.
managedPtr(unsigned int n_elem, ctor_args...Args)
instantiates managedPtr containing n_elem elements in the current dimension and passes Args as argume...
managedPtr(const managedPtr< T, dim > &ref)
copy ctor
unsigned int size() const
Simple getter.
bool prepareUse() const
tells the memory manager to possibly swap in chunk for near future use
void mfree(rambrain::memoryID id, bool inCleanup=false)
this function unregisters and deallocates a chunk
managedPtr(const managedPtr< T, 1 > &ref)
copy ctor
void stop()
stop pulling critical ingredients in a multithreaded situation
~rambrainGlobalCriticalSectionControl()
std::enable_if< !std::is_class< G >::value >::type mDelete()
This function manages correct deallocation for array elements lacking a destructor.
manages all managed Chunks of raw memory
managedMemoryChunk * mmalloc(global_bytesize sizereq)
allocates and registers a new raw memory chunk of size sizereq to be filled in by managedPtr ...
managedMemoryChunk * chunk
void start()
start pulling of critical ingredients in a multithreaded situation
managedPtr()
with no arguments given, instantiates an array with one element
T * getLocPtr() const
returns local pointer to object
bool setUse(bool writable=true, bool *tracker=NULL) const
Atomically sets use to a chunk if tracker is not already set to true. returns whether we set use or n...
bool unsetUse(unsigned int loaded=1) const
unsets use count on memory chunk
this class marks a section as globally critical. Only one thread can process any section where such a...
managedPtr< T, dim-1 > & operator[](int i)
simple getter for this dimension
static pthread_t creatingThread
void waitForSwapin() const
: indefinitely waits for swapin of the chunk While it would have been desirable to throw exceptions w...
static pthread_mutex_t parentalMutex
managedPtr(unsigned int n_elem, ctor_args...Args)
instantiates managedPtr containing n_elem elements and passes Args as arguments to the constructor of...
bool unsetUse(memoryID id)
Convenience interface for unsetUse ( managedMemoryChunk &chunk, bool writeAccess ) ...
managedPtr()
with no arguments given, instantiates an array with one element
static pthread_mutex_t mutex