| 341 | } |
| 342 | |
| 343 | void DumpBacktrace(char type, void* ptr, uint32_t size) |
| 344 | { |
| 345 | static int32_atomic_t call_depth = 0; |
| 346 | |
| 347 | if (!dmMemProfile::g_Mutex) |
| 348 | return; |
| 349 | |
| 350 | int ret = pthread_mutex_lock(dmMemProfile::g_Mutex); |
| 351 | assert(ret == 0); |
| 352 | |
| 353 | if (g_TraceFile == -1) |
| 354 | { |
| 355 | ret = pthread_mutex_unlock(dmMemProfile::g_Mutex); |
| 356 | assert(ret == 0); |
| 357 | return; |
| 358 | } |
| 359 | |
| 360 | // Avoid recursive calls to DumpBacktrace. backtrace can allocate memory... |
| 361 | if (dmAtomicIncrement32(&call_depth) > 0) |
| 362 | { |
| 363 | dmAtomicDecrement32(&call_depth); |
| 364 | return; |
| 365 | } |
| 366 | |
| 367 | char buf[256]; |
| 368 | snprintf(buf, sizeof(buf), "%c %p 0x%x ", type, ptr, (int32_t) size); |
| 369 | Log(g_TraceFile, buf); |
| 370 | |
| 371 | DumpBacktracePlatform(g_TraceFile); |
| 372 | |
| 373 | Log(g_TraceFile, "\n"); |
| 374 | |
| 375 | dmAtomicDecrement32(&call_depth); |
| 376 | ret = pthread_mutex_unlock(dmMemProfile::g_Mutex); |
| 377 | assert(ret == 0); |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | extern "C" |
no test coverage detected