10#ifndef STK_SYNC_MUTEX_H_
11#define STK_SYNC_MUTEX_H_
122 bool success =
false;
143 __stk_full_memfence();
148 else if (timeout_ticks !=
NO_WAIT)
217 __stk_full_memfence();
231 __stk_full_memfence();
#define STK_UNUSED(X)
Explicitly marks a variable as unused to suppress compiler warnings.
#define STK_NONCOPYABLE_CLASS(TYPE)
Disables copy construction and assignment for a class.
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
#define STK_VIRT_DTOR
Makes destructors virtual and compliant to strict rules if STK_STRICT_COMPLIANCY=0.
Implementation of synchronization primitive: stk::sync::ScopedCriticalSection.
Namespace of STK package.
static constexpr ITask * GetUserTaskFromTid(TId task_id) noexcept
Get task instance from its identifier.
constexpr Timeout NO_WAIT
Timeout value: return immediately if the synchronization object is not yet signaled (non-blocking pol...
int32_t Timeout
Timeout time (ticks).
static __stk_forceinline void STK_KERNEL_PANIC(stk::EKernelPanicId id)
Called when the kernel detects an unrecoverable internal fault.
@ WAIT_RESULT_TIMEOUT
The wake was caused by a timeout expiry.
constexpr Timeout WAIT_INFINITE
Timeout value: block indefinitely until the synchronization object is signaled.
static TId GetTid()
Get task/thread Id of the calling task.
constexpr TId TID_NONE
Reserved task/thread id representing zero/none thread id.
Word TId
Task (thread) id.
@ KERNEL_PANIC_ASSERT
Internal assertion failed (maps from STK_ASSERT).
bool IsInsideISR()
Check whether the CPU is currently executing inside a hardware interrupt service routine (ISR).
Synchronization primitives for task coordination and resource protection.
virtual TId GetTid() const =0
Get thread Id of the task owning .
virtual void Wake(bool timeout)=0
Wake task.
IWaitObject::ListHeadType m_wait_list
tasks blocked on this object
ISyncObject()
Constructor.
Weight FindWeightHigherThan(Weight comp) const
Find higher weight within linked wait objects.
Interface for mutex synchronization primitive.
Interface for the kernel services exposed to the user processes during run-time when Kernel started s...
virtual TId GetTid() const =0
Get thread Id of the currently running task.
virtual void InheritWeight(TId tid, Weight weight)=0
Inherit weight for the task.
static IKernelService * GetInstance()
Get CPU-local instance of the kernel service.
virtual EWaitResult Wait(ISyncObject *sobj, IMutex *mutex, Timeout timeout)=0
Put calling process into a waiting state until synchronization object is signaled or timeout occurs.
virtual void RestoreWeight(TId tid, ISyncObject *sobj=nullptr)=0
Restore weight of the task to the original value.
static __stk_forceinline TTargetType * ListEntryToParent(TSourceType *const lentry)
Safely casts an intrusive list entry to its concrete parent container object type.
RAII-style low-level synchronization primitive for atomic code execution. Used as building brick for ...
bool TimedLock(Timeout timeout_ticks)
Acquire lock.
TId m_owner_tid
thread id of the current owner
bool TryLock()
Acquire the lock.
TId GetOwner() const
Get owner of the mutex.
void Unlock() override
Release lock.
uint16_t m_recursion_count
recursion depth
void Lock() override
Acquire lock.
static const uint16_t RECURSION_MAX
maximum nesting depth