Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Monotonic time #40

Closed
cgp1024 opened this Issue · 2 comments

2 participants

@cgp1024

Timer, Util::Timer, TimedNotificationQueue (and possibly others) could be changed not to use Timestamps, which are based on the system clock, and instead use some form of processor ticks to provide a monotonic time source.

The reasoning for this is that backwards system clock jumps may delay the firing of timers by the amount of time the clock was changed.

@cgp1024

Here's a first take at it:
Note: this isn't backwards compatible, since it replaces Poco::Timestamp with a 'long long'

diff -rubN poco-1.4.2p1-all.orig/Foundation/include/Poco/Microseconds.h poco-1.4.2p1-all/Foundation/include/Poco/Microseconds.h
--- poco-1.4.2p1-all.orig/Foundation/include/Poco/Microseconds.h    1969-12-31 18:00:00 -0600
+++ poco-1.4.2p1-all/Foundation/include/Poco/Microseconds.h 2012-12-21 11:51:02 -0600
@@ -0,0 +1,49 @@
+#ifndef MicroSeconds_INCLUDED
+#define MicroSeconds_INCLUDED
+
+#ifdef WIN32
+   #include <windows.h>
+#else
+   #include <ctime>
+   #ifndef CLOCK_MONOTONIC_RAW
+       #define CLOCK_MONOTONIC_RAW 4
+   #endif
+#endif
+
+#include <stdexcept>
+
+static long long sCountsPerSecond = 0; 
+
+#ifdef WIN32
+static long long Microseconds()
+{
+   LARGE_INTEGER s;
+   if (sCountsPerSecond == 0)
+   {
+       if (!QueryPerformanceFrequency(&s))
+           throw std::runtime_error("No performance counter available!");
+       sCountsPerSecond = s.QuadPart;
+   }
+   QueryPerformanceCounter(&s);
+   long long counts = s.QuadPart;
+   return counts*1000*1000/sCountsPerSecond;
+}
+
+#else
+static long long Microseconds()
+{
+   timespec res;
+   if (sCountsPerSecond == 0)
+   {
+       if (clock_getres(CLOCK_MONOTONIC_RAW, &res) != 0)
+           throw std::runtime_error("No monotonic clock available!");
+       sCountsPerSecond = 1000000000ULL;
+   }
+
+   clock_gettime(CLOCK_MONOTONIC_RAW, &res);
+   return res.tv_sec*1000000ULL+res.tv_nsec/1000;
+}  
+
+#endif
+
+#endif
diff -rubN poco-1.4.2p1-all.orig/Foundation/include/Poco/TimedNotificationQueue.h poco-1.4.2p1-all/Foundation/include/Poco/TimedNotificationQueue.h
--- poco-1.4.2p1-all.orig/Foundation/include/Poco/TimedNotificationQueue.h  2011-09-24 03:07:51 -0500
+++ poco-1.4.2p1-all/Foundation/include/Poco/TimedNotificationQueue.h   2012-12-21 11:48:26 -0600
@@ -63,7 +63,7 @@
    /// Notification is inserted according to the given Timestamp, with 
    /// lower Timestamp values being inserted before higher ones.
    ///
-   /// Notifications are dequeued in order of their timestamps.
+   /// Notifications are dequeued in order of their timestamps. (clock ticks)
    ///
    /// TimedNotificationQueue has some restrictions regarding multithreaded use.
    /// While multiple threads may enqueue notifications, only one thread at a
@@ -79,7 +79,7 @@
    ~TimedNotificationQueue();
        /// Destroys the TimedNotificationQueue.

-   void enqueueNotification(Notification::Ptr pNotification, Timestamp timestamp);
+   void enqueueNotification(Notification::Ptr pNotification, long long timestamp);
        /// Enqueues the given notification by adding it to
        /// the queue according to the given timestamp.
        /// Lower timestamp values are inserted before higher ones.
@@ -136,7 +136,7 @@
        /// behavior.

 protected:
-   typedef std::multimap<Timestamp, Notification::Ptr> NfQueue;
+   typedef std::multimap<long long, Notification::Ptr> NfQueue;
    Notification::Ptr dequeueOne(NfQueue::iterator& it);
    bool wait(Timestamp::TimeDiff interval);

