Example #1
0
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;
}
Example #2
0
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();
}
Example #3
0
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);
}
Example #4
0
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();
}
Example #6
0
static TheCustomHeapType * initializeCustomHeap() {
  if (theTLAB == NULL) {
    new (reinterpret_cast<char *>(&tlabBuffer)) TheCustomHeapType(getMainHoardHeap());
    theTLAB = reinterpret_cast<TheCustomHeapType *>(&tlabBuffer);
  }
  return theTLAB;
}
Example #7
0
// 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();
}
Example #8
0
// 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();
}
Example #9
0
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;
}
Example #10
0
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;
}
Example #11
0
// 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
}
Example #12
0
  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;
  }
Example #13
0
  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);
	}
}
Example #15
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);
}
Example #16
0
static TheCustomHeapType * initializeCustomHeap (void) {
  new ((char *) &tlabBuffer) TheCustomHeapType (getMainHoardHeap());
  return (theTLAB = (TheCustomHeapType *) &tlabBuffer);
}