library/src/datastructures/BP-HashTable.cc
// Creates a new hash table registry.
Creates a new hash table registry.
Creates a new hash table registry .
P_BP_HASH_TABLE_REGISTRY BP_CreateHashTableRegistry()
{
	P_BP_HASH_TABLE_REGISTRY hreg = (P_BP_HASH_TABLE_REGISTRY) calloc
	(
		sizeof(BP_HASH_TABLE_REGISTRY),
		1
	);
	size_t calloc_iter = 0;
	size_t calloc_iter_max = 10;
	while(!hreg)
	{
		sleep(1);
		hreg = (P_BP_HASH_TABLE_REGISTRY) calloc
		(
			sizeof(BP_HASH_TABLE_REGISTRY),
			1
		);
		if(hreg)
			break;
		calloc_iter++;
		if(calloc_iter == calloc_iter_max)
			break;
	}
	if(!hreg)
	{
		if(BP_DEBUG_BREAKPOINT_ON_ALLOC_FAIL)
		{
			printf("\n [!!] BP_CreateHashTableRegistry failed to calloc() after waiting 10 seconds.  This is unreasonable behavior and indicates that your system is unable to handle the thoroughput being thrown at it.");
			asm("int3");
		}
		return NULL;
	}
	BP_HASH_TABLE_INIT_SEM(hreg->lock);
	BP_HASH_TABLE_INIT_SEM(hreg->critical_section_lock);
	return hreg;
}
P_BP_HASH_TABLE_REGISTRY BP_CreateHashTableRegistry ( ) { P_BP_HASH_TABLE_REGISTRY hreg = ( P_BP_HASH_TABLE_REGISTRY ) calloc ( sizeof ( BP_HASH_TABLE_REGISTRY ) , 1 ) ; size_t calloc_iter = 0 ; size_t calloc_iter_max = 10 ; while ( ! hreg ) { sleep ( 1 ) ; hreg = ( P_BP_HASH_TABLE_REGISTRY ) calloc ( sizeof ( BP_HASH_TABLE_REGISTRY ) , 1 ) ; if ( hreg ) break ; calloc_iter ++ ; if ( calloc_iter == calloc_iter_max ) break ; } if ( ! hreg ) { if ( BP_DEBUG_BREAKPOINT_ON_ALLOC_FAIL ) { printf ( " \n " ) ; asm ( " " ) ; } return NULL ; } BP_HASH_TABLE_INIT_SEM ( hreg -> lock ) ; BP_HASH_TABLE_INIT_SEM ( hreg -> critical_section_lock ) ; return hreg ; }
Creates a new hash table registry.
Creates a new hash table registry .
// allocate space for hash table registry // iterator for exiting // set 10 second allocation wait time // attempt reallocation // sleep 1 second before trying next allocation // attempt allocation // break the loop if the allocation succeeded // increment the iterator // break if we hit our allocation cap // trigger breakpoint on fail if necessary // initialize the hash table semaphore // initialize the critical section lock // return indicating success