diff -rubN poco-1.4.2p1-all.orig/Foundation/include/Poco/Timer.h poco-1.4.2p1-all/Foundation/include/Poco/Timer.h
--- poco-1.4.2p1-all.orig/Foundation/include/Poco/Timer.h   2011-09-24 03:07:51 -0500
+++ poco-1.4.2p1-all/Foundation/include/Poco/Timer.h    2012-12-21 11:48:23 -0600
@@ -45,7 +45,6 @@
 #include "Poco/Mutex.h"
 #include "Poco/Event.h"
 #include "Poco/Thread.h"
-#include "Poco/Timestamp.h"


 namespace Poco {
@@ -169,7 +168,7 @@
    Event         _done;
    long          _skipped;
    AbstractTimerCallback* _pCallback;
-   Timestamp              _nextInvocation;
+   long long     _nextInvocation;
    mutable FastMutex      _mutex;

    Timer(const Timer&);
diff -rubN poco-1.4.2p1-all.orig/Foundation/src/TimedNotificationQueue.cpp poco-1.4.2p1-all/Foundation/src/TimedNotificationQueue.cpp
--- poco-1.4.2p1-all.orig/Foundation/src/TimedNotificationQueue.cpp 2011-09-24 03:07:52 -0500
+++ poco-1.4.2p1-all/Foundation/src/TimedNotificationQueue.cpp  2012-12-21 11:52:30 -0600
@@ -36,6 +36,7 @@

 #include "Poco/TimedNotificationQueue.h"
 #include "Poco/Notification.h"
+#include "Poco/Microseconds.h"
 #include <limits>


@@ -53,7 +54,7 @@
 }


-void TimedNotificationQueue::enqueueNotification(Notification::Ptr pNotification, Timestamp timestamp)
+void TimedNotificationQueue::enqueueNotification(Notification::Ptr pNotification, long long timestamp)
 {
    poco_check_ptr (pNotification);

@@ -70,7 +71,7 @@
    NfQueue::iterator it = _nfQueue.begin();
    if (it != _nfQueue.end())
    {
-       Timestamp::TimeDiff sleep = -it->first.elapsed();
+       long long sleep = - (Microseconds() - it->first);
        if (sleep <= 0)
        {
            Notification::Ptr pNf = it->second;
@@ -91,7 +92,7 @@
        if (it != _nfQueue.end())
        {
            _mutex.unlock();
-           Timestamp::TimeDiff sleep = -it->first.elapsed();
+           long long sleep = - (Microseconds() - it->first);
            if (sleep <= 0)
            {
                return dequeueOne(it).duplicate();
@@ -120,8 +121,8 @@
        if (it != _nfQueue.end())
        {
            _mutex.unlock();
-           Poco::Timestamp now;
-           Timestamp::TimeDiff sleep = it->first - now;
+           long long now = Microseconds();
+           long long sleep = it->first - now;
            if (sleep <= 0)
            {
                return dequeueOne(it).duplicate();
@@ -134,7 +135,7 @@
                }
                else 
                {
-                   milliseconds -= static_cast<long>((now.elapsed() + 999)/1000);
+                   milliseconds -= static_cast<long>((Microseconds() - now + 999)/1000);
                    continue;
                }
            }
@@ -145,9 +146,9 @@
        }
        if (milliseconds > 0)
        {
-           Poco::Timestamp now;
+           long long now = Microseconds();
            _nfAvailable.tryWait(milliseconds);
-           milliseconds -= static_cast<long>((now.elapsed() + 999)/1000);
+           milliseconds -= static_cast<long>((Microseconds() - now + 999)/1000);
        }
        else return 0;
    }
@@ -160,11 +161,11 @@
    const Timestamp::TimeDiff MAX_SLEEP = 8*60*60*Timestamp::TimeDiff(1000000); // sleep at most 8 hours at a time
    while (interval > 0)
    {
-       Timestamp now;
+       long long now = Microseconds();
        Timestamp::TimeDiff sleep = interval <= MAX_SLEEP ? interval : MAX_SLEEP;
        if (_nfAvailable.tryWait(static_cast<long>((sleep + 999)/1000)))
            return true;
-       interval -= now.elapsed();
+       interval -= (Microseconds() - now);
    }
    return false;
 }
diff -rubN poco-1.4.2p1-all.orig/Foundation/src/Timer.cpp poco-1.4.2p1-all/Foundation/src/Timer.cpp
--- poco-1.4.2p1-all.orig/Foundation/src/Timer.cpp  2011-09-24 03:07:52 -0500
+++ poco-1.4.2p1-all/Foundation/src/Timer.cpp   2012-12-21 11:51:38 -0600
@@ -38,7 +38,7 @@
 #include "Poco/ThreadPool.h"
 #include "Poco/Exception.h"
 #include "Poco/ErrorHandler.h"
-
+#include "Poco/Microseconds.h"

 namespace Poco {

@@ -79,7 +79,7 @@

 void Timer::start(const AbstractTimerCallback& method, Thread::Priority priority, ThreadPool& threadPool)
 {
-   Timestamp nextInvocation;
+   long long nextInvocation = Microseconds(); 
    nextInvocation += _startInterval*1000;

    poco_assert (!_pCallback);
@@ -162,14 +162,14 @@

 void Timer::run()
 {
-   Poco::Timestamp now;
+   long long now;
    long interval(0);
    do
    {
        long sleep(0);
        do
        {
-           now.update();
+           now = Microseconds();
            sleep = static_cast<long>((_nextInvocation - now)/1000);
            if (sleep < 0)
            {
@@ -187,7 +187,7 @@
        if (_wakeUp.tryWait(sleep))
        {
            Poco::FastMutex::ScopedLock lock(_mutex);
-           _nextInvocation.update();
+           _nextInvocation = Microseconds();
            interval = _periodicInterval;
        }
        else
diff -rubN poco-1.4.2p1-all.orig/Foundation/testsuite/src/TimedNotificationQueueTest.cpp poco-1.4.2p1-all/Foundation/testsuite/src/TimedNotificationQueueTest.cpp
--- poco-1.4.2p1-all.orig/Foundation/testsuite/src/TimedNotificationQueueTest.cpp   2011-09-24 03:07:57 -0500
+++ poco-1.4.2p1-all/Foundation/testsuite/src/TimedNotificationQueueTest.cpp    2012-12-21 12:03:05 -0600
@@ -36,7 +36,7 @@
 #include "Poco/TimedNotificationQueue.h"
 #include "Poco/Notification.h"
 #include "Poco/Timestamp.h"
-
+#include "Poco/Microseconds.h"

 using Poco::TimedNotificationQueue;
 using Poco::Notification;
@@ -82,7 +82,7 @@
    assert (queue.size() == 0);
    Notification* pNf = queue.dequeueNotification();
    assertNullPtr(pNf);
-   queue.enqueueNotification(new Notification, Timestamp());
+   queue.enqueueNotification(new Notification, Microseconds());
    assert (!queue.empty());
    assert (queue.size() == 1);
    pNf = queue.dequeueNotification();
@@ -91,14 +91,10 @@
    assert (queue.size() == 0);
    pNf->release();

-   Poco::Timestamp ts1;
-   ts1 += 100000;
-   Poco::Timestamp ts2;
-   ts2 += 200000;
-   Poco::Timestamp ts3;
-   ts3 += 300000;
-   Poco::Timestamp ts4;
-   ts4 += 400000;
+   long long ts1 = Microseconds() + 100000;
+   long long ts2 = Microseconds() + 200000;
+   long long ts3 = Microseconds() + 300000;
+   long long ts4 = Microseconds() + 400000;

    queue.enqueueNotification(new QTestNotification("first"), ts1);
    queue.enqueueNotification(new QTestNotification("fourth"), ts4);
@@ -114,7 +110,7 @@
    assertNotNullPtr(pTNf);
    assert (pTNf->data() == "first");
    pTNf->release();
-   assert (ts1.elapsed() >= 0);
+   assert (Microseconds() - ts1 >= 0);
    assert (!queue.empty());
    assert (queue.size() == 3);

@@ -126,7 +122,7 @@
    assertNotNullPtr(pTNf);
    assert (pTNf->data() == "second");
    pTNf->release();
-   assert (ts2.elapsed() >= 0);
+   assert (Microseconds() - ts2 >= 0);
    assert (!queue.empty());
    assert (queue.size() == 2);

@@ -138,7 +134,7 @@
    assertNotNullPtr(pTNf);
    assert (pTNf->data() == "third");
    pTNf->release();
-   assert (ts3.elapsed() >= 0);
+   assert (Microseconds() - ts3 >= 0);
    assert (!queue.empty());
    assert (queue.size() == 1);

@@ -150,7 +146,7 @@
    assertNotNullPtr(pTNf);
    assert (pTNf->data() == "fourth");
    pTNf->release();
-   assert (ts4.elapsed() >= 0);
+   assert (Microseconds() - ts4 >= 0);
    assert (queue.empty());
    assert (queue.size() == 0);

@@ -163,14 +159,10 @@
 {
    TimedNotificationQueue queue;

-   Poco::Timestamp ts1;
-   ts1 += 100000;
-   Poco::Timestamp ts2;
-   ts2 += 200000;
-   Poco::Timestamp ts3;
-   ts3 += 300000;
-   Poco::Timestamp ts4;
-   ts4 += 400000;
+   long long ts1 = Microseconds() + 100000;
+   long long ts2 = Microseconds() + 200000;
+   long long ts3 = Microseconds() + 300000;
+   long long ts4 = Microseconds() + 400000;

    queue.enqueueNotification(new QTestNotification("first"), ts1);
    queue.enqueueNotification(new QTestNotification("fourth"), ts4);
@@ -182,7 +174,7 @@
    assertNotNullPtr(pTNf);
    assert (pTNf->data() == "first");
    pTNf->release();
-   assert (ts1.elapsed() >= 0);
+   assert (Microseconds() - ts1 >= 0);
    assert (!queue.empty());
    assert (queue.size() == 3);

@@ -190,7 +182,7 @@
    assertNotNullPtr(pTNf);
    assert (pTNf->data() == "second");
    pTNf->release();
-   assert (ts2.elapsed() >= 0);
+   assert (Microseconds() - ts2 >= 0);
    assert (!queue.empty());
    assert (queue.size() == 2);

@@ -198,7 +190,7 @@
    assertNotNullPtr(pTNf);
    assert (pTNf->data() == "third");
    pTNf->release();
-   assert (ts3.elapsed() >= 0);
+   assert (Microseconds() - ts3 >= 0);
    assert (!queue.empty());
    assert (queue.size() == 1);

@@ -206,7 +198,7 @@
    assertNotNullPtr(pTNf);
    assert (pTNf->data() == "fourth");
    pTNf->release();
-   assert (ts4.elapsed() >= 0);
+   assert (Microseconds() - ts4 >= 0);
    assert (queue.empty());
    assert (queue.size() == 0);
 }
@@ -216,14 +208,10 @@
 {
    TimedNotificationQueue queue;

-   Poco::Timestamp ts1;
-   ts1 += 200000;
-   Poco::Timestamp ts2;
-   ts2 += 400000;
-   Poco::Timestamp ts3;
-   ts3 += 600000;
-   Poco::Timestamp ts4;
-   ts4 += 800000;
+   long long ts1 = Microseconds() + 200000;
+   long long ts2 = Microseconds() + 400000;
+   long long ts3 = Microseconds() + 600000;
+   long long ts4 = Microseconds() + 800000;

    queue.enqueueNotification(new QTestNotification("first"), ts1);
    queue.enqueueNotification(new QTestNotification("fourth"), ts4);
@@ -239,7 +227,7 @@
    assertNotNullPtr(pTNf);
    assert (pTNf->data() == "first");
    pTNf->release();
-   assert (ts1.elapsed() >= 0);
+   assert (Microseconds() - ts1 >= 0);
    assert (!queue.empty());
    assert (queue.size() == 3);

@@ -247,7 +235,7 @@
    assertNotNullPtr(pTNf);
    assert (pTNf->data() == "second");
    pTNf->release();
-   assert (ts2.elapsed() >= 0);
+   assert (Microseconds() - ts2 >= 0);
    assert (!queue.empty());
    assert (queue.size() == 2);

@@ -255,7 +243,7 @@
    assertNotNullPtr(pTNf);
    assert (pTNf->data() == "third");
    pTNf->release();
-   assert (ts3.elapsed() >= 0);
+   assert (Microseconds() - ts3 >= 0);
    assert (!queue.empty());
    assert (queue.size() == 1);

@@ -263,7 +251,7 @@
    assertNotNullPtr(pTNf);
    assert (pTNf->data() == "fourth");
    pTNf->release();
-   assert (ts1.elapsed() >= 0);
+   assert (Microseconds() - ts1 >= 0);
    assert (queue.empty());
    assert (queue.size() == 0);
 }
diff -rubN poco-1.4.2p1-all.orig/Util/include/Poco/Util/Timer.h poco-1.4.2p1-all/Util/include/Poco/Util/Timer.h
--- poco-1.4.2p1-all.orig/Util/include/Poco/Util/Timer.h    2011-09-24 03:08:41 -0500
+++ poco-1.4.2p1-all/Util/include/Poco/Util/Timer.h 2012-12-21 11:48:26 -0600
@@ -50,7 +50,6 @@
 namespace Poco {
 namespace Util {

-
 class Util_API Timer: protected Poco::Runnable
    /// A Timer allows to schedule tasks (TimerTask objects) for future execution 
    /// in a background thread. Tasks may be scheduled for one-time execution, 
@@ -88,11 +87,8 @@
        /// running task finishes. If wait is true, waits
        /// until the queue has been purged.

-   void schedule(TimerTask::Ptr pTask, Poco::Timestamp time);
-       /// Schedules a task for execution at the specified time.
-       ///
-       /// If the time lies in the past, the task is executed
-       /// immediately.
+   void schedule(TimerTask::Ptr pTask, long long delay);
+       /// Schedules a task for execution after the specified delay

    void schedule(TimerTask::Ptr pTask, long delay, long interval);
        /// Schedules a task for periodic execution.
@@ -101,13 +97,6 @@
        /// Subsequently, the task is executed periodically with
        /// the given interval in milliseconds between invocations.

-   void schedule(TimerTask::Ptr pTask, Poco::Timestamp time, long interval);
-       /// Schedules a task for periodic execution.
-       ///
-       /// The task is first executed at the given time.
-       /// Subsequently, the task is executed periodically with
-       /// the given interval in milliseconds between invocations.
-       
    void scheduleAtFixedRate(TimerTask::Ptr pTask, long delay, long interval);
        /// Schedules a task for periodic execution at a fixed rate.
        ///
@@ -118,16 +107,6 @@
        /// If task execution takes longer than the given interval,
        /// further executions are delayed.

-   void scheduleAtFixedRate(TimerTask::Ptr pTask, Poco::Timestamp time, long interval);
-       /// Schedules a task for periodic execution at a fixed rate.
-       ///
-       /// The task is first executed at the given time.
-       /// Subsequently, the task is executed periodically 
-       /// every number of milliseconds specified by interval.
-       ///
-       /// If task execution takes longer than the given interval,
-       /// further executions are delayed.
-
 protected:
    void run();

diff -rubN poco-1.4.2p1-all.orig/Util/include/Poco/Util/TimerTask.h poco-1.4.2p1-all/Util/include/Poco/Util/TimerTask.h
--- poco-1.4.2p1-all.orig/Util/include/Poco/Util/TimerTask.h    2011-09-24 03:08:41 -0500
+++ poco-1.4.2p1-all/Util/include/Poco/Util/TimerTask.h 2012-12-21 11:48:26 -0600
@@ -44,7 +44,6 @@
 #include "Poco/Runnable.h"
 #include "Poco/RefCountedObject.h"
 #include "Poco/AutoPtr.h"
-#include "Poco/Timestamp.h"


 namespace Poco {
@@ -76,7 +75,7 @@
        /// Returns true iff the TimerTask has been cancelled by a call
        /// to cancel().

-   Poco::Timestamp lastExecution() const;
+   long long lastExecution() const;
        /// Returns the time of the last execution of the timer task.
        ///
        /// Returns 0 if the timer has never been executed.
@@ -89,7 +88,7 @@
    TimerTask(const TimerTask&);
    TimerTask& operator = (const TimerTask&);

-   Poco::Timestamp _lastExecution;
+   long long _lastExecution;
    bool _isCancelled;

    friend class TaskNotification;
@@ -105,7 +104,7 @@
 }


-inline Poco::Timestamp TimerTask::lastExecution() const
+inline long long TimerTask::lastExecution() const
 {
    return _lastExecution;
 }
diff -rubN poco-1.4.2p1-all.orig/Util/src/Timer.cpp poco-1.4.2p1-all/Util/src/Timer.cpp
--- poco-1.4.2p1-all.orig/Util/src/Timer.cpp    2011-09-24 03:08:41 -0500
+++ poco-1.4.2p1-all/Util/src/Timer.cpp 2012-12-21 11:53:22 -0600
@@ -38,10 +38,11 @@
 #include "Poco/Notification.h"
 #include "Poco/ErrorHandler.h"
 #include "Poco/Event.h"
+#include "Poco/Microseconds.h"


-using Poco::ErrorHandler;

+using Poco::ErrorHandler;

 namespace Poco {
 namespace Util {
@@ -144,7 +145,7 @@
        {
            try
            {
-               _pTask->_lastExecution.update();
+               _pTask->_lastExecution = Microseconds();
                _pTask->run();
            }
            catch (Exception& exc)
@@ -185,15 +186,18 @@
    {   
        TaskNotification::execute();

+       if (_interval > 0)
+       {
        if (!task()->isCancelled())
        {
-           Poco::Timestamp now;
-           Poco::Timestamp nextExecution;
-           nextExecution += static_cast<Poco::Timestamp::TimeDiff>(_interval)*1000;
+               long long now = Microseconds();
+               long long nextExecution = Microseconds();;
+               nextExecution += _interval*1000LL;
            if (nextExecution < now) nextExecution = now;
            queue().enqueueNotification(this, nextExecution);
            duplicate();
        }
+       }
        return true;        
    }

@@ -205,7 +209,7 @@
 class FixedRateTaskNotification: public TaskNotification
 {
 public:
-   FixedRateTaskNotification(Poco::TimedNotificationQueue& queue, TimerTask::Ptr pTask, long interval, Poco::Timestamp time):
+   FixedRateTaskNotification(Poco::TimedNotificationQueue& queue, TimerTask::Ptr pTask, long interval, long long time):
        TaskNotification(queue, pTask),
        _interval(interval),
        _nextExecution(time)
@@ -220,20 +224,23 @@
    {   
        TaskNotification::execute();

+       if (_interval > 0)
+       {
        if (!task()->isCancelled())
        {
-           Poco::Timestamp now;
-           _nextExecution += static_cast<Poco::Timestamp::TimeDiff>(_interval)*1000;
+               long long now = Microseconds();
+               _nextExecution += _interval*1000LL;
            if (_nextExecution < now) _nextExecution = now;
            queue().enqueueNotification(this, _nextExecution);
            duplicate();
        }
+       }
        return true;            
    }

 private:
    long _interval;
-   Poco::Timestamp _nextExecution;
+   long long _nextExecution;
 };


@@ -268,36 +275,26 @@
 }


-void Timer::schedule(TimerTask::Ptr pTask, Poco::Timestamp time)
+void Timer::schedule(TimerTask::Ptr pTask, long long delay)
 {
+   long long time = Microseconds();
+   time += delay*1000LL;
    _queue.enqueueNotification(new TaskNotification(_queue, pTask), time);
 }


 void Timer::schedule(TimerTask::Ptr pTask, long delay, long interval)
 {
-   Poco::Timestamp time;
-   time += static_cast<Poco::Timestamp::TimeDiff>(delay)*1000;
-   schedule(pTask, time, interval);
-}
-
-
-void Timer::schedule(TimerTask::Ptr pTask, Poco::Timestamp time, long interval)
-{
+   long long time = Microseconds();
+   time += delay*1000LL;
    _queue.enqueueNotification(new PeriodicTaskNotification(_queue, pTask, interval), time);
 }


 void Timer::scheduleAtFixedRate(TimerTask::Ptr pTask, long delay, long interval)
 {
-   Poco::Timestamp time;
-   time += static_cast<Poco::Timestamp::TimeDiff>(delay)*1000;
-   scheduleAtFixedRate(pTask, time, interval);
-}
-
-
-void Timer::scheduleAtFixedRate(TimerTask::Ptr pTask, Poco::Timestamp time, long interval)
-{
+   long long time = Microseconds();
+   time += delay*1000LL;
    _queue.enqueueNotification(new FixedRateTaskNotification(_queue, pTask, interval, time), time);
 }

diff -rubN poco-1.4.2p1-all.orig/Util/testsuite/src/TimerTest.cpp poco-1.4.2p1-all/Util/testsuite/src/TimerTest.cpp
--- poco-1.4.2p1-all.orig/Util/testsuite/src/TimerTest.cpp  2011-09-24 03:08:43 -0500
+++ poco-1.4.2p1-all/Util/testsuite/src/TimerTest.cpp   2012-12-21 12:10:20 -0600
@@ -35,7 +35,7 @@
 #include "CppUnit/TestSuite.h"
 #include "Poco/Util/Timer.h"
 #include "Poco/Util/TimerTaskAdapter.h"
-
+#include "Poco/Microseconds.h"

 using Poco::Util::Timer;
 using Poco::Util::TimerTask;
@@ -57,7 +57,7 @@
 {
    Timer timer;

-   Timestamp time;
+   long long  time = Microseconds();
    time += 1000000;

    TimerTask::Ptr pTask = new TimerTaskAdapter<TimerTest>(*this, &TimerTest::onTimer);
@@ -75,7 +75,7 @@
 {
    Timer timer;

-   Timestamp time;
+   long long time = Microseconds();

    TimerTask::Ptr pTask = new TimerTaskAdapter<TimerTest>(*this, &TimerTest::onTimer);

@@ -84,16 +84,16 @@
    timer.schedule(pTask, 500, 500);

    _event.wait();
-   assert (time.elapsed() >= 590000);
-   assert (pTask->lastExecution().elapsed() < 130000);
+   assert (Microseconds() - time >= 590000);
+   assert (Microseconds() - pTask->lastExecution() < 130000);

    _event.wait();
-   assert (time.elapsed() >= 1190000);
-   assert (pTask->lastExecution().elapsed() < 130000);
+   assert (Microseconds() - time >= 1190000);
+   assert (Microseconds() - pTask->lastExecution() < 130000);

    _event.wait();
-   assert (time.elapsed() >= 1790000);
-   assert (pTask->lastExecution().elapsed() < 130000);
+   assert (Microseconds() - time >= 1790000);
+   assert (Microseconds() - pTask->lastExecution() < 130000);

    pTask->cancel();
    assert (pTask->isCancelled());
@@ -104,7 +104,7 @@
 {
    Timer timer;

-   Timestamp time;
+   long long time = Microseconds();

    TimerTask::Ptr pTask = new TimerTaskAdapter<TimerTest>(*this, &TimerTest::onTimer);

@@ -113,16 +113,16 @@
    timer.scheduleAtFixedRate(pTask, 500, 500);

    _event.wait();
-   assert (time.elapsed() >= 500000);
-   assert (pTask->lastExecution().elapsed() < 130000);
+   assert (Microseconds() - time >= 500000);
+   assert (Microseconds() - pTask->lastExecution() < 130000);

    _event.wait();
-   assert (time.elapsed() >= 1000000);
-   assert (pTask->lastExecution().elapsed() < 130000);
+   assert (Microseconds() - time >= 1000000);
+   assert (Microseconds() - pTask->lastExecution() < 130000);

    _event.wait();
-   assert (time.elapsed() >= 1500000);
-   assert (pTask->lastExecution().elapsed() < 130000);
+   assert (Microseconds() - time >= 1500000);
+   assert (Microseconds() - pTask->lastExecution() < 130000);

    pTask->cancel();
    assert (pTask->isCancelled());
@aleks-f
Owner

It is better to fork, create branch, post only commit/diff links here and send pull request when you are ready to propose the change.

@aleks-f aleks-f closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.