ext/revdispatch/libdispatch-0.1/src/ev_dispatch.h in evdispatch-0.2.2 vs ext/revdispatch/libdispatch-0.1/src/ev_dispatch.h in evdispatch-0.2.4
- old
+ new
@@ -27,23 +27,18 @@
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 int current_time( struct timeval *now );
static double elapsed_time( struct timeval *then );
int long m_seconds;
int long m_nanoseconds;
struct timespec m_time;
};
struct Request {
- enum Type{
- HTTP,
- SPHINX,
- MEMCACHED
- };
Request( request_t k, const std::string &u ) : key(k), url(u){ Timer::current_time( &start_time); }
virtual ~Request (){ }
// by default this does nothing, each real request object can do as it pleases with this feature
virtual void set_opt( const std::string &key, const std::string &value ){}
@@ -143,38 +138,12 @@
}
// returns a value from the queue
// rstate: the status of the return, see POP_STATE above.
// cond: an external reason to abort and not pop e.g. exiting event loop
- T *pop_or_wait( POP_STATE *rstate, volatile bool &cond = true, Timer timer = Timer(1,0) ) {
-
- Guard lock(m_lock);
- T *req = NULL;
- 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();
- }
- else {
- *rstate = EXPIRED;
- req = NULL;
- break;
- }
- }
- if( req ){
- *rstate = POPPED;
- m_queue.pop();
- }
- return req;
- }
+ T *pop_or_wait( POP_STATE *rstate, volatile bool &cond = true, Timer timer = Timer(1,0) );
+
size_t size(){
Guard lock(m_lock);
return m_queue.size();
}
@@ -295,10 +264,10 @@
request_t m_counter; // used to create ids for each requests
// sync startup to main thread
Mutex m_lock;
Cond m_cond;
- bool m_loop_started;
+ bool m_loop_started, m_loop_down;
Queue <Request> m_requests;
Queue <Response> m_responses;
// stores all responded messages stored when calling wait_for_request_by_id( request_t id )