PlatformMutex.h (1642B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_PlatformMutex_h 8 #define mozilla_PlatformMutex_h 9 10 #include "mozilla/Types.h" 11 12 #if !defined(XP_WIN) && !defined(__wasi__) 13 # include <pthread.h> 14 #endif 15 16 namespace mozilla { 17 18 namespace detail { 19 20 class ConditionVariableImpl; 21 22 class MutexImpl { 23 public: 24 struct PlatformData; 25 26 explicit MFBT_API MutexImpl(); 27 MFBT_API ~MutexImpl(); 28 29 protected: 30 MFBT_API void lock(); 31 MFBT_API void unlock(); 32 // We have a separate, forwarding API so internal uses don't have to go 33 // through the PLT. 34 MFBT_API bool tryLock(); 35 36 private: 37 MutexImpl(const MutexImpl&) = delete; 38 void operator=(const MutexImpl&) = delete; 39 MutexImpl(MutexImpl&&) = delete; 40 void operator=(MutexImpl&&) = delete; 41 bool operator==(const MutexImpl& rhs) = delete; 42 43 void mutexLock(); 44 bool mutexTryLock(); 45 46 PlatformData* platformData(); 47 48 #if !defined(XP_WIN) && !defined(__wasi__) 49 void* platformData_[sizeof(pthread_mutex_t) / sizeof(void*)]; 50 static_assert(sizeof(pthread_mutex_t) / sizeof(void*) != 0 && 51 sizeof(pthread_mutex_t) % sizeof(void*) == 0, 52 "pthread_mutex_t must have pointer alignment"); 53 #else 54 void* platformData_[6]; 55 #endif 56 57 friend class mozilla::detail::ConditionVariableImpl; 58 }; 59 60 } // namespace detail 61 62 } // namespace mozilla 63 #endif // mozilla_PlatformMutex_h