Index: res/res_rtp_asterisk.c =================================================================== --- res/res_rtp_asterisk.c (revision 371435) +++ res/res_rtp_asterisk.c (working copy) @@ -413,17 +413,29 @@ ao2_ref(remote_candidate, -1); } +AST_THREADSTORAGE(pj_thread_storage); + /*! \brief Function used to check if the calling thread is registered with pjlib. If it is not it will be registered. */ static void pj_thread_register_check(void) { - pj_thread_desc desc; + pj_thread_desc *desc; pj_thread_t *thread; if (pj_thread_is_registered() == PJ_TRUE) { return; } - pj_thread_register("Asterisk Thread", desc, &thread); + ast_log(LOG_NOTICE, "Sizeof pj_thread_desc is %zu\n", sizeof(pj_thread_desc)); + + desc = ast_threadstorage_get(&pj_thread_storage, sizeof(pj_thread_desc)); + if (!desc) { + ast_log(LOG_NOTICE, "Oh crap\n"); + } + pj_bzero(*desc, sizeof(*desc)); + + if (pj_thread_register("Asterisk Thread", *desc, &thread) != PJ_SUCCESS) { + ast_log(LOG_ERROR, "Coudln't register thread with PJLIB?!\n"); + } } /*! \brief Helper function which updates an ast_sockaddr with the candidate used for the component */