first commit for opensource
first commit for opensource
This commit is contained in:
97
kernel/core/include/tos_mutex.h
Normal file
97
kernel/core/include/tos_mutex.h
Normal file
@@ -0,0 +1,97 @@
|
||||
#ifndef _TOS_MUTEX_H_
|
||||
#define _TOS_MUTEX_H_
|
||||
|
||||
#if TOS_CFG_MUTEX_EN > 0u
|
||||
|
||||
typedef struct k_mutex_st {
|
||||
pend_obj_t pend_obj;
|
||||
k_nesting_t pend_nesting;
|
||||
k_task_t *owner;
|
||||
k_prio_t owner_orig_prio;
|
||||
k_list_t owner_list;
|
||||
} k_mutex_t;
|
||||
|
||||
/**
|
||||
* @brief Create a mutex.
|
||||
* create a mutex.
|
||||
*
|
||||
* @attention None
|
||||
*
|
||||
* @param[in] mutex pointer to the handler of the mutex.
|
||||
*
|
||||
* @return errcode
|
||||
* @retval #K_ERR_NONE return successfully.
|
||||
*/
|
||||
__API__ k_err_t tos_mutex_create(k_mutex_t *mutex);
|
||||
|
||||
/**
|
||||
* @brief Destroy a mutex.
|
||||
* destroy a mutex.
|
||||
*
|
||||
* @attention None
|
||||
*
|
||||
* @param[in] mutex pointer to the handler of the mutex.
|
||||
*
|
||||
* @return errcode
|
||||
* @retval #K_ERR_NONE return successfully.
|
||||
*/
|
||||
__API__ k_err_t tos_mutex_destroy(k_mutex_t *mutex);
|
||||
|
||||
/**
|
||||
* @brief Pend a mutex.
|
||||
* pend a mutex.
|
||||
*
|
||||
* @attention The task will keep blocked until the mutex is obtained or a timeout comes.
|
||||
*
|
||||
* @param[in] mutex pointer to the handler of the mutex.
|
||||
* @param[in] timeout how much time(in k_tick_t) we would like to wait.
|
||||
*
|
||||
* @return errcode
|
||||
* @retval #K_ERR_MUTEX_NESTING_OVERFLOW we are the owner of the mutex, and we are nesting pend too much on this mutex.
|
||||
* @retval #K_ERR_MUTEX_NESTING we are the owner of the mutex, and we are nesting pend on it.
|
||||
* @retval #K_ERR_PEND_NOWAIT we get nothing, and we don't wanna wait.
|
||||
* @retval #K_ERR_PEND_SCHED_LOCKED we can wait, but scheduler is locked.
|
||||
* @retval #K_ERR_PEND_TIMEOUT the time we wait is up, we get nothing.
|
||||
* @retval #K_ERR_PEND_DESTROY the mutex we are pending is destroyed.
|
||||
* @retval #K_ERR_NONE return successfully.
|
||||
*/
|
||||
__API__ k_err_t tos_mutex_pend_timed(k_mutex_t *mutex, k_tick_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Pend a mutex.
|
||||
* pend a mutex.
|
||||
*
|
||||
* @attention The task will keep blocked until the mutex is obtained.
|
||||
*
|
||||
* @param[in] mutex pointer to the handler of the mutex.
|
||||
*
|
||||
* @return errcode
|
||||
* @retval #K_ERR_MUTEX_NESTING_OVERFLOW we are the owner of the mutex, and we are nesting pend too much on this mutex.
|
||||
* @retval #K_ERR_MUTEX_NESTING we are the owner of the mutex, and we are nesting pend on it.
|
||||
* @retval #K_ERR_PEND_SCHED_LOCKED we can wait, but scheduler is locked.
|
||||
* @retval #K_ERR_PEND_DESTROY the mutex we are pending is destroyed.
|
||||
* @retval #K_ERR_NONE return successfully.
|
||||
*/
|
||||
__API__ k_err_t tos_mutex_pend(k_mutex_t *mutex);
|
||||
|
||||
/**
|
||||
* @brief Post a mutex.
|
||||
* post a mutex.
|
||||
*
|
||||
* @attention None
|
||||
*
|
||||
* @param[in] mutex pointer to the handler of the mutex.
|
||||
*
|
||||
* @return errcode
|
||||
* @retval #K_ERR_MUTEX_NOT_OWNER we are posting a mutex of which the owner is not us.
|
||||
* @retval #K_ERR_MUTEX_NESTING we are posting a mutex owned by us, and we are still in a nesting.
|
||||
* @retval #K_ERR_NONE return successfully.
|
||||
*/
|
||||
__API__ k_err_t tos_mutex_post(k_mutex_t *mutex);
|
||||
|
||||
__KERNEL__ void mutex_release(k_mutex_t *mutex);
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _TOS_MUTEX_H_ */
|
||||
|
Reference in New Issue
Block a user