uloop: add uloop_cancelling function
Returns true if uloop_run is still running and uloop_cancelled is set Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
parent
3b6181b63d
commit
de3f14b643
2 changed files with 10 additions and 3 deletions
11
uloop.c
11
uloop.c
|
@ -63,6 +63,7 @@ static bool do_sigchld = false;
|
|||
|
||||
static struct uloop_fd_event cur_fds[ULOOP_MAX_EVENTS];
|
||||
static int cur_fd, cur_nfds;
|
||||
static int uloop_run_depth = 0;
|
||||
|
||||
int uloop_fd_add(struct uloop_fd *sock, unsigned int flags);
|
||||
|
||||
|
@ -514,16 +515,20 @@ static void uloop_clear_processes(void)
|
|||
uloop_process_delete(p);
|
||||
}
|
||||
|
||||
bool uloop_cancelling(void)
|
||||
{
|
||||
return uloop_run_depth > 0 && uloop_cancelled;
|
||||
}
|
||||
|
||||
int uloop_run(void)
|
||||
{
|
||||
static int recursive_calls = 0;
|
||||
struct timeval tv;
|
||||
|
||||
/*
|
||||
* Handlers are only updated for the first call to uloop_run() (and restored
|
||||
* when this call is done).
|
||||
*/
|
||||
if (!recursive_calls++)
|
||||
if (!uloop_run_depth++)
|
||||
uloop_setup_signals(true);
|
||||
|
||||
uloop_status = 0;
|
||||
|
@ -543,7 +548,7 @@ int uloop_run(void)
|
|||
uloop_run_events(uloop_get_next_timeout(&tv));
|
||||
}
|
||||
|
||||
if (!--recursive_calls)
|
||||
if (!--uloop_run_depth)
|
||||
uloop_setup_signals(false);
|
||||
|
||||
return uloop_status;
|
||||
|
|
2
uloop.h
2
uloop.h
|
@ -97,6 +97,8 @@ int uloop_timeout_remaining(struct uloop_timeout *timeout);
|
|||
int uloop_process_add(struct uloop_process *p);
|
||||
int uloop_process_delete(struct uloop_process *p);
|
||||
|
||||
bool uloop_cancelling(void);
|
||||
|
||||
static inline void uloop_end(void)
|
||||
{
|
||||
uloop_cancelled = true;
|
||||
|
|
Loading…
Reference in a new issue