2024-01-23 16:23:11 +01:00
|
|
|
#ifndef _timer_H_
|
|
|
|
#define _timer_H_
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
namespace sc {
|
|
|
|
|
|
|
|
class timer {
|
|
|
|
static uint64_t next_id;
|
|
|
|
static std::mutex mutex;
|
|
|
|
|
|
|
|
timer_t _tid;
|
|
|
|
uint64_t _id;
|
|
|
|
double _time;
|
|
|
|
bool _repeat;
|
|
|
|
|
|
|
|
public:
|
|
|
|
timer(void(*callback)(union sigval), double time, bool repeat = false);
|
|
|
|
~timer();
|
|
|
|
|
2024-01-23 19:05:20 +01:00
|
|
|
void time_left(struct itimerspec& cur_value) const;
|
|
|
|
double time_left() const;
|
|
|
|
double time() const { return _time; }
|
2024-01-23 16:23:11 +01:00
|
|
|
bool is_armed() const;
|
|
|
|
bool repeat() const { return _repeat; }
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // _timer_H_
|