ext/revdispatch/libdispatch-0.1/src/ev_dispatch.cc in evdispatch-0.2.1 vs ext/revdispatch/libdispatch-0.1/src/ev_dispatch.cc in evdispatch-0.2.2

- old
+ new

@@ -98,10 +98,22 @@ } return (count < 100); } +void Dispatch::flush() +{ + // lock the responses + m_responses.m_lock.lock(); + while( !m_responses.m_queue.empty() ){ + m_responses.m_queue.pop(); + } + // empty out the thread local buffer + m_responded.clear(); + m_responses.m_lock.unlock(); +} + // tell the background event listener to terminate void Dispatch::stop() { if( !m_loop_started ){ return ; } @@ -243,24 +255,27 @@ Queue<Response>::POP_STATE rstate; RespondedTable::iterator loc = m_responded.find(id); if( loc != m_responded.end() ){ return Queue<Response>::POPPED; } + timeout.update(); while( (rep = m_responses.pop_or_wait( &rstate, m_loop_started, timeout )) ) { //printf( "rep: %s, id: %d\n", rep->name.c_str(), rep->id ); m_responded[rep->id] = rep; if( rep->id == id ){ return rstate; } + timeout.update(); } return rstate; } Response *Dispatch::get_next_response( Timer timer ) { Response *rep = NULL; Queue<Response>::POP_STATE rstate; + timer.update(); do { rep = m_responses.pop_or_wait( &rstate, m_loop_started, timer ); if( rstate == Queue<Response>::EXITING ){ rep = NULL; break; } if( !rep && rstate == Queue<Response>::EXPIRED ) { int pending_count = m_pending; @@ -274,9 +289,10 @@ } } else if( rep ) { --m_pending; } + timer.update(); } while( !rep && rstate == Queue<Response>::EXPIRED ); return rep; }