Changeset 28351 for trunk/psLib/src/sys/psThread.c
- Timestamp:
- Jun 16, 2010, 12:04:05 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/sys/psThread.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psThread.c
r28307 r28351 7 7 #include <unistd.h> 8 8 #include <string.h> 9 10 // Backtrace to help nail down bugs 11 #ifdef HAVE_BACKTRACE 12 #include <execinfo.h> 13 #include <stdlib.h> 14 #define BACKTRACE_BUFFER_SIZE 256 // Maximum size of backtrace 15 static void **bt_buffer = NULL; // Backtrace buffer 16 static int bt_size = 0; // Backtrace buffer size 17 #endif 9 18 10 19 #include "psAssert.h" … … 33 42 static psArray *tsd = NULL; // Thread-specific data 34 43 44 35 45 /***** basic thread functions *****/ 36 46 … … 91 101 PS_ASSERT_THREAD_JOB_NON_NULL(job, false); 92 102 103 psThreadTask *task = psHashLookup(tasks, job->type); // Task to execute job 104 psAssert(task, "Unable to find task %s", job->type); 105 psAssert(job->args->n == task->nArgs, "invalid number of arguments to %s", task->type); 106 93 107 // if we failed to call psThreadPoolInit, or we called it with nThreads == 0, 94 108 // find the matching function and just run it. … … 101 115 psListAdd(done, PS_LIST_TAIL, job); 102 116 103 // find the corresponding task and run it104 psThreadTask *task = psHashLookup(tasks, job->type); // Task to execute job105 psAssert(task, "Unable to find task %s", job->type);106 psAssert(job->args->n == task->nArgs, "invalid number of arguments to %s", task->type);107 117 return task->function(job); 108 118 } … … 209 219 210 220 psThreadTask *task = psHashLookup(tasks, job->type); // Task to execute job 221 #ifdef HAVE_BACKTRACE 222 if (!task && bt_buffer) { 223 psLogMsg("psLib.sys", PS_LOG_ABORT, "Backtrace of waiter:\n"); 224 char **strings = backtrace_symbols((void *const *)bt_buffer, bt_size); 225 psLogMsg("psLib.sys", PS_LOG_ABORT, "Backtrace depth: %d", bt_size); 226 for (int i = 0; i < bt_size; i++) { 227 char *caller = strchr(strings[i], '('); 228 if (caller) { 229 caller++; 230 size_t callerLength = abs(strchr(caller, '+') - caller); 231 psString name = psStringNCopy(caller, callerLength); 232 psLogMsg("psLib.sys", PS_LOG_ABORT, "Backtrace %d: %s", i, name); 233 psFree(name); 234 } else { 235 psLogMsg("psLib.sys", PS_LOG_ABORT, "Backtrace %d: (unknown)", i); 236 } 237 } 238 } 239 #endif 211 240 psAssert(task, "Couldn't find thread task %s", job->type); 212 241 psAssert(job->args->n == task->nArgs, … … 282 311 return true; 283 312 } 313 314 #ifdef HAVE_BACKTRACE 315 if (bt_buffer) { 316 psFree(bt_buffer); 317 } 318 bt_buffer = psAlloc(BACKTRACE_BUFFER_SIZE * sizeof(void *)); 319 bt_size = backtrace(bt_buffer, BACKTRACE_BUFFER_SIZE); 320 #endif 284 321 285 322 while (1) { … … 343 380 tsd = NULL; 344 381 382 #ifdef HAVE_BACKTRACE 383 if (bt_buffer) { 384 psFree(bt_buffer); 385 } 386 #endif 387 345 388 return true; 346 389 }
Note:
See TracChangeset
for help on using the changeset viewer.
