kernel: mutex: add error checking

k_mutex_unlock will now perform error checking and return on failures.

If the current thread does not own the mutex, we will now return -EPERM.
In the unlikely situation where we own a lock and the lock count is
zero, we assert. This is considered an undefined bahviour and should not
happen.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2019-05-04 10:18:13 -04:00
commit 86bb2d06d7
2 changed files with 42 additions and 14 deletions

View file

@ -3346,10 +3346,12 @@ struct k_mutex {
*
* @param mutex Address of the mutex.
*
* @return N/A
* @retval 0 Mutex object created
*
* @req K-MUTEX-002
*/
__syscall void k_mutex_init(struct k_mutex *mutex);
__syscall int k_mutex_init(struct k_mutex *mutex);
/**
* @brief Lock a mutex.
@ -3385,10 +3387,13 @@ __syscall int k_mutex_lock(struct k_mutex *mutex, s32_t timeout);
*
* @param mutex Address of the mutex.
*
* @return N/A
* @retval 0 Mutex unlocked.
* @retval -EPERM The current thread does not own the mutex
* @retval -EINVAL The mutex is not locked
*
* @req K-MUTEX-002
*/
__syscall void k_mutex_unlock(struct k_mutex *mutex);
__syscall int k_mutex_unlock(struct k_mutex *mutex);
/**
* @}