Changeset 815 for pjproject/trunk
- Timestamp:
- Nov 21, 2006 12:39:31 PM (18 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/include/pj/types.h
r764 r815 292 292 * in random string generation, and to initialize operating system dependent 293 293 * functionality (such as WSAStartup() in Windows). 294 * 295 * @return PJ_SUCCESS on success. 294 296 */ 295 297 PJ_DECL(pj_status_t) pj_init(void); 298 299 300 /** 301 * Shutdown PJLIB. 302 */ 303 PJ_DECL(void) pj_shutdown(void); 304 305 /** 306 * Register cleanup function to be called by PJLIB when pj_shutdown() is 307 * called. 308 * 309 * @param func The function to be registered. 310 * 311 * @return PJ_SUCCESS on success. 312 */ 313 PJ_DECL(pj_status_t) pj_atexit(void (*func)(void)); 314 315 296 316 297 317 /** -
pjproject/trunk/pjlib/src/pj/except.c
r635 r815 52 52 } 53 53 54 static void exception_cleanup(void) 55 { 56 if (thread_local_id != -1) { 57 pj_thread_local_free(thread_local_id); 58 thread_local_id = -1; 59 } 60 } 61 54 62 PJ_DEF(void) pj_push_exception_handler_(struct pj_exception_state_t *rec) 55 63 { … … 59 67 pj_thread_local_alloc(&thread_local_id); 60 68 pj_assert(thread_local_id != -1); 69 pj_atexit(&exception_cleanup); 61 70 } 62 71 parent_handler = pj_thread_local_get(thread_local_id); -
pjproject/trunk/pjlib/src/pj/os_core_unix.c
r750 r815 148 148 pj_generate_unique_string( &guid ); 149 149 150 /* Initialize exception ID for the pool.151 * Must do so after critical section is configured.152 */153 rc = pj_exception_id_alloc("PJLIB/No memory", &PJ_NO_MEMORY_EXCEPTION);154 if (rc != PJ_SUCCESS)155 return rc;156 157 150 /* Startup timestamp */ 158 151 #if defined(PJ_HAS_HIGH_RES_TIMER) && PJ_HAS_HIGH_RES_TIMER != 0 … … 170 163 return PJ_SUCCESS; 171 164 } 165 166 /* 167 * pj_atexit() 168 */ 169 PJ_DEF(pj_status_t) pj_atexit(void (*func)(void)) 170 { 171 if (atexit_count >= PJ_ARRAY_SIZE(atexit_func)) 172 return PJ_ETOOMANY; 173 174 atexit_func[atexit_count++] = func; 175 return PJ_SUCCESS; 176 } 177 178 /* 179 * pj_shutdown(void) 180 */ 181 PJ_DEF(void) pj_shutdown() 182 { 183 int i; 184 185 /* Call atexit() functions */ 186 for (i=atexit_count-1; i>=0; --i) { 187 (*atexit_func[i])(); 188 } 189 atexit_count = 0; 190 191 /* Free exception ID */ 192 if (PJ_NO_MEMORY_EXCEPTION != -1) { 193 pj_exception_id_free(PJ_NO_MEMORY_EXCEPTION); 194 PJ_NO_MEMORY_EXCEPTION = -1; 195 } 196 197 #if PJ_HAS_THREADS 198 /* Destroy PJLIB critical section */ 199 pj_mutex_destroy(&critical_section); 200 201 /* Free PJLIB TLS */ 202 if (thread_tls_id != -1) { 203 pj_thread_local_free(thread_tls_id); 204 thread_tls_id = -1; 205 } 206 #endif 207 } 208 172 209 173 210 /* -
pjproject/trunk/pjlib/src/pj/os_core_win32.c
r746 r815 109 109 */ 110 110 static pj_thread_desc main_thread; 111 static long thread_tls_id ;111 static long thread_tls_id = -1; 112 112 static pj_mutex_t critical_section_mutex; 113 113 static unsigned atexit_count; 114 static void (*atexit_func[32])(void); 114 115 115 116 /* … … 178 179 179 180 /* 181 * pj_atexit() 182 */ 183 PJ_DEF(pj_status_t) pj_atexit(void (*func)(void)) 184 { 185 if (atexit_count >= PJ_ARRAY_SIZE(atexit_func)) 186 return PJ_ETOOMANY; 187 188 atexit_func[atexit_count++] = func; 189 return PJ_SUCCESS; 190 } 191 192 193 /* 194 * pj_shutdown(void) 195 */ 196 PJ_DEF(void) pj_shutdown() 197 { 198 int i; 199 200 /* Call atexit() functions */ 201 for (i=atexit_count-1; i>=0; --i) { 202 (*atexit_func[i])(); 203 } 204 atexit_count = 0; 205 206 /* Free exception ID */ 207 if (PJ_NO_MEMORY_EXCEPTION != -1) { 208 pj_exception_id_free(PJ_NO_MEMORY_EXCEPTION); 209 PJ_NO_MEMORY_EXCEPTION = -1; 210 } 211 212 /* Destroy PJLIB critical section */ 213 pj_mutex_destroy(&critical_section_mutex); 214 215 /* Free PJLIB TLS */ 216 if (thread_tls_id != -1) { 217 pj_thread_local_free(thread_tls_id); 218 thread_tls_id = -1; 219 } 220 221 /* Shutdown Winsock */ 222 WSACleanup(); 223 } 224 225 226 /* 180 227 * pj_getpid(void) 181 228 */ -
pjproject/trunk/pjlib/src/pj/pool_buf.c
r768 r815 30 30 31 31 static int is_initialized; 32 static long tls ;32 static long tls = -1; 33 33 static void* stack_alloc(pj_pool_factory *factory, pj_size_t size); 34 34 35 static pj_status_t initialize()35 static void pool_buf_cleanup(void) 36 36 { 37 if (tls != -1) { 38 pj_thread_local_free(tls); 39 tls = -1; 40 } 41 } 42 43 static pj_status_t pool_buf_initialize() 44 { 45 pj_atexit(&pool_buf_cleanup); 46 37 47 stack_based_factory.policy.block_alloc = &stack_alloc; 38 48 return pj_thread_local_alloc(&tls); … … 65 75 66 76 if (!is_initialized) { 67 if ( initialize() != PJ_SUCCESS)77 if (pool_buf_initialize() != PJ_SUCCESS) 68 78 return NULL; 69 79 is_initialized = 1; -
pjproject/trunk/pjsip-apps/src/samples/aectest.c
r648 r815 211 211 pj_caching_pool_destroy( &cp ); 212 212 213 /* Shutdown PJLIB */ 214 pj_shutdown(); 213 215 214 216 /* Done. */ -
pjproject/trunk/pjsip-apps/src/samples/confsample.c
r541 r815 461 461 pj_caching_pool_destroy( &cp ); 462 462 463 /* Shutdown PJLIB */ 464 pj_shutdown(); 463 465 464 466 /* Done. */ -
pjproject/trunk/pjsip-apps/src/samples/level.c
r541 r815 156 156 pj_caching_pool_destroy( &cp ); 157 157 158 /* Shutdown PJLIB */ 159 pj_shutdown(); 160 158 161 159 162 /* Done. */ -
pjproject/trunk/pjsip-apps/src/samples/pjsip-perf.c
r777 r815 895 895 pj_caching_pool_destroy(&app.cp); 896 896 } 897 898 /* Shutdown PJLIB */ 899 pj_shutdown(); 897 900 } 898 901 -
pjproject/trunk/pjsip-apps/src/samples/playfile.c
r541 r815 196 196 pj_caching_pool_destroy( &cp ); 197 197 198 /* Shutdown PJLIB */ 199 pj_shutdown(); 200 198 201 199 202 /* Done. */ -
pjproject/trunk/pjsip-apps/src/samples/playsine.c
r635 r815 301 301 pj_caching_pool_destroy( &cp ); 302 302 303 /* Shutdown PJLIB */ 304 pj_shutdown(); 305 303 306 304 307 /* Done. */ -
pjproject/trunk/pjsip-apps/src/samples/recfile.c
r541 r815 191 191 pj_caching_pool_destroy( &cp ); 192 192 193 /* Shutdown PJLIB */ 194 pj_shutdown(); 195 193 196 194 197 /* Done. */ -
pjproject/trunk/pjsip-apps/src/samples/resampleplay.c
r541 r815 217 217 pj_caching_pool_destroy( &cp ); 218 218 219 /* Shutdown PJLIB */ 220 pj_shutdown(); 221 219 222 220 223 /* Done. */ -
pjproject/trunk/pjsip-apps/src/samples/siprtp.c
r800 r815 380 380 app.sip_endpt = NULL; 381 381 } 382 383 /* Shutdown PJLIB */ 384 pj_shutdown(); 385 382 386 } 383 387 -
pjproject/trunk/pjsip-apps/src/samples/sndinfo.c
r657 r815 286 286 } 287 287 288 /* Shutdown PJLIB */ 289 pj_shutdown(); 290 288 291 return 0; 289 292 } -
pjproject/trunk/pjsip-apps/src/samples/streamutil.c
r582 r815 517 517 /* Destroy pool factory */ 518 518 pj_caching_pool_destroy( &cp ); 519 520 /* Shutdown PJLIB */ 521 pj_shutdown(); 519 522 520 523 -
pjproject/trunk/pjsip-apps/src/samples/tonegen.c
r736 r815 147 147 pj_caching_pool_destroy( &cp ); 148 148 149 /* Shutdown PJLIB */ 150 pj_shutdown(); 151 149 152 150 153 /* Done. */ -
pjproject/trunk/pjsip/src/pjsip/sip_endpoint.c
r810 r815 581 581 /* Delete endpoint mutex. */ 582 582 pj_mutex_destroy(endpt->mutex); 583 584 /* Delete module's mutex */ 585 pj_rwmutex_destroy(endpt->mod_mutex); 583 586 584 587 /* Finally destroy pool. */ -
pjproject/trunk/pjsip/src/pjsip/sip_transaction.c
r756 r815 675 675 pjsip_endpt_release_pool(mod_tsx_layer.endpt, mod_tsx_layer.pool); 676 676 677 /* Free TLS */ 678 pj_thread_local_free(pjsip_tsx_lock_tls_id); 679 677 680 /* Mark as unregistered. */ 678 681 mod_tsx_layer.endpt = NULL; -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
r812 r815 708 708 } 709 709 710 /* Shutdown PJLIB */ 711 pj_shutdown(); 712 710 713 /* Done. */ 711 714 return PJ_SUCCESS; -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c
r785 r815 475 475 } 476 476 477 /* Deinitialize sound subsystem */ 478 pjmedia_snd_deinit(); 479 477 480 return PJ_SUCCESS; 478 481 }
Note: See TracChangeset
for help on using the changeset viewer.