ext/revdispatch/libdispatch-0.1/src/ev_dispatch.h in evdispatch-0.2.1 vs ext/revdispatch/libdispatch-0.1/src/ev_dispatch.h in evdispatch-0.2.2
- old
+ new
@@ -15,18 +15,26 @@
// unique id to represent a request
typedef unsigned long request_t;
struct Timer {
- Timer( long int seconds, long int nanoseconds ) {
+
+ Timer( long int seconds, long int nanoseconds ) : m_seconds( seconds ), m_nanoseconds( nanoseconds ) { update(); }
+
+ // offset the timer from now
+ void update() {
struct timeval now;
current_time( &now );
- m_time.tv_sec = now.tv_sec + seconds;
- m_time.tv_nsec = (now.tv_usec * 1000) + nanoseconds;
+ m_time.tv_sec = now.tv_sec + m_seconds;
+ m_time.tv_nsec = (now.tv_usec*1000) + m_nanoseconds;
+ //printf( "seconds: %ld, nanoseconds: %ld, from s: %ld, ns: %ld, based s: %ld, us: %ld\n", m_time.tv_sec, m_time.tv_nsec, m_seconds, m_nanoseconds, now.tv_sec, now.tv_usec );
}
+
inline static int current_time( struct timeval *now) { return gettimeofday(now, NULL); }
static double elapsed_time( struct timeval *then );
+ int long m_seconds;
+ int long m_nanoseconds;
struct timespec m_time;
};
struct Request {
enum Type{
@@ -144,10 +152,11 @@
size_t size = m_queue.size();
if( size > 0 ){
req = m_queue.front();
}
while( !req ) {
+ timer.update();
m_cond.timed_wait( m_lock, timer );
if( !cond ){ *rstate = EXITING; break; }
size = m_queue.size();
if( size > 0 ){
req = m_queue.front();
@@ -221,9 +230,12 @@
// start up the background event listener
bool start();
// tell the background event listener to terminate
void stop();
+
+ // empty the response local buffer and queue
+ void flush();
request_t request( Request *req );
// from the main thread, get the next available response
// just keep pop'ing off the response queue until we get something