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"
328 &mutex::owner_links_>;
508 : object_named_system{ name },
509 type_ (attr.mx_type),
510 protocol_ (attr.mx_protocol),
511 robustness_ (attr.mx_robustness),
512 max_count_ ((attr.mx_type ==
type::recursive) ? attr.mx_max_count
515#if defined(OS_TRACE_RTOS_MUTEX)
516 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
526#if !defined(OS_USE_RTOS_PORT_MUTEX)
538#if defined(OS_USE_RTOS_PORT_MUTEX)
541 port::mutex::create (
this);
572#if defined(OS_TRACE_RTOS_MUTEX)
576#if defined(OS_USE_RTOS_PORT_MUTEX)
578 port::mutex::destroy (
this);
583 assert (owner_ ==
nullptr);
585 assert (list_.empty ());
595 mutex::internal_init_ (
void)
598 owner_links_.unlink ();
600 prio_ceiling_ = initial_prio_ceiling_;
606#if !defined(OS_USE_RTOS_PORT_MUTEX)
621 mutex::internal_try_lock_ (
thread* th)
624 thread* saved_owner = owner_;
627 if (owner_ ==
nullptr)
638 th_list->link (*
this);
640#pragma GCC diagnostic push
641#if defined(__clang__)
642#pragma clang diagnostic ignored "-Wdeprecated-volatile"
643#elif defined(__GNUC__)
644#pragma GCC diagnostic ignored "-Wvolatile"
647 ++(owner_->acquired_mutexes_);
648#pragma GCC diagnostic pop
652 if (th->priority () > prio_ceiling_)
671 boosted_prio_ = prio_ceiling_;
672 if (boosted_prio_ > owner_->priority_inherited ())
675 scheduler::uncritical_section sucs;
677 owner_->priority_inherited (boosted_prio_);
682#if defined(OS_TRACE_RTOS_MUTEX)
699 if (saved_owner == th)
704 if (count_ >= max_count_)
707#if defined(OS_TRACE_RTOS_MUTEX)
714#pragma GCC diagnostic push
715#if defined(__clang__)
716#pragma clang diagnostic ignored "-Wdeprecated-volatile"
717#elif defined(__GNUC__)
718#pragma GCC diagnostic ignored "-Wvolatile"
722#pragma GCC diagnostic pop
724#if defined(OS_TRACE_RTOS_MUTEX)
726 name (), th, th->name (), count_);
733#if defined(OS_TRACE_RTOS_MUTEX)
740#if defined(OS_TRACE_RTOS_MUTEX)
769 boosted_prio_ = prio;
771 if (owner_links_.unlinked ())
775 th_list->link (*
this);
779 if ((boosted_prio_ > owner_->priority_inherited ()))
782 scheduler::uncritical_section sucs;
784 owner_->priority_inherited (boosted_prio_);
788#if defined(OS_TRACE_RTOS_MUTEX)
790 this,
name (), boosted_prio_, th, th->name ());
802 mutex::internal_unlock_ (
thread* th)
806 return ENOTRECOVERABLE;
811 scheduler::critical_section scs;
818#pragma GCC diagnostic push
819#if defined(__clang__)
820#pragma clang diagnostic ignored "-Wdeprecated-volatile"
821#elif defined(__GNUC__)
822#pragma GCC diagnostic ignored "-Wvolatile"
826#pragma GCC diagnostic pop
828#if defined(OS_TRACE_RTOS_MUTEX)
835#pragma GCC diagnostic push
836#if defined(__clang__)
837#pragma clang diagnostic ignored "-Wdeprecated-volatile"
838#elif defined(__GNUC__)
839#pragma GCC diagnostic ignored "-Wvolatile"
841 --(owner_->acquired_mutexes_);
842#pragma GCC diagnostic pop
846 owner_links_.unlink ();
853 if (thread_mutexes->empty ())
865#pragma GCC diagnostic push
866#if defined(__clang__)
867#elif defined(__GNUC__)
868#pragma GCC diagnostic ignored "-Waggregate-return"
870 for (
auto&& mx : *thread_mutexes)
872 if (mx.boosted_prio_ > max_prio)
874 max_prio = mx.boosted_prio_;
877#pragma GCC diagnostic pop
878 boosted_prio_ = max_prio;
881 owner_->priority_inherited (boosted_prio_);
891#if defined(OS_TRACE_RTOS_MUTEX)
906 recoverable_ =
false;
907 return ENOTRECOVERABLE;
918#if defined(OS_TRACE_RTOS_MUTEX)
927#if defined(OS_TRACE_RTOS_MUTEX)
928 trace::printf (
"%s() ENOTRECOVERABLE @%p %s \n", __func__,
this,
931 return ENOTRECOVERABLE;
938 mutex::internal_mark_owner_dead_ (
void)
1005#if defined(OS_TRACE_RTOS_MUTEX)
1017 return ENOTRECOVERABLE;
1020#if defined(OS_USE_RTOS_PORT_MUTEX)
1022 return port::mutex::lock (
this);
1033 res = internal_try_lock_ (&crt_thread);
1034 if (res != EWOULDBLOCK)
1052 res = internal_try_lock_ (&crt_thread);
1053 if (res != EWOULDBLOCK)
1063 scheduler::internal_link_node (list_, node);
1074 scheduler::internal_unlink_node (node);
1078#if defined(OS_TRACE_RTOS_MUTEX)
1086 return ENOTRECOVERABLE;
1128#if defined(OS_TRACE_RTOS_MUTEX)
1138 return ENOTRECOVERABLE;
1141#if defined(OS_USE_RTOS_PORT_MUTEX)
1143 return port::mutex::try_lock (
this);
1153 return internal_try_lock_ (&crt_thread);
1207#if defined(OS_TRACE_RTOS_MUTEX)
1208#pragma GCC diagnostic push
1209#if defined(__clang__)
1210#elif defined(__GNUC__)
1211#pragma GCC diagnostic ignored "-Wuseless-cast"
1214 static_cast<unsigned int> (timeout),
this,
name (),
1216#pragma GCC diagnostic pop
1226 return ENOTRECOVERABLE;
1229#if defined(OS_USE_RTOS_PORT_MUTEX)
1231 return port::mutex::timed_lock (
this, timeout);
1245 res = internal_try_lock_ (&crt_thread);
1246 if (res != EWOULDBLOCK)
1271 res = internal_try_lock_ (&crt_thread);
1272 if (res != EWOULDBLOCK)
1283 scheduler::internal_link_node (list_, node, clock_list,
1296 scheduler::internal_unlink_node (node, timeout_node);
1302#if defined(OS_TRACE_RTOS_MUTEX)
1307 else if (clock_->steady_now () >= timeout_timestamp)
1309#if defined(OS_TRACE_RTOS_MUTEX)
1324#pragma GCC diagnostic push
1325#if defined(__clang__)
1326#elif defined(__GNUC__)
1327#pragma GCC diagnostic ignored "-Waggregate-return"
1329 for (
auto&& th : list_)
1332 if (prio > max_prio)
1337#pragma GCC diagnostic pop
1341 boosted_prio_ = max_prio;
1342 owner_->priority (boosted_prio_);
1350 return ENOTRECOVERABLE;
1381#if defined(OS_TRACE_RTOS_MUTEX)
1389#if defined(OS_USE_RTOS_PORT_MUTEX)
1391 return port::mutex::unlock (
this);
1397 return internal_unlock_ (crt_thread);
1419#if defined(OS_TRACE_RTOS_MUTEX)
1426#if defined(OS_USE_RTOS_PORT_MUTEX)
1428 return port::mutex::prio_ceiling (
this);
1432 return prio_ceiling_;
1464#if defined(OS_TRACE_RTOS_MUTEX)
1471#if defined(OS_USE_RTOS_PORT_MUTEX)
1473 return port::mutex::prio_ceiling (
this,
prio_ceiling, old_prio_ceiling);
1484 if (old_prio_ceiling !=
nullptr)
1486 *old_prio_ceiling = prio_ceiling_;
1532#if defined(OS_TRACE_RTOS_MUTEX)
1543#if defined(OS_USE_RTOS_PORT_MUTEX)
1545 return port::mutex::consistent (
this);
1569#if defined(OS_TRACE_RTOS_MUTEX)
rtos::clock * clock
Attribute with the address of the clock to be used for timeouts.
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.
thread::priority_t mx_priority_ceiling
Attribute with the mutex priority ceiling.
result_t reset(void)
Reset the mutex.
result_t lock(void)
Lock/acquire the mutex.
thread::priority_t prio_ceiling(void) const
Get the priority ceiling of a mutex.
mutex(const attributes &attr=initializer_normal)
Construct a mutex object instance.
result_t timed_lock(clock::duration_t timeout)
Timed attempt to lock/acquire the mutex.
result_t try_lock(void)
Try to lock/acquire the mutex.
~mutex()
Destruct the mutex object instance.
result_t consistent(void)
Mark mutex as consistent.
result_t unlock(void)
Unlock/release the mutex.
Scheduler critical section RAII helper.
POSIX compliant thread, using the default RTOS allocator.
bool interrupted(void)
Check if interrupted.
The core of a double linked list, pointers to next, previous.
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_recursive initializer_recursive
Default recursive mutex initialiser.
static const attributes initializer_normal
Default normal mutex initialiser.
uint8_t priority_t
Type of variables holding thread priorities.
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.
utils::intrusive_list< mutex, utils::double_list_links, &mutex::owner_links_ > mutexes_list
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.
@ max_
Maximum value, for validation purposes.
@ inherit
Inherit priority from highest priority thread.
@ protect
Execute at the highest priority.
@ max_
Maximum value, for validation purposes.
@ robust
Enhanced robustness at thread termination.
@ max_
Maximum value, for validation purposes.
@ normal
Normal mutex behaviour.
@ errorcheck
Check mutex behaviour.
@ recursive
Recursive mutex behaviour.