Allow timeouts to be cancelled
This commit is contained in:
parent
c29c3fa014
commit
2d27df0268
3 changed files with 19 additions and 11 deletions
|
@ -717,7 +717,6 @@ static void rebootpwr_run_state(struct fpi_ssm *ssm)
|
|||
{
|
||||
struct fp_img_dev *dev = ssm->priv;
|
||||
struct uru4k_dev *urudev = dev->priv;
|
||||
int r;
|
||||
|
||||
switch (ssm->cur_state) {
|
||||
case REBOOTPWR_SET_HWSTAT:
|
||||
|
@ -734,9 +733,8 @@ static void rebootpwr_run_state(struct fpi_ssm *ssm)
|
|||
fpi_ssm_next_state(ssm);
|
||||
break;
|
||||
case REBOOTPWR_PAUSE:
|
||||
r = fpi_timeout_add(10, rebootpwr_pause_cb, ssm);
|
||||
if (r < 0)
|
||||
fpi_ssm_mark_aborted(ssm, r);
|
||||
if (fpi_timeout_add(10, rebootpwr_pause_cb, ssm) == NULL)
|
||||
fpi_ssm_mark_aborted(ssm, -ETIME);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -827,9 +825,8 @@ static void powerup_run_state(struct fpi_ssm *ssm)
|
|||
fpi_ssm_next_state(ssm);
|
||||
break;
|
||||
case POWERUP_PAUSE:
|
||||
r = fpi_timeout_add(10, powerup_pause_cb, ssm);
|
||||
if (r < 0)
|
||||
fpi_ssm_mark_aborted(ssm, r);
|
||||
if (fpi_timeout_add(10, powerup_pause_cb, ssm) == NULL)
|
||||
fpi_ssm_mark_aborted(ssm, -ETIME);
|
||||
break;
|
||||
case POWERUP_CHALLENGE_RESPONSE:
|
||||
r = do_challenge_response(dev, powerup_challenge_response_cb, ssm);
|
||||
|
|
|
@ -333,7 +333,10 @@ void fpi_poll_exit(void);
|
|||
|
||||
typedef void (*fpi_timeout_fn)(void *data);
|
||||
|
||||
int fpi_timeout_add(unsigned int msec, fpi_timeout_fn callback, void *data);
|
||||
struct fpi_timeout;
|
||||
struct fpi_timeout *fpi_timeout_add(unsigned int msec, fpi_timeout_fn callback,
|
||||
void *data);
|
||||
void fpi_timeout_cancel(struct fpi_timeout *timeout);
|
||||
|
||||
/* async drv <--> lib comms */
|
||||
|
||||
|
|
|
@ -89,7 +89,8 @@ static int timeout_sort_fn(gconstpointer _a, gconstpointer _b)
|
|||
/* A timeout is the asynchronous equivalent of sleeping. You create a timeout
|
||||
* saying that you'd like to have a function invoked at a certain time in
|
||||
* the future. */
|
||||
int fpi_timeout_add(unsigned int msec, fpi_timeout_fn callback, void *data)
|
||||
struct fpi_timeout *fpi_timeout_add(unsigned int msec, fpi_timeout_fn callback,
|
||||
void *data)
|
||||
{
|
||||
struct timespec ts;
|
||||
struct timeval add_msec;
|
||||
|
@ -101,7 +102,7 @@ int fpi_timeout_add(unsigned int msec, fpi_timeout_fn callback, void *data)
|
|||
r = clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
if (r < 0) {
|
||||
fp_err("failed to read monotonic clock, errno=%d", errno);
|
||||
return r;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
timeout = g_malloc(sizeof(*timeout));
|
||||
|
@ -118,7 +119,14 @@ int fpi_timeout_add(unsigned int msec, fpi_timeout_fn callback, void *data)
|
|||
active_timers = g_slist_insert_sorted(active_timers, timeout,
|
||||
timeout_sort_fn);
|
||||
|
||||
return 0;
|
||||
return timeout;
|
||||
}
|
||||
|
||||
void fpi_timeout_cancel(struct fpi_timeout *timeout)
|
||||
{
|
||||
fp_dbg("");
|
||||
active_timers = g_slist_remove(active_timers, timeout);
|
||||
g_free(timeout);
|
||||
}
|
||||
|
||||
/* get the expiry time and optionally the timeout structure for the next
|
||||
|
|
Loading…
Reference in a new issue