Skip to content

Commit 971a468

Browse files
committed
Use template function instead of void* parameter
This change gets rid of -Wthread-safety-attributes warning spam.
1 parent dfb75ae commit 971a468

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/sync.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,15 @@ static bool LockHeld(void* mutex)
219219
return false;
220220
}
221221

222-
void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs)
222+
template <typename MutexType>
223+
void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, MutexType* cs)
223224
{
224225
if (LockHeld(cs)) return;
225226
tfm::format(std::cerr, "Assertion failed: lock %s not held in %s:%i; locks held:\n%s", pszName, pszFile, nLine, LocksHeld());
226227
abort();
227228
}
229+
template void AssertLockHeldInternal(const char*, const char*, int, Mutex*);
230+
template void AssertLockHeldInternal(const char*, const char*, int, RecursiveMutex*);
228231

229232
void AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs)
230233
{

src/sync.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ void EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs
5252
void LeaveCritical();
5353
void CheckLastCritical(void* cs, std::string& lockname, const char* guardname, const char* file, int line);
5454
std::string LocksHeld();
55-
void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs) ASSERT_EXCLUSIVE_LOCK(cs);
55+
template <typename MutexType>
56+
void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, MutexType* cs) ASSERT_EXCLUSIVE_LOCK(cs);
5657
void AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs);
5758
void DeleteLock(void* cs);
5859

@@ -66,7 +67,8 @@ extern bool g_debug_lockorder_abort;
6667
void static inline EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs, bool fTry = false) {}
6768
void static inline LeaveCritical() {}
6869
void static inline CheckLastCritical(void* cs, std::string& lockname, const char* guardname, const char* file, int line) {}
69-
void static inline AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs) ASSERT_EXCLUSIVE_LOCK(cs) {}
70+
template <typename MutexType>
71+
void static inline AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, MutexType* cs) ASSERT_EXCLUSIVE_LOCK(cs) {}
7072
void static inline AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs) {}
7173
void static inline DeleteLock(void* cs) {}
7274
#endif

0 commit comments

Comments
 (0)