12#if defined(OS_USE_OS_APP_CONFIG_H)
13#include <cmsis-plus/os-app-config.h>
21#pragma clang diagnostic ignored "-Wc++98-compat"
149 :
semaphore{ name, attr.sm_max_value, attr.sm_initial_value, attr }
158 const count_t initial_value,
159 const attributes& attr
161 __attribute__ ((unused))
164 : object_named_system{ name },
165 max_value_ (max_value),
166 initial_value_ (initial_value)
168#if defined(OS_TRACE_RTOS_SEMAPHORE)
169 trace::printf (
"%s() @%p %s %u %u\n", __func__,
this, this->name (),
178 assert (max_value_ > 0);
184#if !defined(OS_USE_RTOS_PORT_SEMAPHORE)
185 clock_ = attr.clock !=
nullptr ? attr.clock : &
sysclock;
188#if defined(OS_USE_RTOS_PORT_SEMAPHORE)
190 port::semaphore::create (
this);
226#if defined(OS_TRACE_RTOS_SEMAPHORE)
230#if defined(OS_USE_RTOS_PORT_SEMAPHORE)
232 port::semaphore::destroy (
this);
237 assert (list_.empty ());
247 semaphore::internal_init_ (
void)
250 count_ = initial_value_;
252#if !defined(OS_USE_RTOS_PORT_SEMAPHORE)
267 semaphore::internal_try_wait_ (
void)
271#pragma GCC diagnostic push
272#if defined(__clang__)
273#pragma clang diagnostic ignored "-Wdeprecated-volatile"
274#elif defined(__GNUC__)
275#pragma GCC diagnostic ignored "-Wvolatile"
278#pragma GCC diagnostic pop
280#if defined(OS_TRACE_RTOS_SEMAPHORE)
287#if defined(OS_TRACE_RTOS_SEMAPHORE)
342#if defined(OS_USE_RTOS_PORT_SEMAPHORE)
344#if defined(OS_TRACE_RTOS_SEMAPHORE)
348 return port::semaphore::post (
this);
353 assert (port::interrupts::is_priority_valid ());
359 if (count_ >= this->max_value_)
361#if defined(OS_TRACE_RTOS_SEMAPHORE)
367#pragma GCC diagnostic push
368#if defined(__clang__)
369#pragma clang diagnostic ignored "-Wdeprecated-volatile"
370#elif defined(__GNUC__)
371#pragma GCC diagnostic ignored "-Wvolatile"
374#pragma GCC diagnostic pop
376#if defined(OS_TRACE_RTOS_SEMAPHORE)
426#if defined(OS_TRACE_RTOS_SEMAPHORE)
435#if defined(OS_USE_RTOS_PORT_SEMAPHORE)
437 return port::semaphore::wait (
this);
447 if (internal_try_wait_ ())
467 if (internal_try_wait_ ())
473 scheduler::internal_link_node (list_, node);
482 scheduler::internal_unlink_node (node);
486#if defined(OS_TRACE_RTOS_SEMAPHORE)
494 return ENOTRECOVERABLE;
526#if defined(OS_TRACE_RTOS_SEMAPHORE)
531 assert (port::interrupts::is_priority_valid ());
533#if defined(OS_USE_RTOS_PORT_SEMAPHORE)
535 return port::semaphore::try_wait (
this);
543 if (internal_try_wait_ ())
600#if defined(OS_TRACE_RTOS_SEMAPHORE)
601#pragma GCC diagnostic push
602#if defined(__clang__)
603#elif defined(__GNUC__)
604#pragma GCC diagnostic ignored "-Wuseless-cast"
607 static_cast<unsigned int> (timeout),
this,
name (),
609#pragma GCC diagnostic pop
617#if defined(OS_USE_RTOS_PORT_SEMAPHORE)
619 return port::semaphore::timed_wait (
this, timeout);
629 if (internal_try_wait_ ())
656 if (internal_try_wait_ ())
663 scheduler::internal_link_node (list_, node, clock_list,
674 scheduler::internal_unlink_node (node, timeout_node);
678#if defined(OS_TRACE_RTOS_SEMAPHORE)
679#pragma GCC diagnostic push
680#if defined(__clang__)
681#elif defined(__GNUC__)
682#pragma GCC diagnostic ignored "-Wuseless-cast"
685 static_cast<unsigned int> (timeout),
this,
687#pragma GCC diagnostic pop
692 if (clock_->steady_now () >= timeout_timestamp)
694#if defined(OS_TRACE_RTOS_SEMAPHORE)
695#pragma GCC diagnostic push
696#if defined(__clang__)
697#elif defined(__GNUC__)
698#pragma GCC diagnostic ignored "-Wuseless-cast"
701 static_cast<unsigned int> (timeout),
this,
703#pragma GCC diagnostic pop
710 return ENOTRECOVERABLE;
742#if !defined(OS_USE_RTOS_PORT_SEMAPHORE)
743 return (count_ > 0) ? count_ : 0;
761#if defined(OS_TRACE_RTOS_SEMAPHORE)
768#if defined(OS_USE_RTOS_PORT_SEMAPHORE)
770 return port::semaphore::reset (
this);
Ordered list of time stamp nodes.
const char * name(void) const
Get object name.
Double linked list node, with time stamp and thread.
Double linked list node, with thread reference.
Interrupts critical section RAII helper.
POSIX compliant semaphore.
result_t timed_wait(clock::duration_t timeout)
Timed wait to lock the semaphore.
result_t wait(void)
Lock the semaphore, possibly waiting.
result_t reset(void)
Reset the semaphore.
result_t post(void)
Post (unlock) the semaphore.
result_t try_wait(void)
Try to lock the semaphore.
~semaphore()
Destruct the semaphore object instance.
semaphore(const attributes &attr=initializer_binary)
Construct a semaphore object instance.
count_t initial_value(void) const
Get the semaphore initial count value.
count_t value(void) const
Get the semaphore count value.
POSIX compliant thread, using the default RTOS allocator.
bool interrupted(void)
Check if interrupted.
#define OS_USE_RTOS_PORT_SEMAPHORE
Use a custom semaphore implementation.
int printf(const char *format,...)
Write a formatted string to the trace device.
port::clock::duration_t duration_t
Type of variables holding clock durations.
port::clock::timestamp_t timestamp_t
Type of variables holding clock time stamps.
clock_systick sysclock
The system clock object instance.
static const attributes_binary initializer_binary
Default binary semaphore initialiser.
int16_t count_t
Type of semaphore counter storage.
bool in_handler_mode(void)
Check if the CPU is in handler mode.
@ ok
Function completed; no errors or events occurred.
bool locked(void)
Check if the scheduler is locked.
thread & thread(void)
Get the current running thread.
uint32_t result_t
Type of values returned by RTOS functions.
#define os_assert_throw(__e, __er)
Assert or throw a system error exception.
#define os_assert_err(__e, __er)
Assert or return an error.
Single file µOS++ RTOS definitions.