]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
tevent: add tevent_reset_immediate()
authorStefan Metzmacher <metze@samba.org>
Fri, 23 May 2025 12:26:38 +0000 (14:26 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 18 Jun 2025 17:52:37 +0000 (17:52 +0000)
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 <metze@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
lib/tevent/ABI/tevent-0.16.2.sigs
lib/tevent/tevent.c
lib/tevent/tevent.h
lib/tevent/tevent_immediate.c
lib/tevent/tevent_internal.h

index 4b129912b6f81eea9c4e79ac95b1dba10cbeacd4..4cd4226ab807ec20ddc72b01e1a50046383b2eeb 100644 (file)
@@ -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 *)
index c3e688510e1915ad2d0d310cca460728b0c9f9ee..c9f57fece940a83dca5d93e60885c56d685c07c3 100644 (file)
@@ -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
 
index b94504981b97ee987f47ad68db3f53e4fba48504..30825315c82571df877d5cd26323b1257598a8ea 100644 (file)
@@ -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.
  *
index 82f92f1bd7862a6d046380ccd497d34eebd4e9ff..bf44c45a14b641d841fc5dad950f644393f57fef 100644 (file)
@@ -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;
index d43dcbfcccf3951e9ea374751c7b2dae5d76071c..049a3a6c2e278ed84dcc6ce48640ab4009962ca5 100644 (file)
@@ -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,