rework Timer

I'm not sure how I broke it, but I know I don't have the patience
to fix it.  So replacing intrusive list and custom sorting with
std::list and std::list::merge().
This commit is contained in:
Michael Davidsaver
2018-04-04 21:03:11 -07:00
parent 7b8ef390ce
commit 1e1d94ed73
2 changed files with 87 additions and 112 deletions
+9 -3
View File
@@ -9,6 +9,8 @@
#ifndef TIMER_H
#define TIMER_H
#include <memory>
#include <list>
#include <stddef.h>
#include <stdlib.h>
#include <stddef.h>
@@ -55,11 +57,11 @@ public:
*/
virtual void timerStopped() = 0;
private:
TimerCallbackPtr next;
epicsTime timeToRun;
double period;
bool onList;
friend class Timer;
struct IncreasingTime;
};
/**
@@ -98,8 +100,9 @@ public:
/**
* cancel a callback.
* @param timerCallback the timerCallback to cancel.
* @returns true if the timer was queued, and now is cancelled
*/
void cancel(TimerCallbackPtr const &timerCallback);
bool cancel(TimerCallbackPtr const &timerCallback);
/**
* Is the callback scheduled to be called?
* @param timerCallback the timerCallback.
@@ -117,8 +120,11 @@ private:
// call with mutex held
void addElement(TimerCallbackPtr const &timerCallback);
TimerCallbackPtr head;
typedef std::list<TimerCallbackPtr> queue_t;
mutable Mutex mutex;
queue_t queue;
Event waitForWork;
bool alive;
Thread thread;