summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src/futex.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2021-08-31 14:26:47 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2021-09-01 14:14:32 +0200
commitce8f31ced53a11ec27633239f871657fb2a2680b (patch)
treed31c949777d8003f9b1e1413ea66aedf5bb4893d /cpukit/score/src/futex.c
parentrtems: Fix partitions with RTEMS_MULIPROCESSING (diff)
downloadrtems-ce8f31ced53a11ec27633239f871657fb2a2680b.tar.bz2
score: Document Futex Handler
The behaviour of the futex operations is defined by Linux: https://man7.org/linux/man-pages/man2/futex.2.html Use EAGIN instead of EWOULDBLOCK to be in line with the Linux man page. These error numbers have the same value in Newlib. Using the same error numbers helps to avoid confusion. When you look at the history of the Linux man page you see that they replaced EWOULDBLOCK with EAGAIN over time. At the time of the RTEMS futex implementation they used EWOULDBLOCK.
Diffstat (limited to '')
-rw-r--r--cpukit/score/src/futex.c42
1 files changed, 40 insertions, 2 deletions
diff --git a/cpukit/score/src/futex.c b/cpukit/score/src/futex.c
index b65a843704..9bf4d8b37e 100644
--- a/cpukit/score/src/futex.c
+++ b/cpukit/score/src/futex.c
@@ -1,11 +1,12 @@
/**
* @file
*
- * @ingroup RTEMSScore
+ * @ingroup RTEMSScoreFutex
*
* @brief This source file contains the implementation of
* _Futex_Wait() and _Futex_Wake().
*/
+
/*
* Copyright (c) 2015, 2016 embedded brains GmbH. All rights reserved.
*
@@ -20,6 +21,18 @@
* http://www.rtems.org/license/LICENSE.
*/
+/**
+ * @defgroup RTEMSScoreFutex Futex Handler
+ *
+ * @ingroup RTEMSScore
+ *
+ * @brief This group contains the Futex Handler implementation.
+ *
+ * The behaviour of the futex operations is defined by Linux, see also:
+ *
+ * https://man7.org/linux/man-pages/man2/futex.2.html
+ */
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@@ -84,6 +97,22 @@ static void _Futex_Queue_release(
_ISR_Local_enable( level );
}
+/**
+ * @brief Performs the ``FUTEX_WAIT`` operation.
+ *
+ * @param[in, out] _futex is the futex object.
+ *
+ * @param[in] uaddr is the address to the futex state.
+ *
+ * @param val is the expected futex state value.
+ *
+ * @retval 0 Returns zero if the futex state is equal to the expected value.
+ * In this case the calling thread is enqueued on the thread queue of the
+ * futex object.
+ *
+ * @retval EAGAIN Returns EAGAIN if the futex state is not equal to the
+ * expected value.
+ */
int _Futex_Wait( struct _Futex_Control *_futex, int *uaddr, int val )
{
Futex_Control *futex;
@@ -113,7 +142,7 @@ int _Futex_Wait( struct _Futex_Control *_futex, int *uaddr, int val )
eno = 0;
} else {
_Futex_Queue_release( futex, level, &queue_context );
- eno = EWOULDBLOCK;
+ eno = EAGAIN;
}
return eno;
@@ -143,6 +172,15 @@ static Thread_Control *_Futex_Flush_filter(
return the_thread;
}
+/**
+ * @brief Performs the ``FUTEX_WAKE`` operation.
+ *
+ * @param[in, out] _futex is the futex object.
+ *
+ * @param count is the maximum count of threads to wake up.
+ *
+ * @return Returns the count of woken up threads.
+ */
int _Futex_Wake( struct _Futex_Control *_futex, int count )
{
Futex_Control *futex;