Changeset 54
- Timestamp:
- 01/23/05 07:28:07 (18 years ago)
- Files:
-
- trunk/freebob/src/workerthread.cpp (modified) (3 diffs)
- trunk/freebob/src/workerthread.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/freebob/src/workerthread.cpp
r43 r54 26 26 WorkerThread::WorkerThread() 27 27 { 28 setDebugLevel( DEBUG_LEVEL_ ALL);28 setDebugLevel( DEBUG_LEVEL_SCHEDULER ); 29 29 30 30 pthread_create( &m_thread, NULL, workerThread, this ); … … 58 58 59 59 void 60 WorkerThread::addFunctor( Functor* pFunctor )60 WorkerThread::addFunctor( Functor* pFunctor, bool sleeper ) 61 61 { 62 62 pthread_mutex_lock( &m_mutex ); 63 m_queue.push( pFunctor ); 63 if ( !sleeper ) { 64 m_queue.push( pFunctor ); 65 } else { 66 m_sleepQueue.push( pFunctor ); 67 } 64 68 pthread_mutex_unlock( &m_mutex ); 65 69 pthread_cond_signal( &m_cond ); 70 } 71 72 bool 73 WorkerThread::wakeSleepers() 74 { 75 debugPrint( DEBUG_LEVEL_SCHEDULER, 76 "Wake sleeping functors (nr = %d).\n", 77 m_sleepQueue.size() ); 78 while ( !m_sleepQueue.empty() ) { 79 pthread_mutex_lock( &m_mutex ); 80 Functor* pFunctor = m_sleepQueue.front(); 81 m_sleepQueue.pop(); 82 m_queue.push( pFunctor ); 83 pthread_mutex_unlock( &m_mutex ); 84 } 85 pthread_cond_signal( &m_cond ); 86 return true; 66 87 } 67 88 … … 72 93 pthread_mutex_lock( &m_mutex ); 73 94 if ( m_queue.empty() ) { 74 debugPrint( DEBUG_LEVEL_INFO, "Waiting on condition variable.\n" ); 95 debugPrint( DEBUG_LEVEL_SCHEDULER, 96 "Waiting on condition variable.\n" ); 75 97 pthread_cond_wait( &m_cond, &m_mutex ); 76 debugPrint( DEBUG_LEVEL_INFO, "Awoken from condition wait.\n" ); 98 debugPrint( DEBUG_LEVEL_SCHEDULER, 99 "Awoken from condition wait.\n" ); 77 100 } 78 101 pthread_mutex_unlock( &m_mutex ); trunk/freebob/src/workerthread.h
r43 r54 31 31 static WorkerThread* instance(); 32 32 33 void addFunctor( Functor* pFunctor ); 33 void addFunctor( Functor* pFunctor, bool sleeper = false ); 34 bool wakeSleepers(); 34 35 35 36 protected: … … 47 48 pthread_cond_t m_cond; 48 49 std::queue< Functor* > m_queue; 50 std::queue< Functor* > m_sleepQueue; 49 51 50 52 DECLARE_DEBUG_MODULE;