Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
Semaphore Class Reference
[Semaphore class]
The Semaphore class is used to manage and protect access to a set of shared resources. More...
#include <Semaphore.h>
Inherits NonCopyable< Semaphore >.
Public Member Functions | |
Semaphore (int32_t count=0) | |
Create and Initialize a Semaphore object used for managing resources. | |
Semaphore (int32_t count, uint16_t max_count) | |
Create and Initialize a Semaphore object used for managing resources. | |
MBED_DEPRECATED_SINCE ("mbed-os-5.13","Replaced with acquire, try_acquire() and try_acquire_for() functions") int32_t wait(uint32_t millisec | |
Wait until a Semaphore resource becomes available. | |
MBED_DEPRECATED_SINCE ("mbed-os-5.13","Replaced with try_acquire_until()") int32_t wait_until(uint64_t millisec) | |
Wait until a Semaphore resource becomes available. | |
void | acquire () |
Wait until a Semaphore resource becomes available. | |
bool | try_acquire () |
Try to acquire a Semaphore resource, and return immediately. | |
bool | try_acquire_for (uint32_t millisec) |
Wait until a Semaphore resource becomes available. | |
bool | try_acquire_until (uint64_t millisec) |
Wait until a Semaphore resource becomes available. | |
osStatus | release (void) |
Release a Semaphore resource that was obtain with Semaphore::acquire. | |
~Semaphore () | |
Semaphore destructor. | |
Private Member Functions | |
MBED_DEPRECATED ("Invalid copy construction of a NonCopyable resource.") NonCopyable(const NonCopyable &) | |
NonCopyable copy constructor. | |
MBED_DEPRECATED ("Invalid copy assignment of a NonCopyable resource.") NonCopyable &operator | |
NonCopyable copy assignment operator. |
Detailed Description
The Semaphore class is used to manage and protect access to a set of shared resources.
- Note:
- Memory considerations: The semaphore control structures will be created on current thread's stack, both for the mbed OS and underlying RTOS objects (static or dynamic RTOS memory pools are not being used).
Definition at line 47 of file Semaphore.h.
Constructor & Destructor Documentation
Semaphore | ( | int32_t | count = 0 ) |
Create and Initialize a Semaphore object used for managing resources.
- Parameters:
-
count number of available resources; maximum index value is (count-1). (default: 0).
- Note:
- You cannot call this function from ISR context.
Definition at line 33 of file Semaphore.cpp.
Semaphore | ( | int32_t | count, |
uint16_t | max_count | ||
) |
Create and Initialize a Semaphore object used for managing resources.
- Parameters:
-
count number of available resources max_count maximum number of available resources
- Note:
- You cannot call this function from ISR context.
Definition at line 38 of file Semaphore.cpp.
~Semaphore | ( | ) |
Semaphore destructor.
- Note:
- You cannot call this function from ISR context.
Definition at line 220 of file Semaphore.cpp.
Member Function Documentation
void acquire | ( | void | ) |
Wait until a Semaphore resource becomes available.
- Note:
- You cannot call this function from ISR context.
Definition at line 146 of file Semaphore.cpp.
MBED_DEPRECATED_SINCE | ( | "mbed-os-5.13" | , |
"Replaced with try_acquire_until()" | |||
) |
Wait until a Semaphore resource becomes available.
- Parameters:
-
millisec absolute timeout time, referenced to Kernel::get_ms_count()
- Returns:
- number of available tokens, before taking one; or -1 in case of incorrect parameters
- 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 acquire attempt will time out earlier than specified.
- You cannot call this function from ISR context.
MBED_DEPRECATED_SINCE | ( | "mbed-os-5.13" | , |
"Replaced with | acquire, | ||
try_acquire() and try_acquire_for() functions" | |||
) |
Wait until a Semaphore resource becomes available.
- Parameters:
-
millisec timeout value. (default: osWaitForever).
- Returns:
- number of available tokens, before taking one; or -1 in case of incorrect parameters
- Note:
- You may call this function from ISR context if the millisec parameter is set to 0.
osStatus release | ( | void | ) |
Release a Semaphore resource that was obtain with Semaphore::acquire.
- Returns:
- status code that indicates the execution status of the function: osOK the token has been correctly released. osErrorResource the maximum token count has been reached. osErrorParameter internal error.
- Note:
- You may call this function from ISR context.
Definition at line 204 of file Semaphore.cpp.
bool try_acquire | ( | ) |
Try to acquire a Semaphore resource, and return immediately.
- Returns:
- true if a resource was acquired, false otherwise.
- Note:
- equivalent to try_acquire_for(0)
- You may call this function from ISR context.
Definition at line 70 of file Semaphore.cpp.
bool try_acquire_for | ( | uint32_t | millisec ) |
Wait until a Semaphore resource becomes available.
- Parameters:
-
millisec timeout value.
- Returns:
- true if a resource was acquired, false otherwise.
- Note:
- You may call this function from ISR context if the millisec parameter is set to 0.
Definition at line 162 of file Semaphore.cpp.
bool try_acquire_until | ( | uint64_t | millisec ) |
Wait until a Semaphore resource becomes available.
- Parameters:
-
millisec absolute timeout time, referenced to Kernel::get_ms_count()
- Returns:
- true if a resource 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 acquire attempt will time out earlier than specified.
- You cannot call this function from ISR context.
Definition at line 184 of file Semaphore.cpp.
Generated on Tue Jul 12 2022 13:55:45 by
