roo_threads
API Documentation for roo_threads
Loading...
Searching...
No Matches
mutex.h
Go to the documentation of this file.
1#pragma once
2
4
5#if (defined ROO_THREADS_USE_CPPSTD)
6
8
9namespace roo {
10
11/// @brief Mutual exclusion primitive.
12using mutex = ::roo_threads::cppstd::mutex;
13
14/// @brief RAII lock that locks on construction and unlocks on destruction.
15/// @tparam Mutex mutex type.
16template <typename Mutex>
17using lock_guard = ::roo_threads::cppstd::lock_guard<Mutex>;
18
19/// @brief Movable lock wrapper with deferred/try/adopt locking options.
20/// @tparam Mutex mutex type.
21template <typename Mutex>
22using unique_lock = ::roo_threads::cppstd::unique_lock<Mutex>;
23
24/// @brief Tag type used to defer locking in `unique_lock` constructors.
25using defer_lock_t = ::roo_threads::cppstd::defer_lock_t;
26/// @brief Tag type used to request try-locking in `unique_lock` constructors.
27using try_to_lock_t = ::roo_threads::cppstd::try_to_lock_t;
28/// @brief Tag type used to adopt an already-locked mutex in `unique_lock`.
29using adopt_lock_t = ::roo_threads::cppstd::adopt_lock_t;
30
31/// Tags for `unique_lock` constructor overload selection.
32
33/// @brief Tag constant selecting deferred locking constructor overloads.
34inline constexpr defer_lock_t defer_lock{};
35/// @brief Tag constant selecting try-lock constructor overloads.
36inline constexpr try_to_lock_t try_to_lock{};
37/// @brief Tag constant selecting adopt-lock constructor overloads.
38inline constexpr adopt_lock_t adopt_lock{};
39
40} // namespace roo
41
42#elif (defined ROO_THREADS_USE_FREERTOS)
43
45
46namespace roo {
47
48/// @brief Mutual exclusion primitive.
49using mutex = ::roo_threads::freertos::mutex;
50/// @brief RAII lock that locks on construction and unlocks on destruction.
51/// @tparam Mutex mutex type.
52template <typename Mutex>
53using lock_guard = ::roo_threads::freertos::lock_guard<Mutex>;
54
55/// @brief Movable lock wrapper with deferred/try/adopt locking options.
56/// @tparam Mutex mutex type.
57template <typename Mutex>
58using unique_lock = ::roo_threads::freertos::unique_lock<Mutex>;
59
60/// @brief Tag type used to defer locking in `unique_lock` constructors.
61using defer_lock_t = ::roo_threads::freertos::defer_lock_t;
62/// @brief Tag type used to request try-locking in `unique_lock` constructors.
63using try_to_lock_t = ::roo_threads::freertos::try_to_lock_t;
64/// @brief Tag type used to adopt an already-locked mutex in `unique_lock`.
65using adopt_lock_t = ::roo_threads::freertos::adopt_lock_t;
66/// Tags for `unique_lock` constructor overload selection.
67
68/// @brief Tag constant selecting deferred locking constructor overloads.
69inline constexpr defer_lock_t defer_lock{};
70/// @brief Tag constant selecting try-lock constructor overloads.
71inline constexpr try_to_lock_t try_to_lock{};
72/// @brief Tag constant selecting adopt-lock constructor overloads.
73inline constexpr adopt_lock_t adopt_lock{};
74
75} // namespace roo
76
77#elif (defined ROO_THREADS_USE_ROO_TESTING)
78
79#include "roo_threads/impl/roo_testing/mutex.h"
80
81namespace roo {
82
83/// @brief Mutual exclusion primitive.
84using mutex = ::roo_threads::roo_testing::mutex;
85
86/// @brief RAII lock that locks on construction and unlocks on destruction.
87/// @tparam Mutex mutex type.
88template <typename Mutex>
89using lock_guard = ::roo_threads::roo_testing::lock_guard<Mutex>;
90
91/// @brief Movable lock wrapper with deferred/try/adopt locking options.
92/// @tparam Mutex mutex type.
93template <typename Mutex>
94using unique_lock = ::roo_threads::roo_testing::unique_lock<Mutex>;
95
96/// @brief Tag type used to defer locking in `unique_lock` constructors.
97using defer_lock_t = ::roo_threads::roo_testing::defer_lock_t;
98/// @brief Tag type used to request try-locking in `unique_lock` constructors.
99using try_to_lock_t = ::roo_threads::roo_testing::try_to_lock_t;
100/// @brief Tag type used to adopt an already-locked mutex in `unique_lock`.
101using adopt_lock_t = ::roo_threads::roo_testing::adopt_lock_t;
102
103/// Tags for `unique_lock` constructor overload selection.
104
105/// @brief Tag constant selecting deferred locking constructor overloads.
106inline constexpr defer_lock_t defer_lock{};
107/// @brief Tag constant selecting try-lock constructor overloads.
108inline constexpr try_to_lock_t try_to_lock{};
109/// @brief Tag constant selecting adopt-lock constructor overloads.
110inline constexpr adopt_lock_t adopt_lock{};
111
112} // namespace roo
113
114#elif (defined ROO_THREADS_SINGLETHREADED)
115
117
118namespace roo {
119
120/// @brief Mutual exclusion primitive.
121using mutex = ::roo_threads::singlethreaded::mutex;
122
123/// @brief RAII lock that locks on construction and unlocks on destruction.
124/// @tparam Mutex mutex type.
125template <typename Mutex>
126using lock_guard = ::roo_threads::singlethreaded::lock_guard<Mutex>;
127
128/// @brief Movable lock wrapper with deferred/try/adopt locking options.
129/// @tparam Mutex mutex type.
130template <typename Mutex>
131using unique_lock = ::roo_threads::singlethreaded::unique_lock<Mutex>;
132
133} // namespace roo
134
135#endif
Definition latch.h:6