Merge pull request #4703 from acozzette/thread-safety-annotations

Added Clang thread-safety annotations in mutex.h
pull/3863/merge
Adam Cozzette 7 years ago committed by GitHub
commit f8262db919
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      src/google/protobuf/stubs/mutex.h

@ -34,6 +34,18 @@
#include <google/protobuf/stubs/macros.h> #include <google/protobuf/stubs/macros.h>
// Define thread-safety annotations for use below, if we are building with
// Clang.
#if defined(__clang__) && !defined(SWIG)
#define GOOGLE_PROTOBUF_ACQUIRE(...) \
__attribute__((acquire_capability(__VA_ARGS__)))
#define GOOGLE_PROTOBUF_RELEASE(...) \
__attribute__((release_capability(__VA_ARGS__)))
#else
#define GOOGLE_PROTOBUF_ACQUIRE(...)
#define GOOGLE_PROTOBUF_RELEASE(...)
#endif
// =================================================================== // ===================================================================
// emulates google3/base/mutex.h // emulates google3/base/mutex.h
namespace google { namespace google {
@ -48,8 +60,8 @@ namespace internal {
class LIBPROTOBUF_EXPORT WrappedMutex { class LIBPROTOBUF_EXPORT WrappedMutex {
public: public:
WrappedMutex() = default; WrappedMutex() = default;
void Lock() { mu_.lock(); } void Lock() GOOGLE_PROTOBUF_ACQUIRE() { mu_.lock(); }
void Unlock() { mu_.unlock(); } void Unlock() GOOGLE_PROTOBUF_RELEASE() { mu_.unlock(); }
// Crash if this Mutex is not held exclusively by this thread. // Crash if this Mutex is not held exclusively by this thread.
// May fail to crash when it should; will never crash when it should not. // May fail to crash when it should; will never crash when it should not.
void AssertHeld() const {} void AssertHeld() const {}
@ -123,8 +135,10 @@ using internal::ReaderMutexLock;
using internal::WriterMutexLock; using internal::WriterMutexLock;
using internal::MutexLockMaybe; using internal::MutexLockMaybe;
} // namespace protobuf } // namespace protobuf
} // namespace google } // namespace google
#undef GOOGLE_PROTOBUF_ACQUIRE
#undef GOOGLE_PROTOBUF_RELEASE
#endif // GOOGLE_PROTOBUF_STUBS_MUTEX_H_ #endif // GOOGLE_PROTOBUF_STUBS_MUTEX_H_

Loading…
Cancel
Save