From 6b4964727bffb379aca9601e1cf69051ccbf600c Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Fri, 30 Mar 2012 07:10:13 +0000 Subject: 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 --- pjlib/src/pj/os_core_win32.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'pjlib/src/pj/os_core_win32.c') diff --git a/pjlib/src/pj/os_core_win32.c b/pjlib/src/pj/os_core_win32.c index 30992a4f..5168d7db 100644 --- a/pjlib/src/pj/os_core_win32.c +++ b/pjlib/src/pj/os_core_win32.c @@ -116,6 +116,11 @@ struct pj_atomic_t long value; }; +/* + * Flag and reference counter for PJLIB instance. + */ +static int initialized; + /* * Static global variables. */ @@ -142,6 +147,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; + } + /* Init Winsock.. */ if (WSAStartup(MAKEWORD(2,0), &wsa) != 0) { return PJ_RETURN_OS_ERROR(WSAGetLastError()); @@ -187,6 +198,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 win32 initialized", PJ_VERSION)); @@ -213,6 +228,11 @@ PJ_DEF(void) pj_shutdown() { int i; + /* Only perform shutdown operation when 'initialized' reaches zero */ + pj_assert(initialized > 0); + if (--initialized != 0) + return; + /* Display stack usage */ #if defined(PJ_OS_HAS_CHECK_STACK) && PJ_OS_HAS_CHECK_STACK!=0 { -- cgit v1.2.3