Callback cleaner: context can be taken from timer
This commit is contained in:
parent
9dffae5f5d
commit
dbbbbd92bb
@ -9,12 +9,12 @@ std::mutex sc::timer::mutex;
|
||||
|
||||
void sc::timer::callback(union sigval sv) {
|
||||
timer* self = reinterpret_cast<timer*>(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}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user