Changeset 2853 for pjproject/trunk
- Timestamp:
- Aug 5, 2009 10:58:02 AM (15 years ago)
- Location:
- pjproject/trunk/pjlib
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/include/pj/log.h
r2842 r2853 221 221 PJ_DECL(pj_color_t) pj_log_get_color(int level); 222 222 223 /** 224 * Internal function to be called by pj_init() 225 */ 226 pj_status_t pj_log_init(void); 223 227 224 228 #else /* #if PJ_LOG_MAX_LEVEL >= 1 */ … … 288 292 # define pj_log_get_color(level) 0 289 293 294 295 /** 296 * Internal. 297 */ 298 # define pj_log_init() PJ_SUCCESS 290 299 291 300 #endif /* #if PJ_LOG_MAX_LEVEL >= 1 */ -
pjproject/trunk/pjlib/src/pj/log.c
r2842 r2853 31 31 static int pj_log_max_level = PJ_LOG_MAX_LEVEL; 32 32 #endif 33 static long thread_suspended_tls_id = -1; 33 34 static pj_log_func *log_writer = &pj_log_write; 34 35 static unsigned log_decor = PJ_LOG_HAS_TIME | PJ_LOG_HAS_MICRO_SEC | … … 67 68 #endif 68 69 70 static void logging_shutdown(void) 71 { 72 #if PJ_HAS_THREADS 73 if (thread_suspended_tls_id != -1) { 74 pj_thread_local_free(thread_suspended_tls_id); 75 thread_suspended_tls_id = -1; 76 } 77 #endif 78 } 79 80 pj_status_t pj_log_init(void) 81 { 82 #if PJ_HAS_THREADS 83 if (thread_suspended_tls_id == -1) { 84 pj_thread_local_alloc(&thread_suspended_tls_id); 85 pj_atexit(&logging_shutdown); 86 } 87 #endif 88 return PJ_SUCCESS; 89 } 90 69 91 PJ_DEF(void) pj_log_set_decor(unsigned decor) 70 92 { … … 149 171 } 150 172 173 /* Temporarily suspend logging facility for this thread. 174 * If thread local storage/variable is not used or not initialized, then 175 * we can only suspend the logging globally across all threads. This may 176 * happen e.g. when log function is called before PJLIB is fully initialized 177 * or after PJLIB is shutdown. 178 */ 179 static void suspend_logging(int *saved_level) 180 { 181 #if PJ_HAS_THREADS 182 if (thread_suspended_tls_id != -1) 183 { 184 pj_thread_local_set(thread_suspended_tls_id, (void*)PJ_TRUE); 185 } 186 else 187 #endif 188 { 189 pj_log_max_level = 0; 190 } 191 /* Save the level regardless, just in case PJLIB is shutdown 192 * between suspend and resume. 193 */ 194 *saved_level = pj_log_max_level; 195 } 196 197 /* Resume logging facility for this thread */ 198 static void resume_logging(int *saved_level) 199 { 200 #if PJ_HAS_THREADS 201 if (thread_suspended_tls_id != -1) 202 { 203 pj_thread_local_set(thread_suspended_tls_id, (void*)PJ_FALSE); 204 } 205 else 206 #endif 207 { 208 /* Only revert the level if application doesn't change the 209 * logging level between suspend and resume. 210 */ 211 if (pj_log_max_level==0 && *saved_level) 212 pj_log_max_level = *saved_level; 213 } 214 } 215 216 /* Is logging facility suspended for this thread? */ 217 static pj_bool_t is_logging_suspended(void) 218 { 219 #if PJ_HAS_THREADS 220 if (thread_suspended_tls_id != -1) 221 { 222 return pj_thread_local_get(thread_suspended_tls_id) != NULL; 223 } 224 else 225 #endif 226 { 227 return pj_log_max_level != 0; 228 } 229 } 230 151 231 PJ_DEF(void) pj_log( const char *sender, int level, 152 232 const char *format, va_list marker) … … 158 238 char log_buffer[PJ_LOG_MAX_SIZE]; 159 239 #endif 160 int len, print_len;240 int saved_level, len, print_len; 161 241 162 242 PJ_CHECK_STACK(); … … 164 244 if (level > pj_log_max_level) 165 245 return; 246 247 if (is_logging_suspended()) 248 return; 249 250 /* Temporarily disable logging for this thread. Some of PJLIB APIs that 251 * this function calls below will recursively call the logging function 252 * back, hence it will cause infinite recursive calls if we allow that. 253 */ 254 suspend_logging(&saved_level); 166 255 167 256 /* Get current date/time. */ … … 275 364 } 276 365 366 /* It should be safe to resume logging at this point. Application can 367 * recursively call the logging function inside the callback. 368 */ 369 resume_logging(&saved_level); 370 277 371 if (log_writer) 278 372 (*log_writer)(level, log_buffer, len); -
pjproject/trunk/pjlib/src/pj/os_core_symbian.cpp
r2481 r2853 343 343 if (err != KErrNone) 344 344 return PJ_RETURN_OS_ERROR(err); 345 345 346 /* Init logging */ 347 pj_log_init(); 348 346 349 /* Initialize exception ID for the pool. 347 350 * Must do so after critical section is configured. -
pjproject/trunk/pjlib/src/pj/os_core_unix.c
r2395 r2853 139 139 140 140 #endif 141 142 /* Init logging */ 143 pj_log_init(); 141 144 142 145 /* Initialize exception ID for the pool. -
pjproject/trunk/pjlib/src/pj/os_core_win32.c
r2843 r2853 153 153 } 154 154 155 /* Init logging */ 156 pj_log_init(); 157 155 158 /* Init random seed. */ 156 159 /* Or probably not. Let application in charge of this */
Note: See TracChangeset
for help on using the changeset viewer.