Module: kamailio Branch: master Commit: f8b08d01a98be3e5c823af769e20f0ccee1af629 URL: https://github.com/kamailio/kamailio/commit/f8b08d01a98be3e5c823af769e20f0cc...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2024-05-05T19:53:14+02:00
core: async task - functions to find group and send tasks
---
Modified: src/core/async_task.c Modified: src/core/async_task.h
---
Diff: https://github.com/kamailio/kamailio/commit/f8b08d01a98be3e5c823af769e20f0cc... Patch: https://github.com/kamailio/kamailio/commit/f8b08d01a98be3e5c823af769e20f0cc...
---
diff --git a/src/core/async_task.c b/src/core/async_task.c index 376924ae571..bce7ed51faa 100644 --- a/src/core/async_task.c +++ b/src/core/async_task.c @@ -413,6 +413,26 @@ int async_task_push(async_task_t *task) return 0; }
+/** + * + */ +async_wgroup_t *async_task_group_find(str *gname) +{ + async_wgroup_t *awg = NULL; + + if(_async_wgroup_list == NULL) { + LM_WARN("no async group\n"); + return NULL; + } + for(awg = _async_wgroup_list; awg != NULL; awg = awg->next) { + if(awg->name.len == gname->len + && memcmp(awg->name.s, gname->s, gname->len) == 0) { + return awg; + } + } + return NULL; +} + /** * */ @@ -445,6 +465,27 @@ int async_task_group_push(str *gname, async_task_t *task) return 0; }
+/** + * + */ +int async_task_group_send(async_wgroup_t *awg, async_task_t *task) +{ + int len; + if(awg == NULL) { + LM_WARN("group not provided\n"); + return -1; + } + len = write(awg->sockets[1], &task, sizeof(async_task_t *)); + if(len <= 0) { + LM_ERR("failed to pass the task [%p] to group [%.*s]\n", task, + awg->name.len, awg->name.s); + return -1; + } + LM_DBG("task [%p] sent to group [%.*s]\n", task, awg->name.len, + awg->name.s); + return 0; +} + /** * */ diff --git a/src/core/async_task.h b/src/core/async_task.h index 5a3cc19e232..58386bba8bd 100644 --- a/src/core/async_task.h +++ b/src/core/async_task.h @@ -53,7 +53,9 @@ int async_task_set_usleep(int n); int async_task_workers_get(void); int async_task_workers_active(void); async_wgroup_t *async_task_workers_get_crt(void); +async_wgroup_t *async_task_group_find(str *gname);
int async_task_group_push(str *gname, async_task_t *task); +int async_task_group_send(async_wgroup_t *awg, async_task_t *task);
#endif