no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / mozglue / misc / PlatformConditionVariable.h
blob61fb06ade1c194639dc587029f79bbc6c4f59843
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_ConditionVariable_h
8 #define mozilla_ConditionVariable_h
10 #include <stdint.h>
12 #include <utility>
14 #include "mozilla/Attributes.h"
15 #include "mozilla/PlatformMutex.h"
16 #include "mozilla/TimeStamp.h"
17 #if !defined(XP_WIN) && !defined(__wasi__)
18 # include <pthread.h>
19 #endif
21 namespace mozilla {
23 enum class CVStatus { NoTimeout, Timeout };
25 namespace detail {
27 class ConditionVariableImpl {
28 public:
29 struct PlatformData;
31 MFBT_API ConditionVariableImpl();
32 MFBT_API ~ConditionVariableImpl();
34 // Wake one thread that is waiting on this condition.
35 MFBT_API void notify_one();
37 // Wake all threads that are waiting on this condition.
38 MFBT_API void notify_all();
40 // Atomically release |lock| and sleep the current thread of execution on
41 // this condition variable.
42 // |lock| will be re-acquired before this function returns.
43 // The thread may be woken from sleep from another thread via notify_one()
44 // or notify_all(), but may also wake spuriously. The caller should recheck
45 // its predicate after this function returns, typically in a while loop.
46 MFBT_API void wait(MutexImpl& lock);
48 MFBT_API CVStatus wait_for(MutexImpl& lock,
49 const mozilla::TimeDuration& rel_time);
51 private:
52 ConditionVariableImpl(const ConditionVariableImpl&) = delete;
53 ConditionVariableImpl& operator=(const ConditionVariableImpl&) = delete;
55 PlatformData* platformData();
57 #if !defined(XP_WIN) && !defined(__wasi__)
58 void* platformData_[sizeof(pthread_cond_t) / sizeof(void*)];
59 static_assert(sizeof(pthread_cond_t) / sizeof(void*) != 0 &&
60 sizeof(pthread_cond_t) % sizeof(void*) == 0,
61 "pthread_cond_t must have pointer alignment");
62 #else
63 void* platformData_[4];
64 #endif
67 } // namespace detail
69 } // namespace mozilla
71 #endif // mozilla_ConditionVariable_h