1 // Copyright 2022 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 #pragma once
15
16 #include <mutex>
17
18 #include "pw_sync/condition_variable.h"
19
20 namespace pw::sync {
21
notify_one()22 inline void ConditionVariable::notify_one() { native_type_.notify_one(); }
23
notify_all()24 inline void ConditionVariable::notify_all() { native_type_.notify_all(); }
25
26 template <typename Predicate>
wait(std::unique_lock<Mutex> & lock,Predicate predicate)27 void ConditionVariable::wait(std::unique_lock<Mutex>& lock,
28 Predicate predicate) {
29 native_type_.wait(lock, std::move(predicate));
30 }
31
32 template <typename Predicate>
wait_for(std::unique_lock<Mutex> & lock,pw::chrono::SystemClock::duration timeout,Predicate predicate)33 bool ConditionVariable::wait_for(std::unique_lock<Mutex>& lock,
34 pw::chrono::SystemClock::duration timeout,
35 Predicate predicate) {
36 return native_type_.wait_for(lock, timeout, std::move(predicate));
37 }
38
39 template <typename Predicate>
wait_until(std::unique_lock<Mutex> & lock,pw::chrono::SystemClock::time_point deadline,Predicate predicate)40 bool ConditionVariable::wait_until(std::unique_lock<Mutex>& lock,
41 pw::chrono::SystemClock::time_point deadline,
42 Predicate predicate) {
43 return native_type_.wait_until(lock, deadline, std::move(predicate));
44 }
45
46 inline auto ConditionVariable::native_handle() -> native_handle_type {
47 return native_type_;
48 }
49
50 } // namespace pw::sync
51