MINOR: event_hdl: add event_hdl_async_equeue_size() function
Use event_hdl_async_equeue_size() in advanced async task handler to
get the near real-time event queue size.
By near real-time, you should understand that the queue size is not
updated during element insertion/removal, but shortly before insertion
and shortly after removal, so the size should reflect the approximate
queue size at a given time but should definitely not be used as a
unique source of truth.
If 68e692da0 ("MINOR: event_hdl: add event handler base api")
is being backported, then this commit should be backported with it.
diff --git a/src/event_hdl.c b/src/event_hdl.c
index 37a4adc..aecca87 100644
--- a/src/event_hdl.c
+++ b/src/event_hdl.c
@@ -317,7 +317,8 @@
* consumed the END event before the wakeup, and some tasks
* kill themselves (ie: normal async mode) when they receive such event
*/
- lock = MT_LIST_APPEND_LOCKED(del_sub->hdl.async_equeue, &del_sub->async_end->mt_list);
+ HA_ATOMIC_INC(&del_sub->hdl.async_equeue->size);
+ lock = MT_LIST_APPEND_LOCKED(&del_sub->hdl.async_equeue->head, &del_sub->async_end->mt_list);
/* wake up the task */
event_hdl_task_wakeup(del_sub->hdl.async_task);
@@ -462,7 +463,7 @@
/* memory error */
goto memory_error;
}
- MT_LIST_INIT(&task_ctx->e_queue);
+ event_hdl_async_equeue_init(&task_ctx->e_queue);
task_ctx->func = new_sub->hdl.async_ptr;
new_sub->hdl.async_equeue = &task_ctx->e_queue;
@@ -785,7 +786,8 @@
/* appending new event to event hdl queue */
MT_LIST_INIT(&new_event->mt_list);
- MT_LIST_APPEND(cur_sub->hdl.async_equeue, &new_event->mt_list);
+ HA_ATOMIC_INC(&cur_sub->hdl.async_equeue->size);
+ MT_LIST_APPEND(&cur_sub->hdl.async_equeue->head, &new_event->mt_list);
/* wake up the task */
event_hdl_task_wakeup(cur_sub->hdl.async_task);