30 #ifndef GOOGLE_PROTOBUF_STUBS_MUTEX_H_
31 #define GOOGLE_PROTOBUF_STUBS_MUTEX_H_
35 #ifdef GOOGLE_PROTOBUF_SUPPORT_WINDOWS_XP
46 #include <google/protobuf/stubs/macros.h>
50 #if defined(__clang__) && !defined(SWIG)
51 #define GOOGLE_PROTOBUF_ACQUIRE(...) \
52 __attribute__((acquire_capability(__VA_ARGS__)))
53 #define GOOGLE_PROTOBUF_RELEASE(...) \
54 __attribute__((release_capability(__VA_ARGS__)))
55 #define GOOGLE_PROTOBUF_SCOPED_CAPABILITY __attribute__((scoped_lockable))
56 #define GOOGLE_PROTOBUF_CAPABILITY(x) __attribute__((capability(x)))
58 #define GOOGLE_PROTOBUF_ACQUIRE(...)
59 #define GOOGLE_PROTOBUF_RELEASE(...)
60 #define GOOGLE_PROTOBUF_SCOPED_CAPABILITY
61 #define GOOGLE_PROTOBUF_CAPABILITY(x)
64 #include <google/protobuf/port_def.inc>
72 #define GOOGLE_PROTOBUF_LINKER_INITIALIZED
74 #ifdef GOOGLE_PROTOBUF_SUPPORT_WINDOWS_XP
80 class PROTOBUF_EXPORT CriticalSectionLock {
82 CriticalSectionLock() { InitializeCriticalSection(&critical_section_); }
83 ~CriticalSectionLock() { DeleteCriticalSection(&critical_section_); }
84 void lock() { EnterCriticalSection(&critical_section_); }
85 void unlock() { LeaveCriticalSection(&critical_section_); }
88 CRITICAL_SECTION critical_section_;
109 return reinterpret_cast<T&
>(
buf_);
122 constexpr WrappedMutex() =
default;
124 constexpr WrappedMutex() {}
130 void AssertHeld()
const {}
133 #if defined(GOOGLE_PROTOBUF_SUPPORT_WINDOWS_XP)
134 CallOnceInitializedMutex<CriticalSectionLock>
mu_{};
135 #elif defined(_WIN32)
136 CallOnceInitializedMutex<std::mutex>
mu_{};
142 using Mutex = WrappedMutex;
165 mu_(
mu) {
if (this->
mu_ !=
nullptr) { this->
mu_->Lock(); } }
172 #if defined(GOOGLE_PROTOBUF_NO_THREADLOCAL)
174 class ThreadLocalStorage {
176 ThreadLocalStorage() {
179 ~ThreadLocalStorage() {
180 pthread_key_delete(
key_);
192 delete static_cast<T*
>(
value);
208 using internal::MutexLockMaybe;
213 #undef GOOGLE_PROTOBUF_ACQUIRE
214 #undef GOOGLE_PROTOBUF_RELEASE
216 #include <google/protobuf/port_undef.inc>
218 #endif // GOOGLE_PROTOBUF_STUBS_MUTEX_H_