BOOL WINAPI CUSTOM_DLLNAME (HANDLE hinstDLL, DWORD fdwReason, LPVOID lpreserved) { int i; int tid; static int np = HL::CPUInfo::computeNumProcessors(); switch (fdwReason) { case DLL_PROCESS_ATTACH: { LocalTLABIndex = TlsAlloc(); if (LocalTLABIndex == TLS_OUT_OF_INDEXES) { // Not sure what to do here! } HOARD_PRE_ACTION; getCustomHeap(); } break; case DLL_THREAD_ATTACH: if (np == 1) { // We have exactly one processor - just assign the thread to // heap 0. getMainHoardHeap()->chooseZero(); } else { getMainHoardHeap()->findUnusedHeap(); } getCustomHeap(); break; case DLL_THREAD_DETACH: { // Dump the memory from the TLAB. getCustomHeap()->clear(); TheCustomHeapType *heap = (TheCustomHeapType *) TlsGetValue(LocalTLABIndex); if (np != 1) { // If we're on a multiprocessor box, relinquish the heap // assigned to this thread. getMainHoardHeap()->releaseHeap(); } if (heap != 0) { TlsSetValue (LocalTLABIndex, 0); } } break; case DLL_PROCESS_DETACH: HOARD_POST_ACTION; break; default: return TRUE; } return TRUE; }
static void deleteThatHeap(void * p) { TheCustomHeapType * heap = reinterpret_cast<TheCustomHeapType *>(p); heap->clear(); getMainHoardHeap()->free(reinterpret_cast<void *>(heap)); // Relinquish the assigned heap. getMainHoardHeap()->releaseHeap(); }
static void deleteThatHeap(void * p) { auto * heap = reinterpret_cast<TheCustomHeapType *>(p); heap->clear(); getMainHoardHeap()->free(reinterpret_cast<void *>(heap)); // Relinquish the assigned heap. getMainHoardHeap()->releaseHeap(); // pthread_setspecific(theHeapKey, nullptr); }
static TheCustomHeapType * initializeCustomHeap() { assert(pthread_getspecific(theHeapKey) == nullptr); // Allocate a per-thread heap. size_t sz = sizeof(TheCustomHeapType) + sizeof(double); auto * mh = reinterpret_cast<char *>(getMainHoardHeap()->malloc(sz)); auto heap = new (mh) TheCustomHeapType(getMainHoardHeap()); // Store it in the appropriate thread-local area. pthread_setspecific(theHeapKey, reinterpret_cast<void *>(heap)); return heap; }
void hoard_dllThreadAttach() { if (s_numberOfProcessors == 1) { // We have exactly one processor - just assign the thread to // heap 0. getMainHoardHeap()->chooseZero(); } else { getMainHoardHeap()->findUnusedHeap(); } getCustomHeap(); }
static TheCustomHeapType * initializeCustomHeap() { if (theTLAB == NULL) { new (reinterpret_cast<char *>(&tlabBuffer)) TheCustomHeapType(getMainHoardHeap()); theTLAB = reinterpret_cast<TheCustomHeapType *>(&tlabBuffer); } return theTLAB; }
// A special routine we call on thread exits to free up some resources. static void exitRoutine (void) { // Clear the TLAB's buffer. getCustomHeap()->clear(); // Relinquish the assigned heap. getMainHoardHeap()->releaseHeap(); }
// A special routine we call on thread exit to free up some resources. static void exitRoutine() { TheCustomHeapType * heap = getCustomHeap(); // Clear the TLAB's buffer. heap->clear(); // Relinquish the assigned heap. getMainHoardHeap()->releaseHeap(); }
static TheCustomHeapType * initializeCustomHeap() { auto tlab = theTLAB; if (tlab == nullptr) { new (reinterpret_cast<char *>(&tlabBuffer)) TheCustomHeapType(getMainHoardHeap()); tlab = reinterpret_cast<TheCustomHeapType *>(&tlabBuffer); theTLAB = tlab; } return tlab; }
static TheCustomHeapType * initializeCustomHeap (void) { #if !defined(_WIN32) createKey(); assert (pthread_getspecific (theHeapKey) == NULL); #endif // Allocate a per-thread heap. TheCustomHeapType * heap; size_t sz = sizeof(TheCustomHeapType) + sizeof(double); void * mh = getMainHoardHeap()->malloc(sz); heap = new ((char *) mh) TheCustomHeapType (getMainHoardHeap()); // Store it in the appropriate thread-local area. #if defined(_WIN32) TlsSetValue (LocalTLABIndex, heap); #else int r = pthread_setspecific (theHeapKey, (void *) heap); assert (!r); #endif return heap; }
// A special routine we call on thread exit to free up some resources. static void exitRoutine() { TheCustomHeapType * heap = initializeCustomHeap(); // Relinquish the assigned heap. getMainHoardHeap()->releaseHeap(); // Clear the heap (via its destructor). heap->~TheCustomHeapType(); #if !defined(USE_THREAD_KEYWORD) // Reclaim the memory associated with the heap (thread-specific data). pthread_key_delete (theHeapKey); #endif }
static inline void * startMeUp(void * a) { getCustomHeap(); getMainHoardHeap()->findUnusedHeap(); pair<threadFunctionType, void *> * z = (pair<threadFunctionType, void *> *) a; threadFunctionType f = z->first; void * arg = z->second; void * result = NULL; result = (*f)(arg); exitRoutine(); return result; }
static inline void * startMeUp(void * a) { initializeCustomHeap(); getMainHoardHeap()->findUnusedHeap(); auto * z = (pair<threadFunctionType, void *> *) a; auto f = z->first; auto arg = z->second; auto result = (*f)(arg); delete z; exitRoutine(); return result; }
void hoard_dllThreadDetach() { // Dump the memory from the TLAB. getCustomHeap()->clear(); TheCustomHeapType *heap = (TheCustomHeapType *) TlsGetValue(LocalTLABIndex); if (s_numberOfProcessors != 1) { // If we're on a multiprocessor box, relinquish the heap // assigned to this thread. getMainHoardHeap()->releaseHeap(); } if (heap != 0) { TlsSetValue (LocalTLABIndex, 0); } }
static void deleteThatHeap (void * p) { // Called when the thread goes away - reclaims the heap. TheCustomHeapType * heap = (TheCustomHeapType *) p; heap->~TheCustomHeapType(); getMainHoardHeap()->free ((void *) heap); }
static TheCustomHeapType * initializeCustomHeap (void) { new ((char *) &tlabBuffer) TheCustomHeapType (getMainHoardHeap()); return (theTLAB = (TheCustomHeapType *) &tlabBuffer); }