summaryrefslogtreecommitdiff
path: root/pjlib/src/pj/os_core_unix.c
diff options
context:
space:
mode:
authorNanang Izzuddin <nanang@teluu.com>2012-03-22 11:29:20 +0000
committerNanang Izzuddin <nanang@teluu.com>2012-03-22 11:29:20 +0000
commit759520a6f180a638027fdc7be58e12772247fe47 (patch)
tree4f070ee1947464a3a2ec66b875796f1b76aa1470 /pjlib/src/pj/os_core_unix.c
parent6496121f32e986850b48f6d5637e21ccddb1bb22 (diff)
Close #1466 (using PJLIB outside PJSUA-LIB context):
- static reference counter for PJLIB init/shutdown. - implemented atexit() in PJMEDIA and PJSIP level: pjmedia_endpt_atexit() & pjsip_endpt_atexit(). - updated pjmedia/transport_srtp.c, pjsip/sip_timer.c, and pjsip/sip_replaces.c to use the new atexit() functions. - API change: pjmedia_srtp_init_lib() now requires 'pjmedia_endpt' param. git-svn-id: http://svn.pjsip.org/repos/pjproject/branches/1.x@3986 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib/src/pj/os_core_unix.c')
-rw-r--r--pjlib/src/pj/os_core_unix.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/pjlib/src/pj/os_core_unix.c b/pjlib/src/pj/os_core_unix.c
index 3fcfa565..00087b64 100644
--- a/pjlib/src/pj/os_core_unix.c
+++ b/pjlib/src/pj/os_core_unix.c
@@ -102,6 +102,11 @@ struct pj_event_t
#endif /* PJ_HAS_EVENT_OBJ */
+/*
+ * Flag and reference counter for PJLIB instance.
+ */
+static int initialized;
+
#if PJ_HAS_THREADS
static pj_thread_t main_thread;
static long thread_tls_id;
@@ -127,6 +132,12 @@ PJ_DEF(pj_status_t) pj_init(void)
pj_str_t guid;
pj_status_t rc;
+ /* Check if PJLIB have been initialized */
+ if (initialized) {
+ ++initialized;
+ return PJ_SUCCESS;
+ }
+
#if PJ_HAS_THREADS
/* Init this thread's TLS. */
if ((rc=pj_thread_init()) != 0) {
@@ -167,6 +178,10 @@ PJ_DEF(pj_status_t) pj_init(void)
}
#endif
+ /* Flag PJLIB as initialized */
+ ++initialized;
+ pj_assert(initialized == 1);
+
PJ_LOG(4,(THIS_FILE, "pjlib %s for POSIX initialized",
PJ_VERSION));
@@ -192,6 +207,11 @@ PJ_DEF(void) pj_shutdown()
{
int i;
+ /* Only perform shutdown operation when 'initialized' reaches zero */
+ pj_assert(initialized > 0);
+ if (--initialized != 0)
+ return;
+
/* Call atexit() functions */
for (i=atexit_count-1; i>=0; --i) {
(*atexit_func[i])();