From: Arvin Schnell Date: Mon, 6 Aug 2012 07:10:50 +0000 (+0200) Subject: - work on dbus interface X-Git-Tag: v0.1.3~167 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=145991ecd06e9c0a86a8d76927993adf84e28db9;p=thirdparty%2Fsnapper.git - work on dbus interface --- diff --git a/dbus/DBusMainLoop.cc b/dbus/DBusMainLoop.cc index aafc5f20..8ac8da58 100644 --- a/dbus/DBusMainLoop.cc +++ b/dbus/DBusMainLoop.cc @@ -90,9 +90,7 @@ namespace DBus if (idle_timeout >= 0) { - struct timespec tmp; - clock_gettime(CLOCK_MONOTONIC, &tmp); - int time_left = last_action - tmp.tv_sec + idle_timeout; + int time_left = last_action - monotonic_clock() + idle_timeout; if (timeout > time_left * 1000 || timeout == -1) timeout = time_left * 1000; @@ -148,9 +146,7 @@ namespace DBus if (idle_timeout >= 0) { - struct timespec tmp; - clock_gettime(CLOCK_MONOTONIC, &tmp); - int time_left = last_action - tmp.tv_sec + idle_timeout; + int time_left = last_action - monotonic_clock() + idle_timeout; if (time_left <= 0) break; @@ -169,9 +165,7 @@ namespace DBus void MainLoop::reset_idle_count() { - struct timespec tmp; - clock_gettime(CLOCK_MONOTONIC, &tmp); - last_action = tmp.tv_sec; + last_action = monotonic_clock(); } @@ -314,4 +308,13 @@ namespace DBus } } + + time_t + DBus::MainLoop::monotonic_clock() + { + struct timespec tmp; + clock_gettime(CLOCK_MONOTONIC, &tmp); + return tmp.tv_sec; + } + } diff --git a/dbus/DBusMainLoop.h b/dbus/DBusMainLoop.h index 5ac88010..5492c23b 100644 --- a/dbus/DBusMainLoop.h +++ b/dbus/DBusMainLoop.h @@ -91,6 +91,8 @@ namespace DBus int idle_timeout; time_t last_action; + static time_t monotonic_clock(); + }; } diff --git a/server/MetaSnapper.cc b/server/MetaSnapper.cc index a0ad9315..bc5d7248 100644 --- a/server/MetaSnapper.cc +++ b/server/MetaSnapper.cc @@ -34,11 +34,8 @@ MetaSnappers meta_snappers; RefCounter::RefCounter() - : counter(0) + : counter(0), last_used(monotonic_time()) { - struct timespec tmp; - clock_gettime(CLOCK_MONOTONIC, &tmp); - last_used = tmp.tv_sec; } @@ -59,11 +56,7 @@ RefCounter::dec_use_count() assert(counter > 0); if (--counter == 0) - { - struct timespec tmp; - clock_gettime(CLOCK_MONOTONIC, &tmp); - last_used = tmp.tv_sec; - } + last_used = monotonic_time(); return counter; } @@ -74,9 +67,7 @@ RefCounter::update_use_time() { boost::lock_guard lock(mutex); - struct timespec tmp; - clock_gettime(CLOCK_MONOTONIC, &tmp); - last_used = tmp.tv_sec; + last_used = monotonic_time(); } @@ -104,6 +95,15 @@ RefCounter::unused_for() const } +time_t +RefCounter::monotonic_time() +{ + struct timespec tmp; + clock_gettime(CLOCK_MONOTONIC, &tmp); + return tmp.tv_sec; +} + + bool get_user_uid(const char* username, uid_t& uid) { diff --git a/server/MetaSnapper.h b/server/MetaSnapper.h index b73d1c30..62d78093 100644 --- a/server/MetaSnapper.h +++ b/server/MetaSnapper.h @@ -50,6 +50,8 @@ public: private: + static time_t monotonic_time(); + mutable boost::mutex mutex; int counter;