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