dect
/
libdect
Archived
13
0
Fork 0

timer: fix dect_timer_running() for timers already expired

Make sure dect_timer_running() returns the proper result for timers that
have already expired by adding a new function to invoke the timer callback
that resets the state to DECT_TIMER_STOPPED before invoking the callback.

Additionally unexport the timer structure and add an accessor function
for the private storage area to make sure all timer invocations happen
through the new function.

Signed-off-by: Patrick McHardy <kaber@trash.net>
This commit is contained in:
Patrick McHardy 2010-03-31 03:14:08 +02:00
parent 92e6ddcfe8
commit 3f19c0cef1
4 changed files with 35 additions and 20 deletions

View File

@ -49,16 +49,14 @@ static void unregister_fd(const struct dect_handle *dh, struct dect_fd *dfd)
static void timer_expire(int fd, short mask, void *data)
{
struct dect_timer *timer = data;
timer->callback(dh, timer);
dect_run_timer(dh, data);
}
static void start_timer(const struct dect_handle *dh,
struct dect_timer *timer,
const struct timeval *tv)
{
struct event *ev = (struct event *)timer->priv;
struct event *ev = dect_timer_priv(timer);
evtimer_set(ev, timer_expire, timer);
evtimer_add(ev, (struct timeval *)tv);
@ -66,7 +64,7 @@ static void start_timer(const struct dect_handle *dh,
static void stop_timer(const struct dect_handle *dh, struct dect_timer *timer)
{
struct event *ev = (struct event *)timer->priv;
struct event *ev = dect_timer_priv(timer);
evtimer_del(ev);
}

View File

@ -88,21 +88,9 @@ struct dect_fd {
uint8_t priv[];
};
/**
* struct dect_timer - libdect timer
*
* @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[];
};
struct dect_timer;
extern void *dect_timer_priv(struct dect_timer *timer);
extern void dect_run_timer(struct dect_handle *dh, struct dect_timer *timer);
struct timeval;
struct dect_event_ops {

View File

@ -8,6 +8,22 @@ enum dect_timer_state {
DECT_TIMER_RUNNING,
};
/**
* struct dect_timer - libdect timer
*
* @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;
enum dect_timer_state state;
uint8_t priv[];
};
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 *),

View File

@ -18,6 +18,12 @@ struct dect_timer *dect_alloc_timer(const struct dect_handle *dh)
}
EXPORT_SYMBOL(dect_alloc_timer);
void *dect_timer_priv(struct dect_timer *timer)
{
return timer->priv;
}
EXPORT_SYMBOL(dect_timer_priv);
void dect_setup_timer(struct dect_timer *timer,
void (*cb)(struct dect_handle *, struct dect_timer *),
void *data)
@ -56,3 +62,10 @@ bool dect_timer_running(const struct dect_timer *timer)
return timer->state == DECT_TIMER_RUNNING;
}
EXPORT_SYMBOL(dect_timer_running);
void dect_run_timer(struct dect_handle *dh, struct dect_timer *timer)
{
timer->state = DECT_TIMER_STOPPED;
timer->callback(dh, timer);
}
EXPORT_SYMBOL(dect_run_timer);