33#pragma clang diagnostic ignored "-Wc++98-compat"
173 const count_t initial_value,
const attributes& attr
175 __attribute__((unused))
180 max_value_ (max_value),
181 initial_value_ (initial_value)
183#if defined(OS_TRACE_RTOS_SEMAPHORE)
184 trace::printf (
"%s() @%p %s %u %u\n", __func__,
this, this->name (),
185 initial_value, max_value_);
193 assert(max_value_ > 0);
194 assert(initial_value >= 0);
195 assert(initial_value <= max_value_);
197 count_ = initial_value;
199#if !defined(OS_USE_RTOS_PORT_SEMAPHORE)
200 clock_ = attr.clock !=
nullptr ? attr.clock : &
sysclock;
203#if defined(OS_USE_RTOS_PORT_SEMAPHORE)
205 port::semaphore::create (
this);
238#if defined(OS_TRACE_RTOS_SEMAPHORE)
242#if defined(OS_USE_RTOS_PORT_SEMAPHORE)
244 port::semaphore::destroy (
this);
249 assert(list_.empty ());
259 semaphore::internal_init_ (
void)
262 count_ = initial_value_;
264#if !defined(OS_USE_RTOS_PORT_SEMAPHORE)
279 semaphore::internal_try_wait_ (
void)
283#pragma GCC diagnostic push
284#if defined(__clang__)
285#pragma clang diagnostic ignored "-Wdeprecated-volatile"
288#pragma GCC diagnostic pop
290#if defined(OS_TRACE_RTOS_SEMAPHORE)
297#if defined(OS_TRACE_RTOS_SEMAPHORE)
348#if defined(OS_USE_RTOS_PORT_SEMAPHORE)
350#if defined(OS_TRACE_RTOS_SEMAPHORE)
354 return port::semaphore::post (
this);
359 assert(port::interrupts::is_priority_valid ());
365 if (count_ >= this->max_value_)
367#if defined(OS_TRACE_RTOS_SEMAPHORE)
373#pragma GCC diagnostic push
374#if defined(__clang__)
375#pragma clang diagnostic ignored "-Wdeprecated-volatile"
378#pragma GCC diagnostic pop
380#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_ ())
468 if (internal_try_wait_ ())
474 scheduler::internal_link_node (list_, node);
483 scheduler::internal_unlink_node (node);
487#if defined(OS_TRACE_RTOS_SEMAPHORE)
495 return ENOTRECOVERABLE;
523#if defined(OS_TRACE_RTOS_SEMAPHORE)
528 assert(port::interrupts::is_priority_valid ());
530#if defined(OS_USE_RTOS_PORT_SEMAPHORE)
532 return port::semaphore::try_wait (
this);
540 if (internal_try_wait_ ())
593#if defined(OS_TRACE_RTOS_SEMAPHORE)
595 static_cast<unsigned int> (timeout),
this,
name (),
604#if defined(OS_USE_RTOS_PORT_SEMAPHORE)
606 return port::semaphore::timed_wait (
this, timeout);
616 if (internal_try_wait_ ())
636 { timeout_timestamp, crt_thread };
644 if (internal_try_wait_ ())
651 scheduler::internal_link_node (list_, node, clock_list,
662 scheduler::internal_unlink_node (node, timeout_node);
666#if defined(OS_TRACE_RTOS_SEMAPHORE)
668 static_cast<unsigned int> (timeout),
this,
674 if (clock_->steady_now () >= timeout_timestamp)
676#if defined(OS_TRACE_RTOS_SEMAPHORE)
678 static_cast<unsigned int> (timeout),
this,
686 return ENOTRECOVERABLE;
715#if !defined(OS_USE_RTOS_PORT_SEMAPHORE)
716 return (count_ > 0) ? count_ : 0;
734#if defined(OS_TRACE_RTOS_SEMAPHORE)
741#if defined(OS_USE_RTOS_PORT_SEMAPHORE)
743 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.