chore: enable -Werror=thread-safety and add missing annotations (part 2/2) (#3595)

* add missing annotations
* small mutex fixes
* enable -Werror=thread-safety for clang builds

---------

Signed-off-by: kostas <kostas@dragonflydb.io>
This commit is contained in:
Kostas Kyrimis 2024-08-30 15:42:30 +03:00 committed by GitHub
parent 0705bbb536
commit 41f7b611d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 127 additions and 82 deletions

View file

@ -377,6 +377,30 @@ class ABSL_LOCKABLE ThreadLocalMutex {
util::fb2::detail::FiberInterface* locked_fiber_{nullptr};
};
// Replacement of std::SharedLock that allows -Wthread-safety
template <typename Mutex> class ABSL_SCOPED_LOCKABLE SharedLock {
public:
explicit SharedLock(Mutex& m) ABSL_EXCLUSIVE_LOCK_FUNCTION(m) : m_(m) {
m_.lock_shared();
is_locked_ = true;
}
~SharedLock() ABSL_UNLOCK_FUNCTION() {
if (is_locked_) {
m_.unlock_shared();
}
}
void unlock() ABSL_UNLOCK_FUNCTION() {
m_.unlock_shared();
is_locked_ = false;
}
private:
Mutex& m_;
bool is_locked_;
};
extern size_t serialization_max_chunk_size;
} // namespace dfly