Skip to content

Commit

Permalink
doc: Fix sys_mutex and futex missing documentation
Browse files Browse the repository at this point in the history
Adds API reference for sys_mutex and futex to mutex documentation,
adds Doxygen documentation for SYS_MUTEX_DEFINE and fixes typo in
futex documentation.

Fixes zephyrproject-rtos#27829

Signed-off-by: Lauren Murphy <[email protected]>
  • Loading branch information
laurenmurphyx64 committed Feb 2, 2021
1 parent 4c8760b commit fb3719e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
22 changes: 22 additions & 0 deletions doc/reference/kernel/synchronization/mutexes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,25 @@ API Reference

.. doxygengroup:: mutex_apis
:project: Zephyr

Futex API Reference
*********************************

k_futex is a lightweight mutual exclusion primitive designed to minimize
kernel involvement. Uncontended operation relies only on atomic access
to shared memory. k_futex are tracked as kernel objects and can live in
user memory so that any access bypasses the kernel object permission
management mechanism.

.. doxygengroup:: futex_apis
:project: Zephyr

User Mode Mutex API Reference
*********************************

sys_mutex behaves almost exactly like k_mutex, with the added advantage
that a sys_mutex instance can reside in user memory. When user mode isn't
enabled, sys_mutex behaves like k_mutex.

.. doxygengroup:: user_mutex_apis
:project: Zephyr
4 changes: 2 additions & 2 deletions include/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -1945,8 +1945,8 @@ static inline void *z_impl_k_queue_peek_tail(struct k_queue *queue)
* A k_futex is a lightweight mutual exclusion primitive designed
* to minimize kernel involvement. Uncontended operation relies
* only on atomic access to shared memory. k_futex are tracked as
* kernel objects and can live in user memory so any access bypass
* the kernel object permission management mechanism.
* kernel objects and can live in user memory so that any access
* bypasses the kernel object permission management mechanism.
*/
struct k_futex {
atomic_t val;
Expand Down
21 changes: 21 additions & 0 deletions include/sys/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,23 @@ struct sys_mutex {
atomic_t val;
};

/**
* @defgroup user_mutex_apis User mode mutex APIs
* @ingroup kernel_apis
* @{
*/

/**
* @brief Statically define and initialize a sys_mutex
*
* The mutex can be accessed outside the module where it is defined using:
*
* @code extern struct sys_mutex <name>; @endcode
*
* Route this to memory domains using K_APP_DMEM().
*
* @param name Name of the mutex.
*/
#define SYS_MUTEX_DEFINE(name) \
struct sys_mutex name

Expand Down Expand Up @@ -153,6 +170,10 @@ static inline int sys_mutex_unlock(struct sys_mutex *mutex)

#endif /* CONFIG_USERSPACE */

/**
* @}
*/

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit fb3719e

Please sign in to comment.