C/C++ API Reference
Loading...
Searching...
No Matches
lock_traits.h
1// Copyright 2023 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 <type_traits>
17#include <utility>
18
21
22namespace pw::sync {
23
25
30template <typename Lock, typename = void>
31struct is_basic_lockable : std::false_type {};
32
33template <typename Lock>
35 std::void_t<decltype(std::declval<Lock>().lock()),
36 decltype(std::declval<Lock>().unlock())>>
37 : std::true_type {};
38
40template <typename Lock>
42
47template <typename Lock, typename = void>
48struct is_lockable : std::false_type {};
49
50template <typename Lock>
51struct is_lockable<Lock, std::void_t<decltype(std::declval<Lock>().try_lock())>>
52 : is_basic_lockable<Lock> {};
53
55template <typename Lock>
57
63template <typename Lock, typename Duration, typename = void>
64struct is_lockable_for : std::false_type {};
65
66template <typename Lock, typename Duration>
67struct is_lockable_for<Lock,
68 Duration,
69 std::void_t<decltype(std::declval<Lock>().try_lock_for(
70 std::declval<Duration>()))>> : is_lockable<Lock> {};
71
73template <typename Lock, typename Duration>
74inline constexpr bool is_lockable_for_v =
76
82template <typename Lock, typename TimePoint, typename = void>
83struct is_lockable_until : std::false_type {};
84
85template <typename Lock, typename TimePoint>
87 Lock,
88 TimePoint,
89 std::void_t<decltype(std::declval<Lock>().try_lock_until(
90 std::declval<TimePoint>()))>> : is_lockable<Lock> {};
91
93template <typename Lock, typename TimePoint>
94inline constexpr bool is_lockable_until_v =
96
101template <typename Lock, typename Clock>
103 : std::integral_constant<
104 bool,
105 is_lockable_for_v<Lock, typename Clock::duration> &&
106 is_lockable_until_v<Lock, typename Clock::time_point>> {};
107
109template <typename Lock, typename Clock>
110inline constexpr bool is_timed_lockable_v =
112
114
115} // namespace pw::sync
constexpr bool is_timed_lockable_v
Helper variable template for is_timed_lockable<Lock, Clock>::value.
Definition: lock_traits.h:110
constexpr bool is_lockable_v
Helper variable template for is_lockable<Lock>::value.
Definition: lock_traits.h:56
constexpr bool is_basic_lockable_v
Helper variable template for is_basic_lockable<Lock>::value.
Definition: lock_traits.h:41
constexpr bool is_lockable_until_v
Helper variable template for is_lockable_until<Lock, TimePoint>::value.
Definition: lock_traits.h:94
constexpr bool is_lockable_for_v
Helper variable template for is_lockable_for<Lock, Duration>::value.
Definition: lock_traits.h:74
Definition: binary_semaphore.h:26
Definition: lock_traits.h:31
Definition: lock_traits.h:64
Definition: lock_traits.h:83
Definition: lock_traits.h:48
Definition: lock_traits.h:106