µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
condition-variable.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ distribution.
3 * (https://github.com/micro-os-plus)
4 * Copyright (c) 2016 Liviu Ionescu.
5 *
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use,
10 * copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following
13 * conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 */
27
29
30// ----------------------------------------------------------------------------
31
32#if defined(__clang__)
33#pragma clang diagnostic ignored "-Wc++98-compat"
34#endif
35
36// ----------------------------------------------------------------------------
37
38namespace os
39{
40 namespace estd
41 {
42 // ========================================================================
43
44 void
46 {
48 res = ncv_.signal ();
49 if (res != os::rtos::result::ok)
50 {
52 static_cast<int> (res),
53 "condition_variable::notify_one() failed");
54 }
55 }
56
57 void
59 {
61 res = ncv_.broadcast ();
62 if (res != os::rtos::result::ok)
63 {
65 static_cast<int> (res),
66 "condition_variable::notify_all() failed");
67 }
68 }
69
70 void
71 condition_variable::wait (std::unique_lock<mutex>& lk)
72 {
73 if (!lk.owns_lock ())
74 {
76 EPERM, "condition_variable::wait: mutex not locked");
77 }
78 os::rtos::result_t res = ncv_.wait ((*(lk.mutex ()->native_handle ())));
79 if (res != os::rtos::result::ok)
80 {
81 os::estd::__throw_cmsis_error (static_cast<int> (res),
82 "condition_variable wait failed");
83 }
84 }
85
86#pragma GCC diagnostic push
87#pragma GCC diagnostic ignored "-Wunused-parameter"
88#pragma GCC diagnostic ignored "-Wmissing-noreturn"
89
90 void
92 std::unique_lock<mutex> lk)
93 {
94 //__thread_local_data()->notify_all_at_thread_exit(&cond, lk.release());
95 std::abort (); // Not implemented
96 }
97
98#pragma GCC diagnostic pop
99
100 // ==========================================================================
101 } /* namespace estd */
102} /* namespace os */
103
104// ----------------------------------------------------------------------------
105
void wait(std::unique_lock< mutex > &lock)
result_t signal(void)
Notify one thread waiting for a condition variable.
result_t broadcast(void)
Notify all threads waiting for a condition variable.
result_t wait(mutex &mutex)
Wait for a condition variable to be notified.
void notify_all_at_thread_exit(condition_variable &cond, std::unique_lock< mutex > lk)
void __throw_system_error(int ev, const char *what_arg)
void __throw_cmsis_error(int ev, const char *what_arg)
@ ok
Function completed; no errors or events occurred.
Definition os-decls.h:195
uint32_t result_t
Type of values returned by RTOS functions.
Definition os-decls.h:110
System namespace.