µ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-2023 Liviu Ionescu. All rights reserved.
5 *
6 * Permission to use, copy, modify, and/or distribute this software
7 * for any purpose is hereby granted, under the terms of the MIT license.
8 *
9 * If a copy of the license was not distributed with this file, it can
10 * be obtained from https://opensource.org/licenses/mit/.
11 */
12
14
15// ----------------------------------------------------------------------------
16
17#if defined(__clang__)
18#pragma clang diagnostic ignored "-Wc++98-compat"
19#endif
20
21// ----------------------------------------------------------------------------
22
23namespace os
24{
25 namespace estd
26 {
27 // ========================================================================
28
29 void
31 {
33 res = ncv_.signal ();
34 if (res != os::rtos::result::ok)
35 {
37 static_cast<int> (res),
38 "condition_variable::notify_one() failed");
39 }
40 }
41
42 void
44 {
46 res = ncv_.broadcast ();
47 if (res != os::rtos::result::ok)
48 {
50 static_cast<int> (res),
51 "condition_variable::notify_all() failed");
52 }
53 }
54
55 void
56 condition_variable::wait (std::unique_lock<mutex>& lk)
57 {
58 if (!lk.owns_lock ())
59 {
61 EPERM, "condition_variable::wait: mutex not locked");
62 }
63 os::rtos::result_t res = ncv_.wait ((*(lk.mutex ()->native_handle ())));
64 if (res != os::rtos::result::ok)
65 {
66 os::estd::__throw_cmsis_error (static_cast<int> (res),
67 "condition_variable wait failed");
68 }
69 }
70
71#pragma GCC diagnostic push
72#if defined(__clang__)
73#pragma clang diagnostic ignored "-Wunused-parameter"
74#pragma clang diagnostic ignored "-Wmissing-noreturn"
75#elif defined(__GNUC__)
76#pragma GCC diagnostic ignored "-Wunused-parameter"
77#pragma GCC diagnostic ignored "-Wmissing-noreturn"
78#endif
79
80 void
82 std::unique_lock<mutex> lk)
83 {
84 //__thread_local_data()->notify_all_at_thread_exit(&cond, lk.release());
85 std::abort (); // Not implemented
86 }
87
88#pragma GCC diagnostic pop
89
90 // ==========================================================================
91 } /* namespace estd */
92} /* namespace os */
93
94// ----------------------------------------------------------------------------
95
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:181
uint32_t result_t
Type of values returned by RTOS functions.
Definition os-decls.h:96
System namespace.