From f4575170e8786aea8fbad6e75c98164bf04c9c0c Mon Sep 17 00:00:00 2001 From: Marc Plano-Lesay Date: Wed, 9 Jun 2021 10:30:08 +1000 Subject: [PATCH] Add missing capability attributes for LLVM 12 --- src/google/protobuf/stubs/mutex.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/google/protobuf/stubs/mutex.h b/src/google/protobuf/stubs/mutex.h index 79c9f6784894..5c025b1496f1 100644 --- a/src/google/protobuf/stubs/mutex.h +++ b/src/google/protobuf/stubs/mutex.h @@ -52,10 +52,12 @@ __attribute__((acquire_capability(__VA_ARGS__))) #define GOOGLE_PROTOBUF_RELEASE(...) \ __attribute__((release_capability(__VA_ARGS__))) +#define GOOGLE_PROTOBUF_SCOPED_CAPABILITY __attribute__((scoped_lockable)) #define GOOGLE_PROTOBUF_CAPABILITY(x) __attribute__((capability(x))) #else #define GOOGLE_PROTOBUF_ACQUIRE(...) #define GOOGLE_PROTOBUF_RELEASE(...) +#define GOOGLE_PROTOBUF_SCOPED_CAPABILITY #define GOOGLE_PROTOBUF_CAPABILITY(x) #endif @@ -140,10 +142,12 @@ class GOOGLE_PROTOBUF_CAPABILITY("mutex") PROTOBUF_EXPORT WrappedMutex { using Mutex = WrappedMutex; // MutexLock(mu) acquires mu when constructed and releases it when destroyed. -class PROTOBUF_EXPORT MutexLock { +class GOOGLE_PROTOBUF_SCOPED_CAPABILITY PROTOBUF_EXPORT MutexLock { public: - explicit MutexLock(Mutex *mu) : mu_(mu) { this->mu_->Lock(); } - ~MutexLock() { this->mu_->Unlock(); } + explicit MutexLock(Mutex *mu) GOOGLE_PROTOBUF_ACQUIRE(mu) : mu_(mu) { + this->mu_->Lock(); + } + ~MutexLock() GOOGLE_PROTOBUF_RELEASE() { this->mu_->Unlock(); } private: Mutex *const mu_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MutexLock);