library/src/datastructures/BP-HashTable.cc
// Attempts to check in a table which has already been checked out.
Attempts to check in a table which has already been checked out.
Attempts to check in a table which has already been checked out .
BP_ERROR_T BP_HashRegCheckInTable
(
	P_BP_HASH_TABLE_REGISTRY      hreg,
	P_BP_HASH_TABLE_KEYED_ENTRY   table
)
{
	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_HASH_TABLE_SEM_IS_LOCKED(table->lock, tmp_val);
	if(tmp_val == 1)
	{
		return ERR_FAILURE;
	}
	BP_BOOL parent_unlocked_ok = BP_FALSE;
	if(table->data)
	{
		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_HashRegCheckInData
				(
					hreg,
					entry
				);
				if(data_lock_status == ERR_FAILURE)
					return ERR_FAILURE;
			}
			else
			{
				table_lock_status = BP_HashRegCheckInTable
				(
					hreg,
					entry
				);
				if(table_lock_status == ERR_FAILURE)
					return ERR_FAILURE;
			}
		}
	}
	if(BP_HASH_TABLE_UNLOCK_SEM(table->lock) == ERR_FAILURE)
		return ERR_FAILURE;
	return ERR_SUCCESS;
}
BP_ERROR_T BP_HashRegCheckInTable ( P_BP_HASH_TABLE_REGISTRY hreg , P_BP_HASH_TABLE_KEYED_ENTRY table ) { 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_HASH_TABLE_SEM_IS_LOCKED ( table -> lock , tmp_val ) ; if ( tmp_val == 1 ) { return ERR_FAILURE ; } BP_BOOL parent_unlocked_ok = BP_FALSE ; if ( table -> data ) { 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_HashRegCheckInData ( hreg , entry ) ; if ( data_lock_status == ERR_FAILURE ) return ERR_FAILURE ; } else { table_lock_status = BP_HashRegCheckInTable ( hreg , entry ) ; if ( table_lock_status == ERR_FAILURE ) return ERR_FAILURE ; } } } if ( BP_HASH_TABLE_UNLOCK_SEM ( table -> lock ) == ERR_FAILURE ) return ERR_FAILURE ; return ERR_SUCCESS ; }
Attempts to check in a table which has already been checked out.
Attempts to check in a table which has already been checked out .
// macro to override hreg on null // return indicating failure // ensure the table provided is the correct type // check that the semaphore is unlocked // if the table is already unlocked, return failure immediately (1 is unlocked) // Indicator to describe if the parent table is locked before // recursing into children. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Begin Table Checkin %%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // if there is no data, check lock status and return // accordingly. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% 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 checkin the data entry // exit if the lock failed // attempt to checkin the table recursively // exit if the lock failed // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Attempt to Unlock Table %%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // attempt to unlock the semaphore // return indicating success