]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
transport management: Register thread with PJProject. 11/2611/4
authorMark Michelson <mmichelson@digium.com>
Thu, 14 Apr 2016 18:49:35 +0000 (13:49 -0500)
committerMark Michelson <mmichelson@digium.com>
Thu, 14 Apr 2016 19:25:13 +0000 (14:25 -0500)
The scheduler thread that kills idle TCP connections was not registering
with PJProject properly and causing assertions if PJProject was built in
debug mode.

This change registers the thread with PJProject the first time that the
scheduler callback executes.

AST-2016-005

Change-Id: I5f7a37e2c80726a99afe9dc2a4a69bdedf661283

res/res_pjsip_transport_management.c

index fffd1a9fbca4d55a1d5f962c988d0b93eda860fe..eb0240438d978e143cb1ab3adf5fe0f51493b43a 100644 (file)
@@ -101,11 +101,29 @@ static void *keepalive_transport_thread(void *data)
        return NULL;
 }
 
+AST_THREADSTORAGE(desc_storage);
+
 static int idle_sched_cb(const void *data)
 {
        struct monitored_transport *keepalive = (struct monitored_transport *) data;
        int sip_received = ast_atomic_fetchadd_int(&keepalive->sip_received, 0);
 
+       if (!pj_thread_is_registered()) {
+               pj_thread_t *thread;
+               pj_thread_desc *desc;
+
+               desc = ast_threadstorage_get(&desc_storage, sizeof(pj_thread_desc));
+               if (!desc) {
+                       ast_log(LOG_ERROR, "Could not get thread desc from thread-local storage.\n");
+                       ao2_ref(keepalive, -1);
+                       return 0;
+               }
+
+               pj_bzero(*desc, sizeof(*desc));
+
+               pj_thread_register("Transport Monitor", *desc, &thread);
+       }
+
        if (!sip_received) {
                ast_log(LOG_NOTICE, "Shutting down transport '%s' since no request was received in %d seconds\n",
                                keepalive->transport->info, IDLE_TIMEOUT);