ext/revdispatch/libdispatch-0.1/src/ev_dispatch.cc in evdispatch-0.1.5 vs ext/revdispatch/libdispatch-0.1/src/ev_dispatch.cc in evdispatch-0.2.0

- old
+ new

@@ -21,9 +21,44 @@ // memcached: client library for the memcached requests // namespace EVD { +double Timer::elapsed_time( struct timeval *y ) +{ + struct timeval duration; + struct timeval now; + current_time( &now ); + struct timeval *x = &now; + struct timeval *result = &duration; + + // see: http://www.gnu.org/software/libtool/manual/libc/Elapsed-Time.html + // Perform the carry for the later subtraction by updating y. + if (x->tv_usec < y->tv_usec) { + int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1; + y->tv_usec -= 1000000 * nsec; + y->tv_sec += nsec; + } + + if (x->tv_usec - y->tv_usec > 1000000) { + int nsec = (x->tv_usec - y->tv_usec) / 1000000; + y->tv_usec += 1000000 * nsec; + y->tv_sec -= nsec; + } + + // Compute the time remaining to wait. + // tv_usec is certainly positive. + result->tv_sec = x->tv_sec - y->tv_sec; + result->tv_usec = x->tv_usec - y->tv_usec; + + double elasped = ((double)duration.tv_sec + ((double)duration.tv_usec/1000000.0)); + // Return 1 if result is negative. + if( x->tv_sec < y->tv_sec ){ + return (-1.0 * elasped); + } + return elasped; +} + Dispatch::Dispatch() : m_loop(NULL), m_counter(0), m_loop_started(false), m_http_client(NULL), m_pending(0) { // zero everything out memset(&m_clock,0,sizeof(ev_timer)); memset(&m_request_watcher,0,sizeof(ev_async));