]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: event_hdl: global sublist management clarification
authorAurelien DARRAGON <adarragon@haproxy.com>
Thu, 16 Mar 2023 10:16:05 +0000 (11:16 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 5 Apr 2023 06:58:17 +0000 (08:58 +0200)
event_hdl_sub_list_init() and event_hdl_sub_list_destroy() don't expect
to be called with a NULL argument (to use global subscription list
implicitly), simply because the global subscription list init and
destroy is internally managed.

Adding BUG_ON() to detect such invalid usages, and updating some comments
to prevent confusion around these functions.

If 68e692da0 ("MINOR: event_hdl: add event handler base api")
is being backported, then this commit should be backported with it.

include/haproxy/event_hdl.h
src/event_hdl.c

index ee133a2e33bdfea93f274db259066e2d3bc99e82..097f881fe11e9f1faf61c7f0f5471efee6798a9a 100644 (file)
@@ -425,20 +425,13 @@ static inline struct event_hdl_async_event *event_hdl_async_equeue_pop(event_hdl
        return MT_LIST_POP(queue, struct event_hdl_async_event *, mt_list);
 }
 
-/* use this to initialize an event subscription list
- * (event_hdl_sub_list)
- */
-static inline void event_hdl_sub_list_init(event_hdl_sub_list *sub_list)
-{
-       MT_LIST_INIT(&sub_list->head);
-       HA_SPIN_INIT(&sub_list->insert_lock);
-}
+/* use this to initialize <sub_list> event subscription list */
+void event_hdl_sub_list_init(event_hdl_sub_list *sub_list);
 
 /* use this function when you need to destroy <sub_list>
- * subscription list
+ * event subscription list
  * All subscriptions will be removed and properly freed according
  * to their types
- * If <sub_list> is NULL, global subscription list will be used.
  */
 void event_hdl_sub_list_destroy(event_hdl_sub_list *sub_list);
 
index 86fcbf5778160bc4f227b7cecbd29ee9fb7d13a8..c3bacfea65764e723edc40b23013a49061c694ac 100644 (file)
@@ -759,6 +759,13 @@ int event_hdl_publish(event_hdl_sub_list *sub_list,
        }
 }
 
+void event_hdl_sub_list_init(event_hdl_sub_list *sub_list)
+{
+       BUG_ON(!sub_list); /* unexpected, global sublist is managed internally */
+       MT_LIST_INIT(&sub_list->head);
+       HA_SPIN_INIT(&sub_list->insert_lock);
+}
+
 /* when a subscription list is no longer used, call this
  * to do the cleanup and make sure all related subscriptions are
  * safely ended according to their types
@@ -768,8 +775,7 @@ void event_hdl_sub_list_destroy(event_hdl_sub_list *sub_list)
        struct event_hdl_sub *cur_sub;
        struct mt_list *elt1, elt2;
 
-       if (!sub_list)
-               sub_list = &global_event_hdl_sub_list; /* fall back to global list */
+       BUG_ON(!sub_list); /* unexpected, global sublist is managed internally */
        mt_list_for_each_entry_safe(cur_sub, &sub_list->head, mt_list, elt1, elt2) {
                /* remove cur elem from list */
                MT_LIST_DELETE_SAFE(elt1);