Skip to content

Commit 513bdfc

Browse files
Merge #948: [Utils] Templatify AssertLockHeld to placate clang warning
185c71f Templatify AssertLockHeld to placate clang warning (Zannick) Pull request description: By changing the type of the lock from void* (which has no capability) to the actual type (which does). (Templates more or less have to be defined in a header, included in a header, or specializations explicitly declared in a header, so the actual implementation here is to call the original function that took a void*.) ### Test Results Built and run veild/veil-cli with clang. Built veild/veil-cli with clang with `-DDEBUG_LOCKORDER`. Tree-SHA512: dcbf48e26234665f43f84f695e6bee31fd39e5def4c8daf9b14886175c3e44af998e9eb5af120f6c2a0a667add3e58d7c95211f4c37b6a24c91dde2d89e94a52
2 parents 00001fa + 185c71f commit 513bdfc

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)