Bug 1699062 - Flatten toolkit/themes/*/global/alerts/. r=desktop-theme-reviewers,dao
[gecko.git] / mozglue / misc / PlatformMutex.h
blob704bf60e412a921009b17d29878fc408f797dfff
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"
14 #if !defined(XP_WIN)
15 # include <pthread.h>
16 #endif
18 namespace mozilla {
20 namespace detail {
22 class ConditionVariableImpl;
24 class MutexImpl {
25 public:
26 struct PlatformData;
28 explicit MFBT_API MutexImpl();
29 MFBT_API ~MutexImpl();
31 protected:
32 MFBT_API void lock();
33 MFBT_API void unlock();
34 // We have a separate, forwarding API so internal uses don't have to go
35 // through the PLT.
36 MFBT_API bool tryLock();
38 private:
39 MutexImpl(const MutexImpl&) = delete;
40 void operator=(const MutexImpl&) = delete;
41 MutexImpl(MutexImpl&&) = delete;
42 void operator=(MutexImpl&&) = delete;
43 bool operator==(const MutexImpl& rhs) = delete;
45 void mutexLock();
46 bool mutexTryLock();
48 PlatformData* platformData();
50 #if !defined(XP_WIN)
51 void* platformData_[sizeof(pthread_mutex_t) / sizeof(void*)];
52 static_assert(sizeof(pthread_mutex_t) / sizeof(void*) != 0 &&
53 sizeof(pthread_mutex_t) % sizeof(void*) == 0,
54 "pthread_mutex_t must have pointer alignment");
55 #else
56 void* platformData_[6];
57 #endif
59 friend class mozilla::detail::ConditionVariableImpl;
62 } // namespace detail
64 } // namespace mozilla
66 #endif // mozilla_PlatformMutex_h