There are a number of variations of locking available with different characteristics.
This group of functions is the prefered locking mechanism since it allows recovery from a number of exception conditions which cannot be handled by a simple bit-lock.
struct bpo_pid_lock * bpo_Init_pid_lock( struct bpo_pid_lock *bplp, struct timeval *udtp ); void bpo_pid_Lock( struct bpo_pid_lock *bplp ); void bpo_pid_Unlock( struct bpo_pid_lock *bplp );The initialisation function takes a pointer to the lock and a pointer to a timeval structure which should contain a timeout value to be used to determine how often a process should check whether the current owner has died. If the timeval pointer is NULL the timeout value will default to one second.
The lock and unlock functions perform as one would expect.
void b_Init( b_lock *lockp );This function sets the lock up for use by the other functions. If this is used on a lock already in use then unexpected behaviour may occur.
void b_Lock( b_lock *lockp );This function waits until it can gain exclusive access to the structure. It waits by using the select call with a small timeout.
void b_Unlock( b_lock *lockp );This function clears the lock, freeing it up for other users.
int b_TryLock( b_lock_t *lockp );This function attempts to obtain the lock. It returns zero if it succeeds, and non-zero if it failed.
long b_Lockval( b_lock *lockp );This function returns a non-zero value if the lock is currently held by someone.
int bpo_nap_a_while( long secs, long usecs );This function uses the select system call to causes the process to sleep for the specified time.
int bpo_take_a_nap( void );This function call the one above to sleep for a pre-defined time, usually 5mS.