summaryrefslogtreecommitdiff
path: root/pjmedia
diff options
context:
space:
mode:
authorLiong Sauw Ming <ming@teluu.com>2013-04-16 09:12:59 +0000
committerLiong Sauw Ming <ming@teluu.com>2013-04-16 09:12:59 +0000
commitcda3be17d6ae41c9fbf2e623e8f2b09789659d13 (patch)
tree1f80f473f3e0073400fd4456a26ac6384d89144e /pjmedia
parent8f21c6c2853eebe5b507907e8bc1fbf683c5fbc9 (diff)
Fixed #1658: Stop media endpoint's worker threads first when destroying media subsystem
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4474 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjmedia')
-rw-r--r--pjmedia/include/pjmedia/endpoint.h9
-rw-r--r--pjmedia/src/pjmedia/endpoint.c37
2 files changed, 33 insertions, 13 deletions
diff --git a/pjmedia/include/pjmedia/endpoint.h b/pjmedia/include/pjmedia/endpoint.h
index 0e5debb8..f300571b 100644
--- a/pjmedia/include/pjmedia/endpoint.h
+++ b/pjmedia/include/pjmedia/endpoint.h
@@ -150,6 +150,15 @@ PJ_DECL(unsigned) pjmedia_endpt_get_thread_count(pjmedia_endpt *endpt);
PJ_DECL(pj_thread_t*) pjmedia_endpt_get_thread(pjmedia_endpt *endpt,
unsigned index);
+/**
+ * Stop and destroy the worker threads of the media endpoint
+ *
+ * @param endpt The media endpoint instance.
+ *
+ * @return PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) pjmedia_endpt_stop_threads(pjmedia_endpt *endpt);
+
/**
* Request the media endpoint to create pool.
diff --git a/pjmedia/src/pjmedia/endpoint.c b/pjmedia/src/pjmedia/endpoint.c
index 9ac90177..10f1b534 100644
--- a/pjmedia/src/pjmedia/endpoint.c
+++ b/pjmedia/src/pjmedia/endpoint.c
@@ -209,20 +209,8 @@ PJ_DEF(pjmedia_codec_mgr*) pjmedia_endpt_get_codec_mgr(pjmedia_endpt *endpt)
PJ_DEF(pj_status_t) pjmedia_endpt_destroy (pjmedia_endpt *endpt)
{
exit_cb *ecb;
- unsigned i;
- PJ_ASSERT_RETURN(endpt, PJ_EINVAL);
-
- endpt->quit_flag = 1;
-
- /* Destroy threads */
- for (i=0; i<endpt->thread_cnt; ++i) {
- if (endpt->thread[i]) {
- pj_thread_join(endpt->thread[i]);
- pj_thread_destroy(endpt->thread[i]);
- endpt->thread[i] = NULL;
- }
- }
+ pjmedia_endpt_stop_threads(endpt);
/* Destroy internal ioqueue */
if (endpt->ioqueue && endpt->own_ioqueue) {
@@ -314,6 +302,29 @@ PJ_DEF(pj_thread_t*) pjmedia_endpt_get_thread(pjmedia_endpt *endpt,
}
/**
+ * Stop and destroy the worker threads of the media endpoint
+ */
+PJ_DEF(pj_status_t) pjmedia_endpt_stop_threads(pjmedia_endpt *endpt)
+{
+ unsigned i;
+
+ PJ_ASSERT_RETURN(endpt, PJ_EINVAL);
+
+ endpt->quit_flag = 1;
+
+ /* Destroy threads */
+ for (i=0; i<endpt->thread_cnt; ++i) {
+ if (endpt->thread[i]) {
+ pj_thread_join(endpt->thread[i]);
+ pj_thread_destroy(endpt->thread[i]);
+ endpt->thread[i] = NULL;
+ }
+ }
+
+ return PJ_SUCCESS;
+}
+
+/**
* Worker thread proc.
*/
static int PJ_THREAD_FUNC worker_proc(void *arg)