Url * pop_ourlqueue() { Url *url = NULL; pthread_mutex_lock(&oq_lock); if (!ourl_queue.empty()) { url = ourl_queue.front(); ourl_queue.pop(); pthread_mutex_unlock(&oq_lock); return url; } else { int trynum = 3; struct timespec timeout; while (trynum-- && ourl_queue.empty()) { get_timespec(&timeout, 500); /* 0.5s timeout*/ pthread_cond_timedwait(&oq_cond, &oq_lock, &timeout); } if (!ourl_queue.empty()) { url = ourl_queue.front(); ourl_queue.pop(); } pthread_mutex_unlock(&oq_lock); return url; } }
int b_start_timer(struct B * b) { if(!b->running) { get_timespec(&b->start_time); b->samples[0] = b->start_time.nsec; b->running = 1; } return B_SUCCESS; }
int b_stop_timer(struct B * b) { uint64_t start, end, duration; if(b->running) { get_timespec(&b->end_time); if (b->end_time.nsec - b->start_time.nsec < 0) { printf("Invalid nsec\n"); } start = b->start_time.sec; end = b->end_time.sec; duration = end - start; b->s_duration = duration; start = b->start_time.nsec; end = b->end_time.nsec; duration = end - start; b->ns_duration = duration; b->running = 0; } return B_SUCCESS; }
/*! Ctor. \param settonow if true, construct with current time */ Tickval(bool settonow=false) : _value(settonow ? _cvt(get_timespec()) : noticks) {}