Mistake on this page?
Report an issue in GitHub or email us
Data Structures | Functions
Mutex class

Data Structures

class  Mutex
 The Mutex class is used to synchronize the execution of threads. More...
 

Functions

 Mutex ()
 Create and Initialize a Mutex object. More...
 
 Mutex (const char *name)
 Create and Initialize a Mutex object. More...
 
 ~Mutex ()
 Mutex destructor. More...
 
void lock ()
 Wait until a Mutex becomes available. More...
 
bool trylock ()
 Try to lock the mutex, and return immediately. More...
 
bool trylock_for (uint32_t millisec)
 Try to lock the mutex for a specified time. More...
 
bool trylock_for (Kernel::Clock::duration_u32 rel_time)
 Try to lock the mutex for a specified time. More...
 
bool trylock_until (uint64_t millisec)
 Try to lock the mutex until specified time. More...
 
bool trylock_until (Kernel::Clock::time_point abs_time)
 Try to lock the mutex until specified time. More...
 
void unlock ()
 Unlock the mutex that has previously been locked by the same thread. More...
 

Detailed Description

Function Documentation

void lock ( void  )

Wait until a Mutex becomes available.

Note
You cannot call this function from ISR context.

Definition at line 197 of file Mutex.h.

Mutex ( )

Create and Initialize a Mutex object.

Note
You cannot call this function from ISR context.

Definition at line 185 of file Mutex.h.

Mutex ( const char *  name)

Create and Initialize a Mutex object.

Parameters
namename to be used for this mutex. It has to stay allocated for the lifetime of the thread.
Note
You cannot call this function from ISR context.

Definition at line 189 of file Mutex.h.

bool trylock ( )

Try to lock the mutex, and return immediately.

Returns
true if the mutex was acquired, false otherwise.
Note
equivalent to trylock_for(0)
You cannot call this function from ISR context.

Definition at line 201 of file Mutex.h.

bool trylock_for ( uint32_t  millisec)

Try to lock the mutex for a specified time.

Parameters
millisectimeout value.
Returns
true if the mutex was acquired, false otherwise.
Note
the underlying RTOS may have a limit to the maximum wait time due to internal 32-bit computations, but this is guaranteed to work if the wait is <= 0x7fffffff milliseconds (~24 days). If the limit is exceeded, the lock attempt will time out earlier than specified.
You cannot call this function from ISR context.
Deprecated:
Pass a chrono duration, not an integer millisecond count. For example use 5s rather than 5000.

Definition at line 206 of file Mutex.h.

bool trylock_for ( Kernel::Clock::duration_u32  rel_time)

Try to lock the mutex for a specified time.

Parameters
rel_timetimeout value.
Returns
true if the mutex was acquired, false otherwise.
Note
the underlying RTOS may have a limit to the maximum wait time due to internal 32-bit computations, but this is guaranteed to work if the wait is <= 0x7fffffff milliseconds (~24 days). If the limit is exceeded, the lock attempt will time out earlier than specified.
You cannot call this function from ISR context.

Definition at line 211 of file Mutex.h.

bool trylock_until ( uint64_t  millisec)

Try to lock the mutex until specified time.

Parameters
millisecabsolute timeout time, referenced to Kernel::get_ms_count()
Returns
true if the mutex was acquired, false otherwise.
Note
the underlying RTOS may have a limit to the maximum wait time due to internal 32-bit computations, but this is guaranteed to work if the wait is <= 0x7fffffff milliseconds (~24 days). If the limit is exceeded, the lock attempt will time out earlier than specified.
You cannot call this function from ISR context.
Deprecated:
Pass a chrono time_point, not an integer millisecond count. For example use Kernel::Clock::now() + 5s rather than Kernel::get_ms_count() + 5000.

Definition at line 216 of file Mutex.h.

bool trylock_until ( Kernel::Clock::time_point  abs_time)

Try to lock the mutex until specified time.

Parameters
abs_timeabsolute timeout time, referenced to Kernel::get_ms_count()
Returns
true if the mutex was acquired, false otherwise.
Note
the underlying RTOS may have a limit to the maximum wait time due to internal 32-bit computations, but this is guaranteed to work if the wait is <= 0x7fffffff milliseconds (~24 days). If the limit is exceeded, the lock attempt will time out earlier than specified.
You cannot call this function from ISR context.

Definition at line 221 of file Mutex.h.

void unlock ( void  )

Unlock the mutex that has previously been locked by the same thread.

Note
You cannot call this function from ISR context.

Definition at line 226 of file Mutex.h.

~Mutex ( )

Mutex destructor.

Note
You cannot call this function from ISR context.

Definition at line 193 of file Mutex.h.

Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.