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) {
|
void sc::timer::callback(union sigval sv) {
|
||||||
timer* self = reinterpret_cast<timer*>(sv.sival_ptr);
|
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*),
|
sc::timer::timer(double time,
|
||||||
double time,
|
|
||||||
bool repeat,
|
bool repeat,
|
||||||
|
void(*expired_func)(timer*),
|
||||||
void* context)
|
void* context)
|
||||||
: _id {}, _time {time}, _repeat {repeat},
|
: _id {}, _time {time}, _repeat {repeat},
|
||||||
_expired_func {expired_func}, _context {context}
|
_expired_func {expired_func}, _context {context}
|
||||||
|
@ -14,21 +14,22 @@ namespace sc {
|
|||||||
uint64_t _id {};
|
uint64_t _id {};
|
||||||
double _time {};
|
double _time {};
|
||||||
bool _repeat {};
|
bool _repeat {};
|
||||||
void (*_expired_func)(timer* self, void* context);
|
void (*_expired_func)(timer* self);
|
||||||
void* _context {};
|
void* _context {};
|
||||||
|
|
||||||
static void callback(union sigval);
|
static void callback(union sigval);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
timer(void(*expired_func)(timer*, void*),
|
timer(double time,
|
||||||
double time,
|
|
||||||
bool repeat,
|
bool repeat,
|
||||||
void* context);
|
void(*expired_func)(timer*),
|
||||||
|
void* context = nullptr);
|
||||||
~timer();
|
~timer();
|
||||||
|
|
||||||
uint64_t id() const { return _id; }
|
uint64_t id() const { return _id; }
|
||||||
double time() const { return _time; }
|
double time() const { return _time; }
|
||||||
bool repeat() const { return _repeat; }
|
bool repeat() const { return _repeat; }
|
||||||
|
void* context() const { return _context; }
|
||||||
|
|
||||||
bool is_armed() const;
|
bool is_armed() const;
|
||||||
void time_left(struct itimerspec& cur_value) const;
|
void time_left(struct itimerspec& cur_value) const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user