diff options
author | Stefan Metzmacher <metze@samba.org> | 2018-04-25 14:43:22 +0200 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2018-07-12 14:25:19 +0200 |
commit | 791c05144ee9296024cc0fdebe4afeaaf67e26bc (patch) | |
tree | 0fb8727394d5dab10c4b1489af0997b442d34eaf /lib/pthreadpool | |
parent | 245d684d28dab630f3d47ff61006a1fe3e5eeefa (diff) | |
download | samba-791c05144ee9296024cc0fdebe4afeaaf67e26bc.tar.gz |
pthreadpool: add pthreadpool_tevent_job_cancel()
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Diffstat (limited to 'lib/pthreadpool')
-rw-r--r-- | lib/pthreadpool/pthreadpool_tevent.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/pthreadpool/pthreadpool_tevent.c b/lib/pthreadpool/pthreadpool_tevent.c index 7c8015d2f59..bfd178c09a6 100644 --- a/lib/pthreadpool/pthreadpool_tevent.c +++ b/lib/pthreadpool/pthreadpool_tevent.c @@ -267,6 +267,7 @@ static void pthreadpool_tevent_job_fn(void *private_data); static void pthreadpool_tevent_job_done(struct tevent_context *ctx, struct tevent_immediate *im, void *private_data); +static bool pthreadpool_tevent_job_cancel(struct tevent_req *req); static int pthreadpool_tevent_job_destructor(struct pthreadpool_tevent_job *job) { @@ -441,6 +442,7 @@ struct tevent_req *pthreadpool_tevent_job_send( return tevent_req_post(req, ev); } + tevent_req_set_cancel_fn(req, pthreadpool_tevent_job_cancel); return req; } @@ -522,6 +524,44 @@ static void pthreadpool_tevent_job_done(struct tevent_context *ctx, tevent_req_done(state->req); } +static bool pthreadpool_tevent_job_cancel(struct tevent_req *req) +{ + struct pthreadpool_tevent_job_state *state = + tevent_req_data(req, + struct pthreadpool_tevent_job_state); + struct pthreadpool_tevent_job *job = state->job; + size_t num; + + if (job == NULL) { + return false; + } + + num = pthreadpool_cancel_job(job->pool->pool, 0, + pthreadpool_tevent_job_fn, + job); + if (num == 0) { + /* + * It was too late to cancel the request. + */ + return false; + } + + /* + * It was not too late to cancel the request. + * + * We can remove job->im, as it will never be used. + */ + TALLOC_FREE(job->im); + + /* + * pthreadpool_tevent_job_cleanup() + * will destroy the job. + */ + tevent_req_defer_callback(req, state->ev); + tevent_req_error(req, ECANCELED); + return true; +} + int pthreadpool_tevent_job_recv(struct tevent_req *req) { return tevent_req_simple_recv_unix(req); |