library/src/datastructures/BP-HashTable.cc
// Attempts to checkout a hash table at a provided path.  The third parameter
// determines whether or not the routine will attempt to block until locking
// the table (checking it out) completes.
Attempts to checkout a hash table at a provided path.  The third parameter
determines whether or not the routine will attempt to block until locking
the table (checking it out) completes.
Attempts to checkout a hash table at a provided path . The third parameter determines whether or not the routine will attempt to block until locking the table ( checking it out ) completes .
BP_ERROR_T BP_HashRegCheckOutTable
(
	P_BP_HASH_TABLE_REGISTRY      hreg,
	P_BP_HASH_TABLE_KEYED_ENTRY   table,
	BP_BOOL                       block_till_checkout_established
)
{
	BP_GLOBAL_HASH_TABLE_OVERRIDE(ERR_FAILURE);
	if(!table)
		return ERR_FAILURE;
	if(table->type != BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE)
		return ERR_FAILURE;
	int tmp_val = 0;
	BP_BOOL parent_locked_ok = BP_FALSE;
	if(block_till_checkout_established == BP_TRUE)
	{
		BP_HASH_TABLE_LOCK_SEM(table->lock);
		parent_locked_ok = BP_TRUE;
	}
	else
	{
		if
		(
			BP_HASH_TABLE_TRYLOCK_SEM(table->lock) == ERR_SUCCESS
		)
		{
			parent_locked_ok = BP_TRUE;
		}
		else
		{
			return ERR_FAILURE;
		}
	}
	if(!table->data)
	{
		if(parent_locked_ok == BP_TRUE)
			return ERR_SUCCESS;
		else
			return ERR_FAILURE;
	}
	P_BP_HASH_TABLE_KEYED_ENTRY entry_table   = (P_BP_HASH_TABLE_KEYED_ENTRY) table->data;
	P_BP_HASH_TABLE_KEYED_ENTRY entry       = NULL;
	P_BP_HASH_TABLE_KEYED_ENTRY tmp         = NULL;
	P_BP_HASH_TABLE_KEYED_ENTRY sub_table   = NULL;
	BP_ERROR_T data_lock_status  = ERR_FAILURE;
	BP_ERROR_T table_lock_status = ERR_FAILURE;
	HASH_ITER(hh, entry_table, entry, tmp)
	{
		if(entry == table)
			continue;
		data_lock_status  = ERR_FAILURE;
		table_lock_status = ERR_FAILURE;
		if(entry->type != BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE)
		{
			data_lock_status = BP_HashRegCheckOutData
			(
				hreg,
				entry,
				block_till_checkout_established
			);
		}
		else
		{
			table_lock_status = BP_HashRegCheckOutTable
			(
				hreg,
				entry,
				block_till_checkout_established
			);
		}
	}
	return ERR_SUCCESS;
}
BP_ERROR_T BP_HashRegCheckOutTable ( P_BP_HASH_TABLE_REGISTRY hreg , P_BP_HASH_TABLE_KEYED_ENTRY table , BP_BOOL block_till_checkout_established ) { BP_GLOBAL_HASH_TABLE_OVERRIDE ( ERR_FAILURE ) ; if ( ! table ) return ERR_FAILURE ; if ( table -> type != BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE ) return ERR_FAILURE ; int tmp_val = 0 ; BP_BOOL parent_locked_ok = BP_FALSE ; if ( block_till_checkout_established == BP_TRUE ) { BP_HASH_TABLE_LOCK_SEM ( table -> lock ) ; parent_locked_ok = BP_TRUE ; } else { if ( BP_HASH_TABLE_TRYLOCK_SEM ( table -> lock ) == ERR_SUCCESS ) { parent_locked_ok = BP_TRUE ; } else { return ERR_FAILURE ; } } if ( ! table -> data ) { if ( parent_locked_ok == BP_TRUE ) return ERR_SUCCESS ; else return ERR_FAILURE ; } P_BP_HASH_TABLE_KEYED_ENTRY entry_table = ( P_BP_HASH_TABLE_KEYED_ENTRY ) table -> data ; P_BP_HASH_TABLE_KEYED_ENTRY entry = NULL ; P_BP_HASH_TABLE_KEYED_ENTRY tmp = NULL ; P_BP_HASH_TABLE_KEYED_ENTRY sub_table = NULL ; BP_ERROR_T data_lock_status = ERR_FAILURE ; BP_ERROR_T table_lock_status = ERR_FAILURE ; HASH_ITER ( hh , entry_table , entry , tmp ) { if ( entry == table ) continue ; data_lock_status = ERR_FAILURE ; table_lock_status = ERR_FAILURE ; if ( entry -> type != BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE ) { data_lock_status = BP_HashRegCheckOutData ( hreg , entry , block_till_checkout_established ) ; } else { table_lock_status = BP_HashRegCheckOutTable ( hreg , entry , block_till_checkout_established ) ; } } return ERR_SUCCESS ; }
Attempts to checkout a hash table at a provided path.
Attempts to checkout a hash table at a provided path .
// macro to override hreg on null // return indicating failure // ensure the table provided is the correct type // tmp value required by lock check macro // Indicator to describe if the parent table is locked before // recursing into children. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Attempt to Lock Table %%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // block until the checkout has been established // blocking semaphore lock (critical section) // set the lock flag to true // check that semaphore is locked // return indicating failure // NOTE: Should only ever get to this position if the table is locked. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Exit Immediately if No Data %%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // if there is no data, check lock status and return // accordingly. // ensure the parent is locked ok // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Set Cascading Pointer %%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // cascading hash table // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Attempt to Recursively Lock Children %%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // temporary iterator values used during the HASH_ITER loop below // status for last data and table locks // iterate through all hashes and display // always skip self references // reset lock status on loop // It's either a data entry or a hash table.  If it's data, just lock it.  If it's a table, // check out the tables member elements. // attempt to checkout data entry // attempt to checkout the table recursively // return indicating success