#ifndef MSP_TIME_TIMER_H_
#define MSP_TIME_TIMER_H_
-#include <queue>
+#include <set>
#include <sigc++/sigc++.h>
#include "../core/mutex.h"
#include "../core/semaphore.h"
Slot(const TimeStamp &);
const TimeStamp &get_timeout() const { return timeout; }
bool increment();
- bool operator<(const Slot &) const;
};
private:
- typedef bool (*fSlotCompare)(Slot *, Slot *);
+ struct SlotProxy
+ {
+ Slot *slot;
+
+ SlotProxy(Slot *);
+ bool operator<(const SlotProxy &) const;
+ };
- std::priority_queue<Slot *, std::vector<Slot *>, fSlotCompare> slots;
+ std::set<SlotProxy> slots;
Semaphore sem;
Mutex mutex;
public:
- Timer();
~Timer();
/**
*/
Slot &add(const TimeStamp &);
+ /**
+ Cancels a previously added timer.
+ */
+ void cancel(Slot &);
+
/**
Checks all timers, executing any that have timed out. If block is true,
waits until one times out.
won't return until a timer is added from another thread.
*/
void tick(bool block=true);
-private:
- static bool slot_compare(Slot *, Slot *);
+
+ TimeStamp get_next_timeout() const;
};
} // namespace Time