summaryrefslogtreecommitdiff
path: root/main/threadpool.c
diff options
context:
space:
mode:
authorRichard Mudgett <rmudgett@digium.com>2015-06-05 15:37:33 -0500
committerRichard Mudgett <rmudgett@digium.com>2015-07-06 12:52:36 -0500
commitada7346792452f021911063668997f79fdabc1f1 (patch)
tree1a7dd441d2f9f9bc33c176894470790a469179dd /main/threadpool.c
parentcba550df7aea4fdac8a182215ddacb555824e088 (diff)
res_pjsip: Need to use the same serializer for a pjproject SIP transaction.
All send/receive processing for a SIP transaction needs to be done under the same threadpool serializer to prevent reentrancy problems inside pjproject and res_pjsip. * Add threadpool API call to get the current serializer associated with the worker thread. * Pick a serializer from a pool of default serializers if the caller of res_pjsip.c:ast_sip_push_task() does not provide one. This is a simple way to ensure that all outgoing SIP request messages are processed under a serializer. Otherwise, any place where a pushed task is done that would result in an outgoing out-of-dialog request would need to be modified to supply a serializer. Serializers from the default serializer pool are picked in a round robin sequence for simplicity. A side effect is that the default serializer pool will limit the growth of the thread pool from random tasks. This is not necessarily a bad thing. * Made pjsip_distributor.c save the thread's serializer name on the outgoing request tdata struct so the response can be processed under the same serializer. This is a cherry-pick from master. **** ASTERISK-25115 Change-Id: Iea71c16ce1132017b5791635e198b8c27973f40a NOTE: session_inv_on_state_changed() is disassociating the dialog from the session when the invite dialog becomes PJSIP_INV_STATE_DISCONNECTED. Unfortunately this is a tad too soon because our BYE request transaction has not completed yet. ASTERISK-25183 #close Reported by: Matt Jordan Change-Id: I8bad0ae1daf18d75b8c9e55874244b7962df2d0a
Diffstat (limited to 'main/threadpool.c')
-rw-r--r--main/threadpool.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/main/threadpool.c b/main/threadpool.c
index 479938959..d97a7adb8 100644
--- a/main/threadpool.c
+++ b/main/threadpool.c
@@ -1259,13 +1259,17 @@ static struct serializer *serializer_create(struct ast_threadpool *pool,
return ser;
}
+AST_THREADSTORAGE_RAW(current_serializer);
+
static int execute_tasks(void *data)
{
struct ast_taskprocessor *tps = data;
+ ast_threadstorage_set_ptr(&current_serializer, tps);
while (ast_taskprocessor_execute(tps)) {
/* No-op */
}
+ ast_threadstorage_set_ptr(&current_serializer, NULL);
ast_taskprocessor_unreference(tps);
return 0;
@@ -1305,6 +1309,11 @@ static struct ast_taskprocessor_listener_callbacks serializer_tps_listener_callb
.shutdown = serializer_shutdown,
};
+struct ast_taskprocessor *ast_threadpool_serializer_get_current(void)
+{
+ return ast_threadstorage_get_ptr(&current_serializer);
+}
+
struct ast_taskprocessor *ast_threadpool_serializer_group(const char *name,
struct ast_threadpool *pool, struct ast_serializer_shutdown_group *shutdown_group)
{