Skip to content

Commit 185c71f

Browse files
committed
Templatify AssertLockHeld to placate clang warning
By changing the type of the lock from void* (which has no capability) to the actual type (which does). Minimize the amount of code we have to move into sync.h by pointing the AssertLockHeldInternal template at the original function that takes void*.
1 parent 3140a94 commit 185c71f

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/sync.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ std::string LocksHeld()
152152
return result;
153153
}
154154

155-
void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs)
155+
void _AssertLockHeld(const char* pszName, const char* pszFile, int nLine, void* cs)
156156
{
157157
for (const std::pair<void*, CLockLocation>& i : g_lockstack)
158158
if (i.first == cs)

src/sync.h

+10-3
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,21 @@ class LOCKABLE AnnotatedMixin : public PARENT
7474
void EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs, bool fTry = false);
7575
void LeaveCritical();
7676
std::string LocksHeld();
77-
void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs) ASSERT_EXCLUSIVE_LOCK(cs);
7877
void AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs);
7978
void DeleteLock(void* cs);
79+
80+
void _AssertLockHeld(const char* pszName, const char* pszFile, int nLine, void* cs);
81+
template <typename T>
82+
void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, T* cs) ASSERT_EXCLUSIVE_LOCK(cs) {
83+
_AssertLockHeld(pszName, pszFile, nLine, (void*)cs);
84+
}
8085
#else
8186
void static inline EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs, bool fTry = false) {}
8287
void static inline LeaveCritical() {}
83-
void static inline AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs) ASSERT_EXCLUSIVE_LOCK(cs) {}
84-
void static inline AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs) {}
88+
template <typename T>
89+
void static inline AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, T* cs) ASSERT_EXCLUSIVE_LOCK(cs) {}
90+
template <typename T>
91+
void static inline AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, T* cs) {}
8592
void static inline DeleteLock(void* cs) {}
8693
#endif
8794
#define AssertLockHeld(cs) AssertLockHeldInternal(#cs, __FILE__, __LINE__, &cs)

0 commit comments

Comments
 (0)