From: Stefan Metzmacher Date: Fri, 23 May 2025 12:26:38 +0000 (+0200) Subject: tevent: add tevent_reset_immediate() X-Git-Tag: tevent-0.17.0~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=708ee7834d1f2fbadd7a21ea1e503238e4b30d70;p=thirdparty%2Fsamba.git tevent: add tevent_reset_immediate() This is a much better api than using tevent_schedule_immediate() with a NULL handler, while the tevent_context is still required as argument. Note the tevent-0.16.2.sigs changes will be reverted in the 'tevent 0.17.0' commit. Signed-off-by: Stefan Metzmacher Reviewed-by: Volker Lendecke --- diff --git a/lib/tevent/ABI/tevent-0.16.2.sigs b/lib/tevent/ABI/tevent-0.16.2.sigs index 4b129912b6f..4cd4226ab80 100644 --- a/lib/tevent/ABI/tevent-0.16.2.sigs +++ b/lib/tevent/ABI/tevent-0.16.2.sigs @@ -44,6 +44,7 @@ tevent_common_fd_get_flags: uint16_t (struct tevent_fd *) tevent_common_fd_set_close_fn: void (struct tevent_fd *, tevent_fd_close_fn_t) tevent_common_fd_set_flags: void (struct tevent_fd *, uint16_t) tevent_common_have_events: bool (struct tevent_context *) +tevent_common_immediate_cancel: void (struct tevent_immediate *) tevent_common_invoke_fd_handler: int (struct tevent_fd *, uint16_t, bool *) tevent_common_invoke_immediate_handler: int (struct tevent_immediate *, bool *) tevent_common_invoke_signal_handler: int (struct tevent_signal *, int, int, void *, bool *) @@ -124,6 +125,7 @@ tevent_req_set_cleanup_fn: void (struct tevent_req *, tevent_req_cleanup_fn) tevent_req_set_endtime: bool (struct tevent_req *, struct tevent_context *, struct timeval) tevent_req_set_print_fn: void (struct tevent_req *, tevent_req_print_fn) tevent_req_set_profile: bool (struct tevent_req *) +tevent_reset_immediate: void (struct tevent_immediate *) tevent_sa_info_queue_count: size_t (void) tevent_set_abort_fn: void (void (*)(const char *)) tevent_set_debug: int (struct tevent_context *, void (*)(void *, enum tevent_debug_level, const char *, va_list), void *) diff --git a/lib/tevent/tevent.c b/lib/tevent/tevent.c index c3e688510e1..c9f57fece94 100644 --- a/lib/tevent/tevent.c +++ b/lib/tevent/tevent.c @@ -751,6 +751,14 @@ void _tevent_schedule_immediate(struct tevent_immediate *im, handler_name, location); } +/* + reset an immediate event +*/ +void tevent_reset_immediate(struct tevent_immediate *im) +{ + tevent_common_immediate_cancel(im); +} + /* add a signal event diff --git a/lib/tevent/tevent.h b/lib/tevent/tevent.h index b94504981b9..30825315c82 100644 --- a/lib/tevent/tevent.h +++ b/lib/tevent/tevent.h @@ -362,6 +362,12 @@ struct tevent_immediate *_tevent_create_immediate(TALLOC_CTX *mem_ctx, * @param[in] ctx The tevent_context to run this event * @param[in] handler The event handler to run when this event fires * @param[in] private_data Data to pass to the event handler + * + * @note To cancel an immediate handler, call talloc_free() on the event returned + * from tevent_create_immediate() or call tevent_reset_immediate() to + * keep the structure alive for later usage. + * + * @see tevent_create_immediate, tevent_reset_immediate */ void tevent_schedule_immediate(struct tevent_immediate *im, struct tevent_context *ctx, @@ -379,6 +385,17 @@ void _tevent_schedule_immediate(struct tevent_immediate *im, #handler, __location__); #endif +/** + * Reset an event for immediate execution. + * + * Undo the effect of tevent_schedule_immediate(). + * + * @param[in] im The tevent_immediate object to clear the handler + * + * @see tevent_schedule_immediate. + */ +void tevent_reset_immediate(struct tevent_immediate *im); + /** * @brief Associate a custom tag with the event. * diff --git a/lib/tevent/tevent_immediate.c b/lib/tevent/tevent_immediate.c index 82f92f1bd78..bf44c45a14b 100644 --- a/lib/tevent/tevent_immediate.c +++ b/lib/tevent/tevent_immediate.c @@ -29,7 +29,7 @@ #include "tevent_internal.h" #include "tevent_util.h" -static void tevent_common_immediate_cancel(struct tevent_immediate *im) +void tevent_common_immediate_cancel(struct tevent_immediate *im) { const char *create_location = im->create_location; bool busy = im->busy; diff --git a/lib/tevent/tevent_internal.h b/lib/tevent/tevent_internal.h index d43dcbfcccf..049a3a6c2e2 100644 --- a/lib/tevent/tevent_internal.h +++ b/lib/tevent/tevent_internal.h @@ -499,6 +499,7 @@ int tevent_common_invoke_timer_handler(struct tevent_timer *te, struct timeval current_time, bool *removed); +void tevent_common_immediate_cancel(struct tevent_immediate *im); void tevent_common_schedule_immediate(struct tevent_immediate *im, struct tevent_context *ev, tevent_immediate_handler_t handler,