Пример #1
0
RegionInfoTable* RegionInfoTable::CreateInstance() {
    THROWSCOMPLUSEXCEPTION();

    if (m_pDefaultTable==NULL) {
        Thread* pThread = GetThread();
        pThread->EnablePreemptiveGC();

        LOCKCOUNTINCL("CreateInstance in regioninfotable.cpp");						\
        EnterCriticalSection(&m_ProtectDefaultTable);
        
        pThread->DisablePreemptiveGC();
     
        EE_TRY_FOR_FINALLY {
            //Make sure that nobody allocated the table before us.
            if (m_pDefaultTable==NULL) {
                //Allocate the default table and verify that we got one.
                m_pDefaultTable = AllocateTable();
                if (m_pDefaultTable==NULL) {
                    COMPlusThrowOM();
                }
            }
        } EE_FINALLY {
            //We need to leave the critical section regardless of whether
            //or not we were successful in allocating the table.
            LeaveCriticalSection(&m_ProtectDefaultTable);
			LOCKCOUNTDECL("CreateInstance in regioninfotable.cpp");						\

        } EE_END_FINALLY;
    }
Пример #2
0
static int ResizeHashArray (TRI_hash_array_t* array) {
  TRI_hash_index_element_t* oldTable;
  uint64_t oldAlloc;
  uint64_t j;
  int res;

  oldTable = array->_table;
  oldAlloc = array->_nrAlloc;

  res = AllocateTable(array, 2 * array->_nrAlloc + 1);

  if (res != TRI_ERROR_NO_ERROR) {
    return res;
  }

  array->_nrUsed = 0;

#ifdef TRI_INTERNAL_STATS
  array->_nrResizes++;
#endif

  for (j = 0; j < oldAlloc; j++) {
    if (! IsEmptyElement(array, &oldTable[j])) {
      AddNewElement(array, &oldTable[j]);
    }
  }

  TRI_Free(TRI_UNKNOWN_MEM_ZONE, oldTable);
  return TRI_ERROR_NO_ERROR;
}
Пример #3
0
static int ResizeHashArray (TRI_hash_array_multi_t* array,
                            uint64_t targetSize,
                            bool allowShrink) {
  if (array->_nrAlloc >= targetSize && ! allowShrink) {
    return TRI_ERROR_NO_ERROR;
  }

  TRI_hash_index_element_multi_t* oldTable    = array->_table;
  TRI_hash_index_element_multi_t* oldTablePtr = array->_tablePtr;
  uint64_t oldAlloc = array->_nrAlloc;

  TRI_ASSERT(targetSize > 0);

  int res = AllocateTable(array, targetSize);

  if (res != TRI_ERROR_NO_ERROR) {
    return res;
  }

  if (array->_nrUsed > 0) {
    uint64_t const n = array->_nrAlloc;

    for (uint64_t j = 0; j < oldAlloc; j++) {
      TRI_hash_index_element_multi_t* element = &oldTable[j];

      if (element->_document != nullptr) {
        uint64_t i, k;
        i = k = HashElement(array, element) % n;

        for (; i < n && array->_table[i]._document != nullptr; ++i);
        if (i == n) {
          for (i = 0; i < k && array->_table[i]._document != nullptr; ++i);
        }

        TRI_ASSERT_EXPENSIVE(i < n);

        // ...........................................................................
        // add a new element to the associative array
        // memcpy ok here since are simply moving array items internally
        // ...........................................................................

        memcpy(&array->_table[i], element, TableEntrySize());
      }
    }
  }

  TRI_Free(TRI_UNKNOWN_MEM_ZONE, oldTablePtr);

  return TRI_ERROR_NO_ERROR;
}
Пример #4
0
int TRI_InitHashArray (TRI_hash_array_t* array,
                       size_t initialDocumentCount,
                       size_t numFields) {
  size_t initialSize;
  int res;

  // ...........................................................................
  // Assign the callback functions
  // ...........................................................................

  assert(numFields > 0);

  array->_numFields = numFields;
  array->_table = NULL;

  if (initialDocumentCount > 0) {
    // use initial document count provided as initial size
    initialSize = (size_t) (2.5 * initialDocumentCount);
  }
  else {
    initialSize = INITIAL_SIZE;
  }

  res = AllocateTable(array, initialSize);

  if (res != TRI_ERROR_NO_ERROR) {
    return res;
  }

  // ...........................................................................
  // allocate storage for the hash array
  // ...........................................................................

  array->_nrUsed = 0;

#ifdef TRI_INTERNAL_STATS
  array->_nrFinds = 0;
  array->_nrAdds = 0;
  array->_nrRems = 0;
  array->_nrResizes = 0;
  array->_nrProbesF = 0;
  array->_nrProbesA = 0;
  array->_nrProbesD = 0;
  array->_nrProbesR = 0;
#endif

  return TRI_ERROR_NO_ERROR;
}
Пример #5
0
int TRI_InitHashArrayMulti (TRI_hash_array_multi_t* array,
                            size_t numFields) {

  TRI_ASSERT(numFields > 0);

  array->_numFields       = numFields;
  array->_tablePtr        = nullptr;
  array->_table           = nullptr;
  array->_nrUsed          = 0;
  array->_nrAlloc         = 0;
  array->_nrOverflowUsed  = 0;
  array->_nrOverflowAlloc = 0;
  array->_freelist        = nullptr;

  TRI_InitVectorPointer2(&array->_blocks, TRI_UNKNOWN_MEM_ZONE, 16);

  return AllocateTable(array, InitialSize());
}