13#if defined(OS_USE_OS_APP_CONFIG_H)
14#include <cmsis-plus/os-app-config.h>
22#pragma clang diagnostic ignored "-Wc++98-compat"
161 const count_t initial_value,
const attributes& attr
163 __attribute__((unused))
168 max_value_ (max_value),
169 initial_value_ (initial_value)
171#if defined(OS_TRACE_RTOS_SEMAPHORE)
172 trace::printf (
"%s() @%p %s %u %u\n", __func__,
this, this->name (),
173 initial_value, max_value_);
181 assert(max_value_ > 0);
182 assert(initial_value >= 0);
183 assert(initial_value <= max_value_);
185 count_ = initial_value;
187#if !defined(OS_USE_RTOS_PORT_SEMAPHORE)
188 clock_ = attr.clock !=
nullptr ? attr.clock : &
sysclock;
191#if defined(OS_USE_RTOS_PORT_SEMAPHORE)
193 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)
338#if defined(OS_USE_RTOS_PORT_SEMAPHORE)
340#if defined(OS_TRACE_RTOS_SEMAPHORE)
344 return port::semaphore::post (
this);
349 assert(port::interrupts::is_priority_valid ());
355 if (count_ >= this->max_value_)
357#if defined(OS_TRACE_RTOS_SEMAPHORE)
363#pragma GCC diagnostic push
364#if defined(__clang__)
365#pragma clang diagnostic ignored "-Wdeprecated-volatile"
366#elif defined(__GNUC__)
367#pragma GCC diagnostic ignored "-Wvolatile"
370#pragma GCC diagnostic pop
372#if defined(OS_TRACE_RTOS_SEMAPHORE)
418#if defined(OS_TRACE_RTOS_SEMAPHORE)
427#if defined(OS_USE_RTOS_PORT_SEMAPHORE)
429 return port::semaphore::wait (
this);
439 if (internal_try_wait_ ())
460 if (internal_try_wait_ ())
466 scheduler::internal_link_node (list_, node);
475 scheduler::internal_unlink_node (node);
479#if defined(OS_TRACE_RTOS_SEMAPHORE)
487 return ENOTRECOVERABLE;
515#if defined(OS_TRACE_RTOS_SEMAPHORE)
520 assert(port::interrupts::is_priority_valid ());
522#if defined(OS_USE_RTOS_PORT_SEMAPHORE)
524 return port::semaphore::try_wait (
this);
532 if (internal_try_wait_ ())
585#if defined(OS_TRACE_RTOS_SEMAPHORE)
586#pragma GCC diagnostic push
587#if defined(__clang__)
588#elif defined(__GNUC__)
589#pragma GCC diagnostic ignored "-Wuseless-cast"
592 static_cast<unsigned int> (timeout),
this,
name (),
594#pragma GCC diagnostic pop
602#if defined(OS_USE_RTOS_PORT_SEMAPHORE)
604 return port::semaphore::timed_wait (
this, timeout);
614 if (internal_try_wait_ ())
634 { timeout_timestamp, crt_thread };
642 if (internal_try_wait_ ())
649 scheduler::internal_link_node (list_, node, clock_list,
660 scheduler::internal_unlink_node (node, timeout_node);
664#if defined(OS_TRACE_RTOS_SEMAPHORE)
665#pragma GCC diagnostic push
666#if defined(__clang__)
667#elif defined(__GNUC__)
668#pragma GCC diagnostic ignored "-Wuseless-cast"
671 static_cast<unsigned int> (timeout),
this,
673#pragma GCC diagnostic pop
678 if (clock_->steady_now () >= timeout_timestamp)
680#if defined(OS_TRACE_RTOS_SEMAPHORE)
681#pragma GCC diagnostic push
682#if defined(__clang__)
683#elif defined(__GNUC__)
684#pragma GCC diagnostic ignored "-Wuseless-cast"
687 static_cast<unsigned int> (timeout),
this,
689#pragma GCC diagnostic pop
696 return ENOTRECOVERABLE;
725#if !defined(OS_USE_RTOS_PORT_SEMAPHORE)
726 return (count_ > 0) ? count_ : 0;
744#if defined(OS_TRACE_RTOS_SEMAPHORE)
751#if defined(OS_USE_RTOS_PORT_SEMAPHORE)
753 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.
count_t sm_max_value
Semaphore max count value.
count_t sm_initial_value
Semaphore initial count value.
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 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.