Changeset 3986 for pjproject/branches/1.x
- Timestamp:
- Mar 22, 2012 11:29:20 AM (13 years ago)
- Location:
- pjproject/branches/1.x
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/1.x/pjlib/src/pj/os_core_symbian.cpp
r3553 r3986 76 76 }; 77 77 78 /* Flag and reference counter for PJLIB instance */ 79 static int initialized; 80 78 81 /* Flags to indicate which TLS variables have been used */ 79 82 static int tls_vars[PJ_MAX_TLS]; … … 82 85 static unsigned atexit_count; 83 86 static void (*atexit_func[32])(void); 84 85 86 87 87 88 … … 336 337 pj_status_t status; 337 338 339 /* Check if PJLIB have been initialized */ 340 if (initialized) { 341 ++initialized; 342 return PJ_SUCCESS; 343 } 344 338 345 pj_ansi_strcpy(main_thread.obj_name, "pjthread"); 339 346 … … 369 376 #endif 370 377 378 /* Flag PJLIB as initialized */ 379 ++initialized; 380 pj_assert(initialized == 1); 381 371 382 PJ_LOG(5,(THIS_FILE, "PJLIB initialized.")); 372 383 return PJ_SUCCESS; … … 391 402 PJ_DEF(void) pj_shutdown(void) 392 403 { 404 /* Only perform shutdown operation when 'initialized' reaches zero */ 405 pj_assert(initialized > 0); 406 if (--initialized != 0) 407 return; 408 393 409 /* Call atexit() functions */ 394 410 while (atexit_count > 0) { -
pjproject/branches/1.x/pjlib/src/pj/os_core_unix.c
r3553 r3986 103 103 104 104 105 /* 106 * Flag and reference counter for PJLIB instance. 107 */ 108 static int initialized; 109 105 110 #if PJ_HAS_THREADS 106 111 static pj_thread_t main_thread; … … 127 132 pj_str_t guid; 128 133 pj_status_t rc; 134 135 /* Check if PJLIB have been initialized */ 136 if (initialized) { 137 ++initialized; 138 return PJ_SUCCESS; 139 } 129 140 130 141 #if PJ_HAS_THREADS … … 168 179 #endif 169 180 181 /* Flag PJLIB as initialized */ 182 ++initialized; 183 pj_assert(initialized == 1); 184 170 185 PJ_LOG(4,(THIS_FILE, "pjlib %s for POSIX initialized", 171 186 PJ_VERSION)); … … 192 207 { 193 208 int i; 209 210 /* Only perform shutdown operation when 'initialized' reaches zero */ 211 pj_assert(initialized > 0); 212 if (--initialized != 0) 213 return; 194 214 195 215 /* Call atexit() functions */ -
pjproject/branches/1.x/pjlib/src/pj/os_core_win32.c
r3553 r3986 118 118 119 119 /* 120 * Flag and reference counter for PJLIB instance. 121 */ 122 static int initialized; 123 124 /* 120 125 * Static global variables. 121 126 */ … … 142 147 pj_str_t guid; 143 148 pj_status_t rc; 149 150 /* Check if PJLIB have been initialized */ 151 if (initialized) { 152 ++initialized; 153 return PJ_SUCCESS; 154 } 144 155 145 156 /* Init Winsock.. */ … … 188 199 #endif 189 200 201 /* Flag PJLIB as initialized */ 202 ++initialized; 203 pj_assert(initialized == 1); 204 190 205 PJ_LOG(4,(THIS_FILE, "pjlib %s for win32 initialized", 191 206 PJ_VERSION)); … … 213 228 { 214 229 int i; 230 231 /* Only perform shutdown operation when 'initialized' reaches zero */ 232 pj_assert(initialized > 0); 233 if (--initialized != 0) 234 return; 215 235 216 236 /* Display stack usage */ -
pjproject/branches/1.x/pjmedia/include/pjmedia/endpoint.h
r3553 r3986 58 58 59 59 } pjmedia_endpt_flag; 60 61 62 /** 63 * Type of callback to register to pjmedia_endpt_atexit(). 64 */ 65 typedef void (*pjmedia_endpt_exit_callback)(pjmedia_endpt *endpt); 60 66 61 67 … … 205 211 206 212 213 /** 214 * Register cleanup function to be called by media endpoint when 215 * #pjmedia_endpt_destroy() is called. 216 * 217 * @param endpt The media endpoint. 218 * @param func The function to be registered. 219 * 220 * @return PJ_SUCCESS on success. 221 */ 222 PJ_DECL(pj_status_t) pjmedia_endpt_atexit(pjmedia_endpt *endpt, 223 pjmedia_endpt_exit_callback func); 224 225 226 207 227 PJ_END_DECL 208 228 -
pjproject/branches/1.x/pjmedia/include/pjmedia/transport_srtp.h
r3553 r3986 201 201 * library deinitialization to #pj_atexit(), so the deinitialization 202 202 * of SRTP library will be performed automatically by PJLIB destructor. 203 */ 204 PJ_DECL(pj_status_t) pjmedia_srtp_init_lib(void); 203 * 204 * @param endpt The media endpoint instance. 205 * 206 * @return PJ_SUCCESS on success. 207 */ 208 PJ_DECL(pj_status_t) pjmedia_srtp_init_lib(pjmedia_endpt *endpt); 205 209 206 210 -
pjproject/branches/1.x/pjmedia/src/pjmedia/endpoint.c
r3957 r3986 24 24 #include <pj/assert.h> 25 25 #include <pj/ioqueue.h> 26 #include <pj/lock.h> 26 27 #include <pj/log.h> 27 28 #include <pj/os.h> … … 57 58 58 59 60 /* List of media endpoint exit callback. */ 61 typedef struct exit_cb 62 { 63 PJ_DECL_LIST_MEMBER (struct exit_cb); 64 pjmedia_endpt_exit_callback func; 65 } exit_cb; 66 67 59 68 /** Concrete declaration of media endpoint. */ 60 69 struct pjmedia_endpt … … 86 95 /** Is telephone-event enable */ 87 96 pj_bool_t has_telephone_event; 97 98 /** List of exit callback. */ 99 exit_cb exit_cb_list; 88 100 }; 89 101 … … 129 141 goto on_error; 130 142 143 /* Initialize exit callback list. */ 144 pj_list_init(&endpt->exit_cb_list); 145 131 146 /* Create ioqueue if none is specified. */ 132 147 if (endpt->ioqueue == NULL) { … … 189 204 PJ_DEF(pj_status_t) pjmedia_endpt_destroy (pjmedia_endpt *endpt) 190 205 { 206 exit_cb *ecb; 191 207 unsigned i; 192 208 … … 202 218 endpt->thread[i] = NULL; 203 219 } 220 } 221 222 /* Call all registered exit callbacks */ 223 ecb = endpt->exit_cb_list.next; 224 while (ecb != &endpt->exit_cb_list) { 225 (*ecb->func)(endpt); 226 ecb = ecb->next; 204 227 } 205 228 … … 629 652 return PJ_SUCCESS; 630 653 } 654 655 PJ_DEF(pj_status_t) pjmedia_endpt_atexit( pjmedia_endpt *endpt, 656 pjmedia_endpt_exit_callback func) 657 { 658 exit_cb *new_cb; 659 660 PJ_ASSERT_RETURN(endpt && func, PJ_EINVAL); 661 662 if (endpt->quit_flag) 663 return PJ_EINVALIDOP; 664 665 new_cb = PJ_POOL_ZALLOC_T(endpt->pool, exit_cb); 666 new_cb->func = func; 667 668 pj_enter_critical_section(); 669 pj_list_push_back(&endpt->exit_cb_list, new_cb); 670 pj_leave_critical_section(); 671 672 return PJ_SUCCESS; 673 } -
pjproject/branches/1.x/pjmedia/src/pjmedia/transport_srtp.c
r3961 r3986 271 271 272 272 static pj_bool_t libsrtp_initialized; 273 static void pjmedia_srtp_deinit_lib( void);274 275 PJ_DEF(pj_status_t) pjmedia_srtp_init_lib( void)273 static void pjmedia_srtp_deinit_lib(pjmedia_endpt *endpt); 274 275 PJ_DEF(pj_status_t) pjmedia_srtp_init_lib(pjmedia_endpt *endpt) 276 276 { 277 277 if (libsrtp_initialized == PJ_FALSE) { … … 285 285 } 286 286 287 if (pj_atexit(pjmedia_srtp_deinit_lib) != PJ_SUCCESS) { 287 if (pjmedia_endpt_atexit(endpt, pjmedia_srtp_deinit_lib) != PJ_SUCCESS) 288 { 288 289 /* There will be memory leak when it fails to schedule libsrtp 289 290 * deinitialization, however the memory leak could be harmless, … … 300 301 } 301 302 302 static void pjmedia_srtp_deinit_lib( void)303 static void pjmedia_srtp_deinit_lib(pjmedia_endpt *endpt) 303 304 { 304 305 err_status_t err; 306 307 /* Note that currently this SRTP init/deinit is not equipped with 308 * reference counter, it should be safe as normally there is only 309 * one single instance of media endpoint and even if it isn't, the 310 * pjmedia_transport_srtp_create() will invoke SRTP init (the only 311 * drawback should be the delay described by #788). 312 */ 313 314 PJ_UNUSED_ARG(endpt); 305 315 306 316 err = srtp_deinit(); … … 411 421 412 422 /* Init libsrtp. */ 413 status = pjmedia_srtp_init_lib( );423 status = pjmedia_srtp_init_lib(endpt); 414 424 if (status != PJ_SUCCESS) 415 425 return status; -
pjproject/branches/1.x/pjsip/include/pjsip/sip_endpoint.h
r3828 r3986 63 63 */ 64 64 65 66 /** 67 * Type of callback to register to pjsip_endpt_atexit(). 68 */ 69 typedef void (*pjsip_endpt_exit_callback)(pjsip_endpoint *endpt); 70 71 65 72 /** 66 73 * Create an instance of SIP endpoint from the specified pool factory. … … 512 519 513 520 521 /** 522 * Register cleanup function to be called by SIP endpoint when 523 * #pjsip_endpt_destroy() is called. 524 * 525 * @param endpt The SIP endpoint. 526 * @param func The function to be registered. 527 * 528 * @return PJ_SUCCESS on success. 529 */ 530 PJ_DECL(pj_status_t) pjsip_endpt_atexit(pjsip_endpoint *endpt, 531 pjsip_endpt_exit_callback func); 532 514 533 515 534 /** -
pjproject/branches/1.x/pjsip/src/pjsip-ua/sip_replaces.c
r3553 r3986 163 163 164 164 /* Deinitialize Replaces */ 165 static void pjsip_replaces_deinit_module(void) 166 { 165 static void pjsip_replaces_deinit_module(pjsip_endpoint *endpt) 166 { 167 PJ_TODO(provide_initialized_flag_for_each_endpoint); 168 PJ_UNUSED_ARG(endpt); 167 169 is_initialized = PJ_FALSE; 168 170 } … … 192 194 193 195 /* Register deinit module to be executed when PJLIB shutdown */ 194 if (pj_atexit(&pjsip_replaces_deinit_module) != PJ_SUCCESS) { 196 if (pjsip_endpt_atexit(endpt, &pjsip_replaces_deinit_module) != PJ_SUCCESS) 197 { 195 198 /* Failure to register this function may cause this module won't 196 199 * work properly when the stack is restarted (without quitting -
pjproject/branches/1.x/pjsip/src/pjsip-ua/sip_timer.c
r3553 r3986 496 496 497 497 /* Deinitialize Session Timers */ 498 static void pjsip_timer_deinit_module(void) 499 { 498 static void pjsip_timer_deinit_module(pjsip_endpoint *endpt) 499 { 500 PJ_TODO(provide_initialized_flag_for_each_endpoint); 501 PJ_UNUSED_ARG(endpt); 500 502 is_initialized = PJ_FALSE; 501 503 } … … 532 534 533 535 /* Register deinit module to be executed when PJLIB shutdown */ 534 if (pj _atexit(&pjsip_timer_deinit_module) != PJ_SUCCESS) {536 if (pjsip_endpt_atexit(endpt, &pjsip_timer_deinit_module) != PJ_SUCCESS) { 535 537 /* Failure to register this function may cause this module won't 536 538 * work properly when the stack is restarted (without quitting -
pjproject/branches/1.x/pjsip/src/pjsip/sip_endpoint.c
r3553 r3986 41 41 #define MAX_METHODS 32 42 42 43 44 /* List of SIP endpoint exit callback. */ 45 typedef struct exit_cb 46 { 47 PJ_DECL_LIST_MEMBER (struct exit_cb); 48 pjsip_endpt_exit_callback func; 49 } exit_cb; 50 51 43 52 /** 44 53 * The SIP endpoint. … … 87 96 /** Additional request headers. */ 88 97 pjsip_hdr req_hdr; 98 99 /** List of exit callback. */ 100 exit_cb exit_cb_list; 89 101 }; 90 102 … … 446 458 pj_list_init(&endpt->module_list); 447 459 460 /* Initialize exit callback list. */ 461 pj_list_init(&endpt->exit_cb_list); 462 448 463 /* Create R/W mutex for module manipulation. */ 449 464 status = pj_rwmutex_create(endpt->pool, "ept%p", &endpt->mod_mutex); … … 560 575 { 561 576 pjsip_module *mod; 577 exit_cb *ecb; 562 578 563 579 PJ_LOG(5, (THIS_FILE, "Destroying endpoing instance..")); 580 581 /* Call all registered exit callbacks */ 582 ecb = endpt->exit_cb_list.next; 583 while (ecb != &endpt->exit_cb_list) { 584 (*ecb->func)(endpt); 585 ecb = ecb->next; 586 } 564 587 565 588 /* Phase 1: stop all modules */ … … 1179 1202 } 1180 1203 1204 1205 PJ_DEF(pj_status_t) pjsip_endpt_atexit( pjsip_endpoint *endpt, 1206 pjsip_endpt_exit_callback func) 1207 { 1208 exit_cb *new_cb; 1209 1210 PJ_ASSERT_RETURN(endpt && func, PJ_EINVAL); 1211 1212 new_cb = PJ_POOL_ZALLOC_T(endpt->pool, exit_cb); 1213 new_cb->func = func; 1214 1215 pj_mutex_lock(endpt->mutex); 1216 pj_list_push_back(&endpt->exit_cb_list, new_cb); 1217 pj_mutex_unlock(endpt->mutex); 1218 1219 return PJ_SUCCESS; 1220 } -
pjproject/branches/1.x/pjsip/src/pjsua-lib/pjsua_media.c
r3962 r3986 336 336 337 337 #if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0) 338 /* Initialize SRTP library . */339 status = pjmedia_srtp_init_lib( );338 /* Initialize SRTP library (ticket #788). */ 339 status = pjmedia_srtp_init_lib(pjsua_var.med_endpt); 340 340 if (status != PJ_SUCCESS) { 341 341 pjsua_perror(THIS_FILE, "Error initializing SRTP library",
Note: See TracChangeset
for help on using the changeset viewer.