utils: add running/stopped state to timers
Signed-off-by: Patrick McHardy <kaber@trash.net>
This commit is contained in:
parent
e795362c37
commit
a489a1626b
|
@ -88,12 +88,14 @@ struct dect_fd {
|
|||
*
|
||||
* @callback: callback to invoke on timer expiry
|
||||
* @data: libdect internal data
|
||||
* @state: libdect internal state
|
||||
* @priv: libdect user private timer storage
|
||||
*/
|
||||
struct dect_timer {
|
||||
void (*callback)(struct dect_handle *,
|
||||
struct dect_timer *);
|
||||
void *data;
|
||||
uint32_t state;
|
||||
uint8_t priv[];
|
||||
};
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef _UITLS_H
|
||||
#ifndef _UTILS_H
|
||||
#define _UTILS_H
|
||||
|
||||
#include <assert.h>
|
||||
|
@ -22,6 +22,11 @@ extern void *dect_malloc(const struct dect_handle *dh, size_t size);
|
|||
extern void *dect_zalloc(const struct dect_handle *dh, size_t size);
|
||||
extern void dect_free(const struct dect_handle *dh, void *ptr);
|
||||
|
||||
enum dect_timer_state {
|
||||
DECT_TIMER_STOPPED,
|
||||
DECT_TIMER_RUNNING,
|
||||
};
|
||||
|
||||
extern struct dect_timer *dect_alloc_timer(const struct dect_handle *dh);
|
||||
extern void dect_setup_timer(struct dect_timer *timer,
|
||||
void (*cb)(struct dect_handle *, struct dect_timer *),
|
||||
|
|
|
@ -67,12 +67,14 @@ void dect_start_timer(const struct dect_handle *dh,
|
|||
.tv_sec = timeout,
|
||||
};
|
||||
|
||||
timer->state = DECT_TIMER_RUNNING;
|
||||
dh->ops->event_ops->start_timer(dh, timer, &tv);
|
||||
}
|
||||
|
||||
void dect_stop_timer(const struct dect_handle *dh, struct dect_timer *timer)
|
||||
{
|
||||
dh->ops->event_ops->stop_timer(dh, timer);
|
||||
timer->state = DECT_TIMER_STOPPED;
|
||||
}
|
||||
|
||||
struct dect_fd *dect_alloc_fd(const struct dect_handle *dh)
|
||||
|
|
Reference in New Issue