/* Caller MUST be holding the mutex lock; the lock is released and the caller is blocked waiting on 'cond'. When 'cond' is signaled, the mutex is re-acquired before returning to the caller. */ int sp_thread_cond_wait( sp_thread_cond_t * cond, sp_thread_mutex_t * mutex ) { int ret = 0; sp_thread_mutex_unlock( mutex ); ret = WaitForSingleObject( *cond, INFINITE ); sp_thread_mutex_lock( mutex ); return WAIT_OBJECT_0 == ret ? 0 : GetLastError(); }
int SP_BlockingQueue :: getLength() { int len = 0; sp_thread_mutex_lock( &mMutex ); len = mQueue->getLength(); sp_thread_mutex_unlock( &mMutex ); return len; }
void * SP_BlockingQueue :: top() { void * ret = NULL; sp_thread_mutex_lock( &mMutex ); ret = mQueue->top(); sp_thread_mutex_unlock( &mMutex ); return ret; }
void SP_OnlineSidList :: remove( SP_Sid_t sid ) { sp_thread_mutex_lock( &mMutex ); for( int i = 0; i < mList.getCount(); i++ ) { SP_Sid_t theSid = mList.get( i ); if( theSid.mKey == sid.mKey && theSid.mSeq == sid.mSeq ) { mList.take( i ); break; } } sp_thread_mutex_unlock( &mMutex ); }
void SP_OnlineManager :: remove( SP_Sid_t sid ) { sp_thread_mutex_lock( &mMutex ); for( int i = 0; i < mList.getCount(); i++ ) { SP_OnlineInfo_t * info = (SP_OnlineInfo_t*)mList.getItem( i ); SP_Sid_t theSid = info->mSid; if( theSid.mKey == sid.mKey && theSid.mSeq == sid.mSeq ) { mList.takeItem( i ); free( info ); break; } } sp_thread_mutex_unlock( &mMutex ); }
void * SP_BlockingQueue :: pop() { void * ret = NULL; sp_thread_mutex_lock( &mMutex ); if( mQueue->getLength() == 0 ) { sp_thread_cond_wait( &mCond, &mMutex ); } ret = mQueue->pop(); sp_thread_mutex_unlock( &mMutex ); return ret; }
void SP_OnlineSidList :: copy( SP_SidList * outList, SP_Sid_t * ignoreSid ) { sp_thread_mutex_lock( &mMutex ); for( int i = 0; i < mList.getCount(); i++ ) { if( NULL != ignoreSid ) { SP_Sid_t theSid = mList.get( i ); if( theSid.mKey == ignoreSid->mKey && theSid.mSeq == ignoreSid->mSeq ) { continue; } } outList->add( mList.get( i ) ); } sp_thread_mutex_unlock( &mMutex ); }
void SP_OnlineManager :: copy( SP_SidList * outList, SP_Sid_t * ignoreSid ) { sp_thread_mutex_lock( &mMutex ); for( int i = 0; i < mList.getCount(); i++ ) { SP_OnlineInfo_t * info = (SP_OnlineInfo_t*)mList.getItem( i ); if( NULL != ignoreSid ) { SP_Sid_t theSid = info->mSid; if( theSid.mKey == ignoreSid->mKey && theSid.mSeq == ignoreSid->mSeq ) { continue; } } outList->add( info->mSid ); } sp_thread_mutex_unlock( &mMutex ); }
int SP_OnlineManager :: getChatID( SP_Sid_t sid ) { int chatID = -1; sp_thread_mutex_lock( &mMutex ); for( int i = 0; i < mList.getCount(); i++ ) { SP_OnlineInfo_t * info = (SP_OnlineInfo_t*)mList.getItem( i ); SP_Sid_t theSid = info->mSid; if( theSid.mKey == sid.mKey && theSid.mSeq == sid.mSeq ) { chatID = info->mChatID; break; } } sp_thread_mutex_unlock( &mMutex ); return chatID; }
int save_thread( _threadpool * pool, _thread * thread ) { int ret = -1; sp_thread_mutex_lock( &pool->tp_mutex ); if( pool->tp_index < pool->tp_max_index ) { pool->tp_list[ pool->tp_index ] = thread; pool->tp_index++; ret = 0; sp_thread_cond_signal( &pool->tp_idle ); if( pool->tp_index >= pool->tp_total ) { sp_thread_cond_signal( &pool->tp_full ); } } sp_thread_mutex_unlock( &pool->tp_mutex ); return ret; }
void SP_CacheItem :: addRef() { sp_thread_mutex_lock( &mMutex ); mRefCount++; sp_thread_mutex_unlock( &mMutex ); }