cortex 0.0.1
Loading...
Searching...
No Matches
cortex::tiny_fiber::Mutex Class Reference

A cooperative mutex that yields instead of blocking. More...

#include <mutex.hpp>

Classes

class  Guard
 RAII lock guard for Mutex. More...
 

Public Member Functions

 Mutex ()=default
 
 ~Mutex ()
 
 Mutex (const Mutex &)=delete
 
Mutexoperator= (const Mutex &)=delete
 
void Lock ()
 Lock the mutex.
 
bool TryLock ()
 Try to lock the mutex without yielding.
 
void Unlock ()
 Unlock the mutex.
 
bool IsLocked () const noexcept
 Check if the mutex is currently locked.
 

Friends

class ConditionVariable
 

Detailed Description

A cooperative mutex that yields instead of blocking.

When a fiber tries to lock an already-locked mutex, it yields control to other fibers until the mutex becomes available.

Constructor & Destructor Documentation

◆ Mutex() [1/2]

cortex::tiny_fiber::Mutex::Mutex ( )
default

◆ ~Mutex()

cortex::tiny_fiber::Mutex::~Mutex ( )

◆ Mutex() [2/2]

cortex::tiny_fiber::Mutex::Mutex ( const Mutex )
delete

Member Function Documentation

◆ IsLocked()

bool cortex::tiny_fiber::Mutex::IsLocked ( ) const
inlinenoexcept

Check if the mutex is currently locked.

◆ Lock()

void cortex::tiny_fiber::Mutex::Lock ( )

Lock the mutex.

If the mutex is already locked, the current fiber yields until it becomes available.

◆ operator=()

Mutex & cortex::tiny_fiber::Mutex::operator= ( const Mutex )
delete

◆ TryLock()

bool cortex::tiny_fiber::Mutex::TryLock ( )

Try to lock the mutex without yielding.

Returns
true if the lock was acquired, false otherwise.

◆ Unlock()

void cortex::tiny_fiber::Mutex::Unlock ( )

Unlock the mutex.

If there are fibers waiting for this mutex, one will be scheduled.

Friends And Related Symbol Documentation

◆ ConditionVariable


The documentation for this class was generated from the following file: