[sr-dev] git:master:e71f60ff: core: async - function to push task to a specific group of workers

Daniel-Constantin Mierla miconda at gmail.com
Wed Nov 25 14:06:50 CET 2020


Module: kamailio
Branch: master
Commit: e71f60ffc51654512863e583d863f7247381281d
URL: https://github.com/kamailio/kamailio/commit/e71f60ffc51654512863e583d863f7247381281d

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2020-11-25T14:04:21+01:00

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

---

Modified: src/core/async_task.c
Modified: src/core/async_task.h

---

Diff:  https://github.com/kamailio/kamailio/commit/e71f60ffc51654512863e583d863f7247381281d.diff
Patch: https://github.com/kamailio/kamailio/commit/e71f60ffc51654512863e583d863f7247381281d.patch

---

diff --git a/src/core/async_task.c b/src/core/async_task.c
index dc7fe7c57f..b6532f69e1 100644
--- a/src/core/async_task.c
+++ b/src/core/async_task.c
@@ -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;
+}
+
 /**
  *
  */
diff --git a/src/core/async_task.h b/src/core/async_task.h
index 13f6c64b0c..84f1e9c954 100644
--- a/src/core/async_task.h
+++ b/src/core/async_task.h
@@ -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




More information about the sr-dev mailing list