MINOR: event_hdl: global sublist management clarification

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.
This commit is contained in:
Aurelien DARRAGON 2023-03-16 11:16:05 +01:00 committed by Christopher Faulet
parent d514ca45c6
commit 3a81e997ac
2 changed files with 11 additions and 12 deletions

View 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);

View 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);