unified: Add support for semaphore groups
Semaphore groups are enabled by default. Disabling them will both decrease the footprint as well as improve the performance of the k_sem_give() routine. Change-Id: If6c1b0e2e1f71afd43e620f05f17068039d12b05 Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
This commit is contained in:
parent
3ffe5bfb8c
commit
45403678aa
4 changed files with 295 additions and 19 deletions
|
@ -644,10 +644,53 @@ static inline int k_sem_count_get(struct k_sem *sem)
|
|||
return sem->count;
|
||||
}
|
||||
|
||||
extern struct k_sem *k_sem_group_take(struct k_sem **sem_array,
|
||||
int32_t timeout);
|
||||
extern void k_sem_group_give(struct k_sem **sem_array);
|
||||
extern void k_sem_group_reset(struct k_sem **sem_array);
|
||||
#ifdef CONFIG_SEMAPHORE_GROUPS
|
||||
/**
|
||||
* @brief Take the first available semaphore
|
||||
*
|
||||
* Given a list of semaphore pointers, this routine will attempt to take one
|
||||
* of them, waiting up to a maximum of @a timeout ms to do so. The taken
|
||||
* semaphore is identified by @a sem (set to NULL on error).
|
||||
*
|
||||
* Be aware that the more semaphores specified in the group, the more stack
|
||||
* space is required by the waiting thread.
|
||||
*
|
||||
* @param sem_array Array of semaphore pointers terminated by a K_END entry
|
||||
* @param sem Identifies the semaphore that was taken
|
||||
* @param timeout Maximum number of milliseconds to wait
|
||||
*
|
||||
* @retval 0 A semaphore was successfully taken
|
||||
* @retval -EBUSY No semaphore was available (@a timeout = K_NO_WAIT)
|
||||
* @retval -EAGAIN Time out occurred while waiting for semaphore
|
||||
*/
|
||||
|
||||
extern int k_sem_group_take(struct k_sem *sem_array[], struct k_sem **sem,
|
||||
int32_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Give all the semaphores in the group
|
||||
*
|
||||
* This routine will give each semaphore in the array of semaphore pointers.
|
||||
*
|
||||
* @param sem_array Array of semaphore pointers terminated by a K_END entry
|
||||
*
|
||||
* @return N/A
|
||||
*/
|
||||
extern void k_sem_group_give(struct k_sem *sem_array[]);
|
||||
|
||||
/**
|
||||
* @brief Reset the count to zero on each semaphore in the array
|
||||
*
|
||||
* This routine resets the count of each semaphore in the group to zero.
|
||||
* Note that it does NOT have any impact on any thread that might have
|
||||
* been previously pending on any of the semaphores.
|
||||
*
|
||||
* @param sem_array Array of semaphore pointers terminated by a K_END entry
|
||||
*
|
||||
* @return N/A
|
||||
*/
|
||||
extern void k_sem_group_reset(struct k_sem *sem_array[]);
|
||||
#endif
|
||||
|
||||
#define K_SEM_INITIALIZER(obj, initial_count, count_limit) \
|
||||
{ \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue