added Clock class which provides a monotonic clock on most platforms and is now used by Poco::Timer, Poco::Stopwatch, Poco::TimedNotificationQueue and Poco::UtilTimer to avoid issues when the system time is changed

This commit is contained in:
Guenter Obiltschnig
2013-12-12 18:33:29 +01:00
parent 5edb90c48e
commit ac2b26fcb9
47 changed files with 884 additions and 48 deletions

View File

@@ -1,7 +1,7 @@
//
// TimedNotificationQueue.h
//
// $Id: //poco/1.4/Foundation/include/Poco/TimedNotificationQueue.h#1 $
// $Id: //poco/1.4/Foundation/include/Poco/TimedNotificationQueue.h#2 $
//
// Library: Foundation
// Package: Notifications
@@ -45,6 +45,7 @@
#include "Poco/Mutex.h"
#include "Poco/Event.h"
#include "Poco/Timestamp.h"
#include "Poco/Clock.h"
#include <map>
@@ -87,6 +88,17 @@ public:
/// a call like
/// notificationQueue.enqueueNotification(new MyNotification, someTime);
/// does not result in a memory leak.
///
/// The Timestamp is converted to an equivalent Clock value.
void enqueueNotification(Notification::Ptr pNotification, Clock clock);
/// Enqueues the given notification by adding it to
/// the queue according to the given clock value.
/// Lower clock values are inserted before higher ones.
/// The queue takes ownership of the notification, thus
/// a call like
/// notificationQueue.enqueueNotification(new MyNotification, someTime);
/// does not result in a memory leak.
Notification* dequeueNotification();
/// Dequeues the next pending notification with a timestamp
@@ -102,11 +114,9 @@ public:
Notification* waitDequeueNotification();
/// Dequeues the next pending notification.
/// If no notification is available, waits for a notification
/// to be enqueued.
/// to be enqueued.
/// The caller gains ownership of the notification and
/// is expected to release it when done with it.
/// This method returns 0 (null) if wakeUpWaitingThreads()
/// has been called by another thread.
///
/// It is highly recommended that the result is immediately
/// assigned to a Notification::Ptr, to avoid potential
@@ -138,13 +148,13 @@ public:
/// behavior.
protected:
typedef std::multimap<Timestamp, Notification::Ptr> NfQueue;
typedef std::multimap<Clock, Notification::Ptr> NfQueue;
Notification::Ptr dequeueOne(NfQueue::iterator& it);
bool wait(Timestamp::TimeDiff interval);
bool wait(Clock::ClockDiff interval);
private:
NfQueue _nfQueue;
Event _nfAvailable;
Event _nfAvailable;
mutable FastMutex _mutex;
};