Skip to content

Commit

Permalink
core: async - function to push task to a specific group of workers
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Nov 25, 2020
1 parent bd02d61 commit e71f60f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/core/async_task.c
Expand Up @@ -273,6 +273,38 @@ int async_task_push(async_task_t *task)
return 0;
}

/**
*
*/
int async_task_group_push(str *gname, async_task_t *task)
{
int len;
async_wgroup_t *awg = NULL;

if(_async_wgroup_list==NULL) {
LM_WARN("async task pushed, but no async group - ignoring\n");
return 0;
}
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) {
break;
}
}
if(awg==NULL) {
LM_WARN("group [%.*s] not found - ignoring\n", gname->len, gname->s);
return 0;
}
len = write(_async_wgroup_list->sockets[1], &task, sizeof(async_task_t*));
if(len<=0) {
LM_ERR("failed to pass the task [%p] to group [%.*s]\n", task,
gname->len, gname->s);
return -1;
}
LM_DBG("task [%p] sent to groupt [%.*s]\n", task, gname->len, gname->s);
return 0;
}

/**
*
*/
Expand Down
2 changes: 2 additions & 0 deletions src/core/async_task.h
Expand Up @@ -50,4 +50,6 @@ int async_task_set_usleep(int n);
int async_task_workers_get(void);
int async_task_workers_active(void);

int async_task_group_push(str *gname, async_task_t *task);

#endif

0 comments on commit e71f60f

Please sign in to comment.