std::string log_time() { static const ptime start = time_now_hires(); char ret[200]; snprintf(ret, sizeof(ret), "%" PRId64, total_microseconds(time_now_hires() - start)); return ret; }
void condition_variable::wait_for(mutex::scoped_lock& l, time_duration rel_time) { TORRENT_ASSERT(l.locked()); ++m_num_waiters; l.unlock(); acquire_sem_etc(m_sem, 1, B_RELATIVE_TIMEOUT, total_microseconds(rel_time)); l.lock(); --m_num_waiters; }
void condition_variable::wait_for(mutex::scoped_lock& l, time_duration rel_time) { TORRENT_ASSERT(l.locked()); struct timeval tv; struct timespec ts; gettimeofday(&tv, NULL); boost::uint64_t microseconds = tv.tv_usec + total_microseconds(rel_time) % 1000000; ts.tv_nsec = (microseconds % 1000000) * 1000; ts.tv_sec = tv.tv_sec + total_seconds(rel_time) + microseconds / 1000000; // wow, this is quite a hack pthread_cond_timedwait(&m_cond, (::pthread_mutex_t*)&l.mutex(), &ts); }
bool dht_tracker::has_quota() { time_point now = clock_type::now(); time_duration delta = now - m_last_tick; m_last_tick = now; // add any new quota we've accrued since last time m_send_quota += int(std::uint64_t(m_settings.upload_rate_limit) * total_microseconds(delta) / 1000000); // allow 3 seconds worth of burst if (m_send_quota > 3 * m_settings.upload_rate_limit) m_send_quota = 3 * m_settings.upload_rate_limit; return m_send_quota > 0; }