aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Cozzette <acozzette@gmail.com>2018-05-31 11:20:00 -0700
committerGitHub <noreply@github.com>2018-05-31 11:20:00 -0700
commitf8262db9191280d9e8ed0b2f4a77f71f86960c46 (patch)
treea20488ad569dabdc911231425cfd7c269c90d925
parentcf242503ec157a7dda8a6eda48712dd26c81d2e6 (diff)
parentadc408698a60a165f38bd66221a1a9ca46ad0c46 (diff)
downloadprotobuf-f8262db9191280d9e8ed0b2f4a77f71f86960c46.tar.gz
protobuf-f8262db9191280d9e8ed0b2f4a77f71f86960c46.tar.bz2
protobuf-f8262db9191280d9e8ed0b2f4a77f71f86960c46.zip
Merge pull request #4703 from acozzette/thread-safety-annotations
Added Clang thread-safety annotations in mutex.h
-rw-r--r--src/google/protobuf/stubs/mutex.h20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/google/protobuf/stubs/mutex.h b/src/google/protobuf/stubs/mutex.h
index b9b7d2e1..47edb7a3 100644
--- a/src/google/protobuf/stubs/mutex.h
+++ b/src/google/protobuf/stubs/mutex.h
@@ -34,6 +34,18 @@
#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
namespace google {
@@ -48,8 +60,8 @@ namespace internal {
class LIBPROTOBUF_EXPORT WrappedMutex {
public:
WrappedMutex() = default;
- void Lock() { mu_.lock(); }
- void Unlock() { mu_.unlock(); }
+ void Lock() GOOGLE_PROTOBUF_ACQUIRE() { mu_.lock(); }
+ void Unlock() GOOGLE_PROTOBUF_RELEASE() { mu_.unlock(); }
// 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.
void AssertHeld() const {}
@@ -123,8 +135,10 @@ using internal::ReaderMutexLock;
using internal::WriterMutexLock;
using internal::MutexLockMaybe;
-
} // namespace protobuf
} // namespace google
+#undef GOOGLE_PROTOBUF_ACQUIRE
+#undef GOOGLE_PROTOBUF_RELEASE
+
#endif // GOOGLE_PROTOBUF_STUBS_MUTEX_H_