diff --git a/src/timer.cpp b/src/timer.cpp index ed27891..5cbca57 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -9,12 +9,12 @@ std::mutex sc::timer::mutex; void sc::timer::callback(union sigval sv) { timer* self = reinterpret_cast(sv.sival_ptr); - self->_expired_func(self, self->_context); + self->_expired_func(self); } -sc::timer::timer(void(*expired_func)(timer*, void*), - double time, +sc::timer::timer(double time, bool repeat, + void(*expired_func)(timer*), void* context) : _id {}, _time {time}, _repeat {repeat}, _expired_func {expired_func}, _context {context} diff --git a/src/timer.hpp b/src/timer.hpp index 030be04..8f96da5 100644 --- a/src/timer.hpp +++ b/src/timer.hpp @@ -14,21 +14,22 @@ namespace sc { uint64_t _id {}; double _time {}; bool _repeat {}; - void (*_expired_func)(timer* self, void* context); + void (*_expired_func)(timer* self); void* _context {}; static void callback(union sigval); public: - timer(void(*expired_func)(timer*, void*), - double time, + timer(double time, bool repeat, - void* context); + void(*expired_func)(timer*), + void* context = nullptr); ~timer(); uint64_t id() const { return _id; } double time() const { return _time; } bool repeat() const { return _repeat; } + void* context() const { return _context; } bool is_armed() const; void time_left(struct itimerspec& cur_value) const;