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
Semaphores
[OS abstraction layer]
Semaphores can be either counting or binary - lwIP works with both kinds. More...
Functions | |
err_t | sys_sem_new (sys_sem_t *sem, u8_t count) |
Create a new semaphore Creates a new semaphore. | |
void | sys_sem_signal (sys_sem_t *sem) |
Signals a semaphore. | |
u32_t | sys_arch_sem_wait (sys_sem_t *sem, u32_t timeout) |
Blocks the thread while waiting for the semaphore to be signaled. | |
void | sys_sem_free (sys_sem_t *sem) |
Deallocates a semaphore. | |
int | sys_sem_valid (sys_sem_t *sem) |
Returns 1 if the semaphore is valid, 0 if it is not valid. | |
void | sys_sem_set_invalid (sys_sem_t *sem) |
Invalidate a semaphore so that sys_sem_valid() returns 0. |
Detailed Description
Semaphores can be either counting or binary - lwIP works with both kinds.
Semaphores are represented by the type "sys_sem_t" which is typedef'd in the sys_arch.h file. Mailboxes are equivalently represented by the type "sys_mbox_t". Mutexes are represented by the type "sys_mutex_t". lwIP does not place any restrictions on how these types are represented internally.
Function Documentation
u32_t sys_arch_sem_wait | ( | sys_sem_t * | sem, |
u32_t | timeout | ||
) |
Blocks the thread while waiting for the semaphore to be signaled.
If the "timeout" argument is non-zero, the thread should only be blocked for the specified time (measured in milliseconds). If the "timeout" argument is zero, the thread should be blocked until the semaphore is signalled.
The return value is SYS_ARCH_TIMEOUT if the semaphore wasn't signaled within the specified time or any other value if it was signaled (with or without waiting). Notice that lwIP implements a function with a similar name, sys_sem_wait(), that uses the sys_arch_sem_wait() function.
- Parameters:
-
sem the semaphore to wait for timeout timeout in milliseconds to wait (0 = wait forever)
- Returns:
- SYS_ARCH_TIMEOUT on timeout, any other value on success
Definition at line 98 of file sys_arch.c.
void sys_sem_free | ( | sys_sem_t * | sem ) |
Deallocates a semaphore.
- Parameters:
-
sem semaphore to delete
Definition at line 83 of file sys_arch.c.
err_t sys_sem_new | ( | sys_sem_t * | sem, |
u8_t | count | ||
) |
Create a new semaphore Creates a new semaphore.
The semaphore is allocated to the memory that 'sem' points to (which can be both a pointer or the actual OS structure). The "count" argument specifies the initial state of the semaphore (which is either 0 or 1). If the semaphore has been created, ERR_OK should be returned. Returning any other error will provide a hint what went wrong, but except for assertions, no real error handling is implemented.
- Parameters:
-
sem pointer to the semaphore to create count initial count of the semaphore
- Returns:
- ERR_OK if successful, another err_t otherwise
Definition at line 75 of file sys_arch.c.
void sys_sem_set_invalid | ( | sys_sem_t * | sem ) |
Invalidate a semaphore so that sys_sem_valid() returns 0.
ATTENTION: This does NOT mean that the semaphore shall be deallocated: sys_sem_free() is always called before calling this function! This may also be a define, in which case the function is not prototyped.
Definition at line 90 of file sys_arch.c.
void sys_sem_signal | ( | sys_sem_t * | sem ) |
Signals a semaphore.
- Parameters:
-
sem the semaphore to signal
Definition at line 140 of file sys_arch.c.
int sys_sem_valid | ( | sys_sem_t * | sem ) |
Returns 1 if the semaphore is valid, 0 if it is not valid.
When using pointers, a simple way is to check the pointer for != NULL. When directly using OS structures, implementing this may be more complex. This may also be a define, in which case the function is not prototyped.
Generated on Tue Jul 12 2022 13:55:23 by
