Debian Codegraph @

mozglue/misc/PlatformConditionVariable.h

raw ◀ ▶
1 Debian patch touch this file
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_ConditionVariable_h
8 #define mozilla_ConditionVariable_h
9
10 #include <stdint.h>
11
12 #include <utility>
13
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
20
21 namespace mozilla {
22
23 enum class CVStatus { NoTimeout, Timeout };
24
25 namespace detail {
26
27 class ConditionVariableImpl {
28 public:
29 struct PlatformData;
30
31 MFBT_API ConditionVariableImpl();
32 MFBT_API ~ConditionVariableImpl();
33
34 // Wake one thread that is waiting on this condition.
35 MFBT_API void notify_one();
36
37 // Wake all threads that are waiting on this condition.
38 MFBT_API void notify_all();
39
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);
47
48 MFBT_API CVStatus wait_for(MutexImpl& lock,
49 const mozilla::TimeDuration& rel_time);
50
51 private:
52 ConditionVariableImpl(const ConditionVariableImpl&) = delete;
53 ConditionVariableImpl& operator=(const ConditionVariableImpl&) = delete;
54
55 PlatformData* platformData();
56
57 #if !defined(XP_WIN) && !defined(__wasi__)
•58 pthread_cond_t platformData_[1];
59 #else
60 void* platformData_[4];
61 #endif
62 };
63
64 } // namespace detail
65
66 } // namespace mozilla
67
68 #endif // mozilla_ConditionVariable_h