Browse code

core: async - function to push task to a specific group of workers

Daniel-Constantin Mierla authored on 25/11/2020 13:04:21
Showing 2 changed files
... ...
@@ -273,6 +273,38 @@ int async_task_push(async_task_t *task)
273 273
 	return 0;
274 274
 }
275 275
 
276
+/**
277
+ *
278
+ */
279
+int async_task_group_push(str *gname, async_task_t *task)
280
+{
281
+	int len;
282
+	async_wgroup_t *awg = NULL;
283
+
284
+	if(_async_wgroup_list==NULL) {
285
+		LM_WARN("async task pushed, but no async group - ignoring\n");
286
+		return 0;
287
+	}
288
+	for(awg=_async_wgroup_list; awg!=NULL; awg=awg->next) {
289
+		if(awg->name.len==gname->len
290
+				&& memcmp(awg->name.s, gname->s, gname->len)==0) {
291
+			break;
292
+		}
293
+	}
294
+	if(awg==NULL) {
295
+		LM_WARN("group [%.*s] not found - ignoring\n", gname->len, gname->s);
296
+		return 0;
297
+	}
298
+	len = write(_async_wgroup_list->sockets[1], &task, sizeof(async_task_t*));
299
+	if(len<=0) {
300
+		LM_ERR("failed to pass the task [%p] to group [%.*s]\n", task,
301
+				gname->len, gname->s);
302
+		return -1;
303
+	}
304
+	LM_DBG("task [%p] sent to groupt [%.*s]\n", task, gname->len, gname->s);
305
+	return 0;
306
+}
307
+
276 308
 /**
277 309
  *
278 310
  */
... ...
@@ -50,4 +50,6 @@ int async_task_set_usleep(int n);
50 50
 int async_task_workers_get(void);
51 51
 int async_task_workers_active(void);
52 52
 
53
+int async_task_group_push(str *gname, async_task_t *task);
54
+
53 55
 #endif