Changeset 54

Show
Ignore:
Timestamp:
01/23/05 07:28:07 (18 years ago)
Author:
wagi
Message:

Added sleeping queue support.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/freebob/src/workerthread.cpp

    r43 r54  
    2626WorkerThread::WorkerThread() 
    2727{ 
    28     setDebugLevel( DEBUG_LEVEL_ALL ); 
     28    setDebugLevel( DEBUG_LEVEL_SCHEDULER ); 
    2929 
    3030    pthread_create( &m_thread, NULL, workerThread, this ); 
     
    5858 
    5959void 
    60 WorkerThread::addFunctor( Functor* pFunctor
     60WorkerThread::addFunctor( Functor* pFunctor, bool sleeper
    6161{ 
    6262    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    } 
    6468    pthread_mutex_unlock( &m_mutex ); 
    6569    pthread_cond_signal( &m_cond ); 
     70} 
     71 
     72bool 
     73WorkerThread::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; 
    6687} 
    6788 
     
    7293        pthread_mutex_lock( &m_mutex ); 
    7394        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" ); 
    7597            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" ); 
    77100        } 
    78101        pthread_mutex_unlock( &m_mutex ); 
  • trunk/freebob/src/workerthread.h

    r43 r54  
    3131    static WorkerThread* instance(); 
    3232 
    33     void addFunctor( Functor* pFunctor ); 
     33    void addFunctor( Functor* pFunctor, bool sleeper = false ); 
     34    bool wakeSleepers(); 
    3435 
    3536 protected: 
     
    4748    pthread_cond_t m_cond; 
    4849    std::queue< Functor* > m_queue; 
     50    std::queue< Functor* > m_sleepQueue; 
    4951 
    5052    DECLARE_DEBUG_MODULE;