[Asterisk-code-review] pjsip: modify taskprocessor scheduling algorithm from round-... (asterisk[13])

Alexei Gradinari asteriskteam at digium.com
Mon Nov 5 12:49:17 CST 2018


Alexei Gradinari has uploaded this change for review. ( https://gerrit.asterisk.org/10587


Change subject: pjsip: modify taskprocessor scheduling algorithm from round-robin to least-size
......................................................................

pjsip: modify taskprocessor scheduling algorithm from round-robin to least-size

This patch modifies the algorithm from round-robin to least-size
for picking PJSIP taskprocessor from default serializer pool.

Change-Id: I7b8d8cc2c2490494f579374b6af0a4868e3a37cd
---
M res/res_pjsip.c
1 file changed, 11 insertions(+), 16 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/87/10587/1

diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index 03b86e9..58f20b8 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -2505,9 +2505,6 @@
 /*! Number of serializers in pool if one not supplied. */
 #define SERIALIZER_POOL_SIZE		8
 
-/*! Next serializer pool index to use. */
-static int serializer_pool_pos;
-
 /*! Pool of serializers to use if not supplied. */
 static struct ast_taskprocessor *serializer_pool[SERIALIZER_POOL_SIZE];
 
@@ -4332,22 +4329,20 @@
 
 static struct ast_taskprocessor *serializer_pool_pick(void)
 {
-	struct ast_taskprocessor *serializer;
+        int idx;
+        int pos;
 
-	unsigned int pos;
+        if (!serializer_pool[0]) {
+                return NULL;
+        }
 
-	/*
-	 * Pick a serializer to use from the pool.
-	 *
-	 * Note: We don't care about any reentrancy behavior
-	 * when incrementing serializer_pool_pos.  If it gets
-	 * incorrectly incremented it doesn't matter.
-	 */
-	pos = serializer_pool_pos++;
-	pos %= SERIALIZER_POOL_SIZE;
-	serializer = serializer_pool[pos];
+        for (pos = idx = 0; idx < SERIALIZER_POOL_SIZE; ++idx) {
+                if (ast_taskprocessor_size(serializer_pool[idx]) < ast_taskprocessor_size(serializer_pool[pos])) {
+                        pos = idx;
+                }
+        }
 
-	return serializer;
+        return serializer_pool[pos]; 
 }
 
 int ast_sip_push_task(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data)

-- 
To view, visit https://gerrit.asterisk.org/10587
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7b8d8cc2c2490494f579374b6af0a4868e3a37cd
Gerrit-Change-Number: 10587
Gerrit-PatchSet: 1
Gerrit-Owner: Alexei Gradinari <alex2grad at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20181105/f5044d48/attachment.html>


More information about the asterisk-code-review mailing list