on_idle scheduling
@@ -2856,6 +2856,10 @@ typedef struct {
static callback_collection_s callback_collection[FIO_CALL_NEVER + 1];
+static void fio_state_on_idle_perform(void *task, void *arg) {
+ ((void (*)(void *))task)(arg);
+}
+
static inline void fio_state_callback_ensure(callback_collection_s *c) {
if (c->callbacks.next)
return;
@@ -2909,7 +2913,7 @@ void fio_state_callback_force(callback_type_e c_type) {
fio_ls_embd_s copy = FIO_LS_INIT(copy);
fio_lock(&callback_collection[c_type].lock);
fio_state_callback_ensure(&callback_collection[c_type]);
- switch (c_type) { /* the difference between `shift` and `push` */
+ switch (c_type) { /* the difference between `unshift` and `push` */
case FIO_CALL_ON_INITIALIZE: /* overflow */
case FIO_CALL_PRE_START: /* overflow */
case FIO_CALL_BEFORE_FORK: /* overflow */
@@ -2917,7 +2921,6 @@ void fio_state_callback_force(callback_type_e c_type) {
case FIO_CALL_IN_CHILD: /* overflow */
case FIO_CALL_IN_MASTER: /* overflow */
case FIO_CALL_ON_START: /* overflow */
- case FIO_CALL_ON_IDLE: /* overflow */
FIO_LS_EMBD_FOR(&callback_collection[c_type].callbacks, pos) {
callback_data_s *tmp = fio_malloc(sizeof(*tmp));
FIO_ASSERT_ALLOC(tmp);
@@ -2926,6 +2929,14 @@ void fio_state_callback_force(callback_type_e c_type) {
}
break;
+ case FIO_CALL_ON_IDLE: /* idle callbacks are orderless and evented */
+ FIO_LS_EMBD_FOR(&callback_collection[c_type].callbacks, pos) {
+ callback_data_s *tmp = FIO_LS_EMBD_OBJ(callback_data_s, node, pos);
+ fio_defer(fio_state_on_idle_perform, (void *)(uintptr_t)tmp->func,
+ tmp->arg);
+ }
+ break;
+
case FIO_CALL_ON_SHUTDOWN: /* overflow */
case FIO_CALL_ON_FINISH: /* overflow */
case FIO_CALL_ON_PARENT_CRUSH: /* overflow */
