void tr_lockUnlock( tr_lock * l ) { assert( l->depth > 0 ); assert( tr_areThreadsEqual( l->lockThread, tr_getCurrentThread( ) ) ); --l->depth; assert( l->depth >= 0 ); #ifdef WIN32 LeaveCriticalSection( &l->lock ); #else pthread_mutex_unlock( &l->lock ); #endif }
void tr_lockLock( tr_lock * l ) { #ifdef WIN32 EnterCriticalSection( &l->lock ); #else pthread_mutex_lock( &l->lock ); #endif assert( l->depth >= 0 ); if( l->depth ) assert( tr_areThreadsEqual( l->lockThread, tr_getCurrentThread( ) ) ); l->lockThread = tr_getCurrentThread( ); ++l->depth; }
void tr_lockUnlock( tr_lock * l ) { assert( l->depth > 0 ); assert( tr_areThreadsEqual( l->lockThread, tr_getCurrentThread( ) ) ); --l->depth; assert( l->depth >= 0 ); #ifdef __BEOS__ release_sem( l->lock ); #elif defined( WIN32 ) LeaveCriticalSection( &l->lock ); #else pthread_mutex_unlock( &l->lock ); #endif }
int tr_amInThread( const tr_thread * t ) { return tr_areThreadsEqual( tr_getCurrentThread( ), t->thread ); }
int tr_lockHave( const tr_lock * l ) { return ( l->depth > 0 ) && ( tr_areThreadsEqual( l->lockThread, tr_getCurrentThread( ) ) ); }