30 #ifndef GOOGLE_PROTOBUF_STUBS_MUTEX_H_
31 #define GOOGLE_PROTOBUF_STUBS_MUTEX_H_
35 #ifdef GOOGLE_PROTOBUF_SUPPORT_WINDOWS_XP
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_CAPABILITY(x) __attribute__((capability(x)))
57 #define GOOGLE_PROTOBUF_ACQUIRE(...)
58 #define GOOGLE_PROTOBUF_RELEASE(...)
59 #define GOOGLE_PROTOBUF_CAPABILITY(x)
62 #include <google/protobuf/port_def.inc>
70 #define GOOGLE_PROTOBUF_LINKER_INITIALIZED
72 #ifdef GOOGLE_PROTOBUF_SUPPORT_WINDOWS_XP
78 class PROTOBUF_EXPORT CriticalSectionLock {
80 CriticalSectionLock() { InitializeCriticalSection(&critical_section_); }
81 ~CriticalSectionLock() { DeleteCriticalSection(&critical_section_); }
82 void lock() { EnterCriticalSection(&critical_section_); }
83 void unlock() { LeaveCriticalSection(&critical_section_); }
86 CRITICAL_SECTION critical_section_;
98 WrappedMutex() =
default;
103 void AssertHeld()
const {}
106 #ifndef GOOGLE_PROTOBUF_SUPPORT_WINDOWS_XP
108 #else // ifndef GOOGLE_PROTOBUF_SUPPORT_WINDOWS_XP
109 CriticalSectionLock
mu_;
110 #endif // #ifndef GOOGLE_PROTOBUF_SUPPORT_WINDOWS_XP
133 mu_(mu) {
if (this->
mu_ !=
nullptr) { this->
mu_->Lock(); } }
140 #if defined(GOOGLE_PROTOBUF_NO_THREADLOCAL)
142 class ThreadLocalStorage {
144 ThreadLocalStorage() {
145 pthread_key_create(&key_, &ThreadLocalStorage::Delete);
147 ~ThreadLocalStorage() {
148 pthread_key_delete(key_);
151 T* result =
static_cast<T*
>(pthread_getspecific(key_));
152 if (result ==
nullptr) {
154 pthread_setspecific(key_, result);
159 static void Delete(
void*
value) {
160 delete static_cast<T*
>(
value);
176 using internal::MutexLockMaybe;
181 #undef GOOGLE_PROTOBUF_ACQUIRE
182 #undef GOOGLE_PROTOBUF_RELEASE
184 #include <google/protobuf/port_undef.inc>
186 #endif // GOOGLE_PROTOBUF_STUBS_MUTEX_H_