mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-06 22:29:23 +00:00
Moved over to a next time based display update.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@320 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
+23
-18
@@ -1,6 +1,7 @@
|
||||
#ifndef LIBTORRENT_TIMER_H
|
||||
#define LIBTORRENT_TIMER_H
|
||||
|
||||
#include <limits>
|
||||
#include <inttypes.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
@@ -13,18 +14,10 @@ class Timer {
|
||||
Timer(int64_t usec) : m_time(usec) {}
|
||||
Timer(timeval tv) : m_time((int64_t)(uint32_t)tv.tv_sec * 1000000 + (int64_t)(uint32_t)tv.tv_usec % 1000000) {}
|
||||
|
||||
int64_t usec() const { return m_time; }
|
||||
int64_t usec() const { return m_time; }
|
||||
timeval tval() const { return (timeval) { m_time / 1000000, m_time % 1000000}; }
|
||||
|
||||
timeval tval() const { return (timeval) { m_time / 1000000, m_time % 1000000}; }
|
||||
|
||||
Timer operator - (const Timer& t) const { return Timer(m_time - t.m_time); }
|
||||
Timer operator + (const Timer& t) const { return Timer(m_time + t.m_time); }
|
||||
|
||||
Timer operator -= (int64_t t) { m_time -= t; return *this; }
|
||||
Timer operator -= (const Timer& t) { m_time -= t.m_time; return *this; }
|
||||
|
||||
Timer operator += (int64_t t) { m_time += t; return *this; }
|
||||
Timer operator += (const Timer& t) { m_time += t.m_time; return *this; }
|
||||
Timer round_seconds() const { return (m_time / 1000000) * 1000000; }
|
||||
|
||||
static Timer current() {
|
||||
timeval t;
|
||||
@@ -38,15 +31,27 @@ class Timer {
|
||||
|
||||
// TODO: Find out if it's worth it. The kernel is supposed to cache the
|
||||
// time. Though system calls would be more expensive than we can afford.
|
||||
static Timer cache() { return Timer(m_cache); }
|
||||
static Timer cache() { return Timer(m_cache); }
|
||||
|
||||
static void update() { m_cache = Timer::current().usec(); }
|
||||
static Timer min() { return 0; }
|
||||
static Timer max() { return (int64_t)std::numeric_limits<time_t>::max() * 1000000; }
|
||||
|
||||
bool operator < (const Timer& t) const { return m_time < t.m_time; }
|
||||
bool operator > (const Timer& t) const { return m_time > t.m_time; }
|
||||
bool operator <= (const Timer& t) const { return m_time <= t.m_time; }
|
||||
bool operator >= (const Timer& t) const { return m_time >= t.m_time; }
|
||||
bool operator == (const Timer& t) const { return m_time == t.m_time; }
|
||||
static void update() { m_cache = Timer::current().usec(); }
|
||||
|
||||
Timer operator - (const Timer& t) const { return Timer(m_time - t.m_time); }
|
||||
Timer operator + (const Timer& t) const { return Timer(m_time + t.m_time); }
|
||||
|
||||
Timer operator -= (int64_t t) { m_time -= t; return *this; }
|
||||
Timer operator -= (const Timer& t) { m_time -= t.m_time; return *this; }
|
||||
|
||||
Timer operator += (int64_t t) { m_time += t; return *this; }
|
||||
Timer operator += (const Timer& t) { m_time += t.m_time; return *this; }
|
||||
|
||||
bool operator < (const Timer& t) const { return m_time < t.m_time; }
|
||||
bool operator > (const Timer& t) const { return m_time > t.m_time; }
|
||||
bool operator <= (const Timer& t) const { return m_time <= t.m_time; }
|
||||
bool operator >= (const Timer& t) const { return m_time >= t.m_time; }
|
||||
bool operator == (const Timer& t) const { return m_time == t.m_time; }
|
||||
|
||||
private:
|
||||
int64_t m_time;
|
||||
|
||||
Reference in New Issue
Block a user