summaryrefslogtreecommitdiff
path: root/pjlib/src/pj/os_core_unix.c
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2012-03-30 07:10:13 +0000
committerBenny Prijono <bennylp@teluu.com>2012-03-30 07:10:13 +0000
commit6b4964727bffb379aca9601e1cf69051ccbf600c (patch)
tree1d9739ea8b3b5e0421f1d99b39e798b1514fb644 /pjlib/src/pj/os_core_unix.c
parent85ac546acb235df62169c4ad317da74a62e56a88 (diff)
Re #1474: Merged all changes from 1.12 - HEAD (from the 1.x branch)
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@3999 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 1c8cb14e..810e4b0d 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])();