Merge mozilla-central to autoland. CLOSED TREE
[gecko.git] / mozglue / misc / PlatformMutex.h
blobac5459cf1033f75157737eba0caa9e2ec6fd50a5
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/. */
7 #ifndef mozilla_PlatformMutex_h
8 #define mozilla_PlatformMutex_h
10 #include <utility>
12 #include "mozilla/Attributes.h"
13 #include "mozilla/Types.h"
15 #if !defined(XP_WIN) && !defined(__wasi__)
16 # include <pthread.h>
17 #endif
19 namespace mozilla {
21 namespace detail {
23 class ConditionVariableImpl;
25 class MutexImpl {
26 public:
27 struct PlatformData;
29 explicit MFBT_API MutexImpl();
30 MFBT_API ~MutexImpl();
32 protected:
33 MFBT_API void lock();
34 MFBT_API void unlock();
35 // We have a separate, forwarding API so internal uses don't have to go
36 // through the PLT.
37 MFBT_API bool tryLock();
39 private:
40 MutexImpl(const MutexImpl&) = delete;
41 void operator=(const MutexImpl&) = delete;
42 MutexImpl(MutexImpl&&) = delete;
43 void operator=(MutexImpl&&) = delete;
44 bool operator==(const MutexImpl& rhs) = delete;
46 void mutexLock();
47 bool mutexTryLock();
49 PlatformData* platformData();
51 #if !defined(XP_WIN) && !defined(__wasi__)
52 void* platformData_[sizeof(pthread_mutex_t) / sizeof(void*)];
53 static_assert(sizeof(pthread_mutex_t) / sizeof(void*) != 0 &&
54 sizeof(pthread_mutex_t) % sizeof(void*) == 0,
55 "pthread_mutex_t must have pointer alignment");
56 #else
57 void* platformData_[6];
58 #endif
60 friend class mozilla::detail::ConditionVariableImpl;
63 } // namespace detail
65 } // namespace mozilla
66 #endif // mozilla_PlatformMutex_h