library/src/databases/mysql/BP-DBMySQLConnectionPooling.cc
// Attempts to acquire a free entry in the mysql connection pool and lock it for our use.  Will
// return NULL on failure.
Attempts to acquire a free entry in the mysql connection pool and lock it for our use.  Will
return NULL on failure.
Attempts to acquire a free entry in the mysql connection pool and lock it for our use . Will return NULL on failure .
P_BP_MYSQL_CONNECTION_POOL_ENTRY BP_MySQLConnectionPoolAcquireAndLock(P_BP_MYSQL_CONN_POOL pool)
{
	if(!pool)
	{
		return NULL;
	}
	size_t n = 0;
	for(n = 0; n < pool->entries_total; n++)
	{
		int wait_status = sem_trywait(&pool->entries[n].lock);
		if(wait_status != 0)
		{
			if(pool->entries_total-1 == n)
				n = 0;
			continue;
		}
		pool->entries[n].in_use = BP_TRUE;
		pool->entries_in_use++;
		sem_post(&pool->lock);
		return &pool->entries[n];
	}
	return NULL;
}
P_BP_MYSQL_CONNECTION_POOL_ENTRY BP_MySQLConnectionPoolAcquireAndLock ( P_BP_MYSQL_CONN_POOL pool ) { if ( ! pool ) { return NULL ; } size_t n = 0 ; for ( n = 0 ; n < pool -> entries_total ; n ++ ) { int wait_status = sem_trywait ( & pool -> entries [ n ] . lock ) ; if ( wait_status != 0 ) { if ( pool -> entries_total - 1 == n ) n = 0 ; continue ; } pool -> entries [ n ] . in_use = BP_TRUE ; pool -> entries_in_use ++ ; sem_post ( & pool -> lock ) ; return & pool -> entries [ n ] ; } return NULL ; }
Attempts to acquire a free entry in the mysql connection pool and lock it for our use.
Attempts to acquire a free entry in the mysql connection pool and lock it for our use .
// check to see if we have pointer // walk each entry and issue a sem_trywait till we get an available connection // Loop forever till we get a connection, but only loop through // connections found within the connection pool.  Infinite loop // is caused by reset logic at bottom of loop. // try to wait // reset loop iter if we havent found a good entry // continue the loop // set the in use flag to true // increment the number of entries currently in use // unlock pool // return the newly locked entry // return no entry if one could'nt be found