|
23 | 23 | #if !defined(HAVE_THREAD_LOCAL) |
24 | 24 | static_assert(false, "thread_local is not supported"); |
25 | 25 | #endif |
26 | | -void PrintLockContention(const char* pszName, const char* pszFile, int nLine) |
27 | | -{ |
28 | | - LogPrintf("LOCKCONTENTION: %s\n", pszName); |
29 | | - LogPrintf("Locker: %s:%d\n", pszFile, nLine); |
30 | | -} |
31 | 26 | #endif /* DEBUG_LOCKCONTENTION */ |
32 | 27 |
|
33 | 28 | #ifdef DEBUG_LOCKORDER |
@@ -344,3 +339,26 @@ bool LockStackEmpty() |
344 | 339 | return true; |
345 | 340 | #endif |
346 | 341 | } |
| 342 | + |
| 343 | +#ifdef DEBUG_LOCKCONTENTION |
| 344 | +static void PrintLockContention(const char* pszName, const char* pszFile, int nLine) |
| 345 | +{ |
| 346 | + LogPrintf("LOCKCONTENTION: %s\n", pszName); |
| 347 | + LogPrintf("Locker: %s:%d\n", pszFile, nLine); |
| 348 | +} |
| 349 | +#endif |
| 350 | + |
| 351 | +template <typename Base> |
| 352 | +void CheckContentionAndLock(Base* base, const char* pszName, const char* pszFile, int nLine) |
| 353 | +{ |
| 354 | +#ifdef DEBUG_LOCKCONTENTION |
| 355 | + if (!base->try_lock()) { |
| 356 | + PrintLockContention(pszName, pszFile, nLine); |
| 357 | +#endif |
| 358 | + base->lock(); |
| 359 | +#ifdef DEBUG_LOCKCONTENTION |
| 360 | + } |
| 361 | +#endif |
| 362 | +} |
| 363 | +template void CheckContentionAndLock(Mutex::UniqueLock*, const char*, const char*, int); |
| 364 | +template void CheckContentionAndLock(RecursiveMutex::UniqueLock*, const char*, const char*, int); |
0 commit comments