RT-Thread RTOS
1.2.0
An open source embedded real-time operating system
|
Data Structures | |
struct | rt_semaphore |
Functions | |
rt_err_t | rt_sem_init (rt_sem_t sem, const char *name, rt_uint32_t value, rt_uint8_t flag) |
rt_err_t | rt_sem_detach (rt_sem_t sem) |
rt_sem_t | rt_sem_create (const char *name, rt_uint32_t value, rt_uint8_t flag) |
rt_err_t | rt_sem_delete (rt_sem_t sem) |
rt_err_t | rt_sem_trytake (rt_sem_t sem) |
rt_err_t | rt_sem_release (rt_sem_t sem) |
rt_err_t | rt_sem_control (rt_sem_t sem, int cmd, void *arg) |
rt_err_t rt_sem_init | ( | rt_sem_t | sem, |
const char * | name, | ||
rt_uint32_t | value, | ||
rt_uint8_t | flag | ||
) |
This function will initialize a static semaphore object.
sem | is a pointer to the semaphore to initialize. It is assumed that storage for the semaphore will be allocated in your application. |
name | is a pointer to the name you would like to give the semaphore. |
value | is the initial value for the semaphore. If used to share resources, you should initialize the value as the number of available resources. If used to signal the occurrence of an event, you should initialize the value as 0. |
flag | is the semaphore flag, which determines the queuing way of how multiple threads wait when the semaphore is not available. The semaphore flag can be ONE of the following values: RT_IPC_FLAG_PRIO The pending threads will queue in order of priority. RT_IPC_FLAG_FIFO The pending threads will queue in the first-in-first-out method (also known as first-come-first-served (FCFS) scheduling strategy). NOTE: RT_IPC_FLAG_FIFO is a non-real-time scheduling mode. It is strongly recommended to use RT_IPC_FLAG_PRIO to ensure the thread is real-time UNLESS your applications concern about the first-in-first-out principle, and you clearly understand that all threads involved in this semaphore will become non-real-time threads. |
rt_err_t rt_sem_detach | ( | rt_sem_t | sem | ) |
This function will detach a static semaphore object.
sem | is a pointer to a semaphore object to be detached. |
rt_sem_t rt_sem_create | ( | const char * | name, |
rt_uint32_t | value, | ||
rt_uint8_t | flag | ||
) |
Creating a semaphore object.
name | is a pointer to the name you would like to give the semaphore. |
value | is the initial value for the semaphore. If used to share resources, you should initialize the value as the number of available resources. If used to signal the occurrence of an event, you should initialize the value as 0. |
flag | is the semaphore flag, which determines the queuing way of how multiple threads wait when the semaphore is not available. The semaphore flag can be ONE of the following values: RT_IPC_FLAG_PRIO The pending threads will queue in order of priority. RT_IPC_FLAG_FIFO The pending threads will queue in the first-in-first-out method (also known as first-come-first-served (FCFS) scheduling strategy). NOTE: RT_IPC_FLAG_FIFO is a non-real-time scheduling mode. It is strongly recommended to use RT_IPC_FLAG_PRIO to ensure the thread is real-time UNLESS your applications concern about the first-in-first-out principle, and you clearly understand that all threads involved in this semaphore will become non-real-time threads. |
rt_err_t rt_sem_delete | ( | rt_sem_t | sem | ) |
This function will delete a semaphore object and release the memory space.
sem | is a pointer to a semaphore object to be deleted. |
rt_err_t rt_sem_trytake | ( | rt_sem_t | sem | ) |
This function will try to take a semaphore, if the semaphore is unavailable, the thread returns immediately.
sem | is a pointer to a semaphore object. |
rt_err_t rt_sem_release | ( | rt_sem_t | sem | ) |
This function will release a semaphore. If there is thread suspended on the semaphore, it will get resumed.
sem | is a pointer to a semaphore object. |
rt_err_t rt_sem_control | ( | rt_sem_t | sem, |
int | cmd, | ||
void * | arg | ||
) |
This function will set some extra attributions of a semaphore object.
sem | is a pointer to a semaphore object. |
cmd | is a command word used to configure some attributions of the semaphore. |
arg | is the argument of the function to execute the command. |