1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#ifndef _TIMER_POSIX_H_
#define _TIMER_POSIX_H_
#ifndef _WIN32
#include <boost/function.hpp>
#include <boost/optional.hpp>
#include "timestamp.h"
#include "threadutils.h"
class Timer {
boost::function<void ()> callback;
Mutex mutex;
ConditionVariable cond;
// Stores the handle to a bgthread, which is created upon demand. (Previously
// the thread was created in the constructor, but addressed sanitized (ASAN)
// builds of R would hang when pthread_create was called during dlopen.)
boost::optional<tct_thrd_t> bgthread;
boost::optional<Timestamp> wakeAt;
bool stopped;
static int bg_main_func(void*);
void bg_main();
public:
Timer(const boost::function<void ()>& callback);
virtual ~Timer();
// Schedules the timer to fire next at the specified time.
// If the timer is currently scheduled to fire, that will
// be overwritten with this one (the timer only tracks one
// timestamp at a time).
void set(const Timestamp& timestamp);
};
#endif // _WIN32
#endif // _TIMER_POSIX_H_
|