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>
diff --git a/include/kernel.h b/include/kernel.h
index c16d583..1587b78 100644
--- a/include/kernel.h
+++ b/include/kernel.h
@@ -3346,10 +3346,12 @@
*
* @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 @@
*
* @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);
/**
* @}