コード例 #1
0
ファイル: userealtls.cpp プロジェクト: Miguel-J/eneboo-core
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;
}
コード例 #2
0
ファイル: unixtls.cpp プロジェクト: Similer/Hoard
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();
}
コード例 #3
0
ファイル: unixtls.cpp プロジェクト: simonzhangsm/Hoard
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);
}
コード例 #4
0
ファイル: unixtls.cpp プロジェクト: simonzhangsm/Hoard
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;
}
コード例 #5
0
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();
}
コード例 #6
0
ファイル: unixtls.cpp プロジェクト: LlsDimple/Hoard
static TheCustomHeapType * initializeCustomHeap() {
  if (theTLAB == NULL) {
    new (reinterpret_cast<char *>(&tlabBuffer)) TheCustomHeapType(getMainHoardHeap());
    theTLAB = reinterpret_cast<TheCustomHeapType *>(&tlabBuffer);
  }
  return theTLAB;
}
コード例 #7
0
ファイル: userealtls.cpp プロジェクト: Miguel-J/eneboo-core
// 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();
}
コード例 #8
0
ファイル: unixtls.cpp プロジェクト: Similer/Hoard
// 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();
}
コード例 #9
0
ファイル: unixtls.cpp プロジェクト: simonzhangsm/Hoard
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;
}
コード例 #10
0
ファイル: userealtls.cpp プロジェクト: Miguel-J/eneboo-core
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;
}
コード例 #11
0
ファイル: unixtls.cpp プロジェクト: LlsDimple/Hoard
// 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
}
コード例 #12
0
ファイル: unixtls.cpp プロジェクト: Similer/Hoard
  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;
  }
コード例 #13
0
ファイル: unixtls.cpp プロジェクト: simonzhangsm/Hoard
  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;
  }
コード例 #14
0
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);
	}
}
コード例 #15
0
ファイル: userealtls.cpp プロジェクト: Miguel-J/eneboo-core
static void deleteThatHeap (void * p) {
  // Called when the thread goes away - reclaims the heap.
  TheCustomHeapType * heap = (TheCustomHeapType *) p;
  heap->~TheCustomHeapType();
  getMainHoardHeap()->free ((void *) heap);
}
コード例 #16
0
ファイル: userealtls.cpp プロジェクト: Miguel-J/eneboo-core
static TheCustomHeapType * initializeCustomHeap (void) {
  new ((char *) &tlabBuffer) TheCustomHeapType (getMainHoardHeap());
  return (theTLAB = (TheCustomHeapType *) &tlabBuffer);
}