diff options
author | Liong Sauw Ming <ming@teluu.com> | 2014-01-16 05:30:46 +0000 |
---|---|---|
committer | Liong Sauw Ming <ming@teluu.com> | 2014-01-16 05:30:46 +0000 |
commit | e56ea14ab8531ee3cec375460577d1b89bf62e26 (patch) | |
tree | df77c3acb961514b2022ee9e030071b691145920 /pjsip/src/pjsua-lib/pjsua_core.c | |
parent | bd1c47e995a3a844868f1d4dcc8f77f163ae721b (diff) |
Closed #1723: Merging pjsua2 branch into trunk
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4704 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip/src/pjsua-lib/pjsua_core.c')
-rw-r--r-- | pjsip/src/pjsua-lib/pjsua_core.c | 60 |
1 files changed, 45 insertions, 15 deletions
diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c index 8b0f0e62..e4893401 100644 --- a/pjsip/src/pjsua-lib/pjsua_core.c +++ b/pjsip/src/pjsua-lib/pjsua_core.c @@ -699,6 +699,50 @@ static int worker_thread(void *arg) return 0; } +PJ_DEF(pj_status_t) pjsua_register_worker_thread(const char *name) +{ + pj_thread_desc desc; + pj_thread_t *thread; + pj_status_t status; + + if (pjsua_var.thread_quit_flag) + return PJ_EGONE; + + status = pj_thread_register(NULL, desc, &thread); + if (status != PJ_SUCCESS) + return status; + + if (name) + PJ_LOG(4,(THIS_FILE, "Worker thread %s started", name)); + + worker_thread(NULL); + + if (name) + PJ_LOG(4,(THIS_FILE, "Worker thread %s stopped", name)); + + return PJ_SUCCESS; +} + +PJ_DEF(void) pjsua_stop_worker_threads(void) +{ + unsigned i; + + pjsua_var.thread_quit_flag = 1; + + /* Wait worker threads to quit: */ + for (i=0; i<(int)pjsua_var.ua_cfg.thread_cnt; ++i) { + if (pjsua_var.thread[i]) { + pj_status_t status; + status = pj_thread_join(pjsua_var.thread[i]); + if (status != PJ_SUCCESS) { + PJ_PERROR(4,(THIS_FILE, status, "Error joining worker thread")); + pj_thread_sleep(1000); + } + pj_thread_destroy(pjsua_var.thread[i]); + pjsua_var.thread[i] = NULL; + } + } +} /* Init random seed */ static void init_random_seed(void) @@ -1478,21 +1522,7 @@ PJ_DEF(pj_status_t) pjsua_destroy2(unsigned flags) } /* Signal threads to quit: */ - pjsua_var.thread_quit_flag = 1; - - /* Wait worker threads to quit: */ - for (i=0; i<(int)pjsua_var.ua_cfg.thread_cnt; ++i) { - if (pjsua_var.thread[i]) { - pj_status_t status; - status = pj_thread_join(pjsua_var.thread[i]); - if (status != PJ_SUCCESS) { - PJ_PERROR(4,(THIS_FILE, status, "Error joining worker thread")); - pj_thread_sleep(1000); - } - pj_thread_destroy(pjsua_var.thread[i]); - pjsua_var.thread[i] = NULL; - } - } + pjsua_stop_worker_threads(); if (pjsua_var.endpt) { unsigned max_wait; |