diff options
Diffstat (limited to 'cpukit/score/src/futex.c')
-rw-r--r-- | cpukit/score/src/futex.c | 73 |
1 files changed, 62 insertions, 11 deletions
diff --git a/cpukit/score/src/futex.c b/cpukit/score/src/futex.c index b65a843704..e158b61238 100644 --- a/cpukit/score/src/futex.c +++ b/cpukit/score/src/futex.c @@ -1,23 +1,49 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @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. + * Copyright (C) 2015, 2016 embedded brains GmbH & Co. KG + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @defgroup RTEMSScoreFutex Futex Handler + * + * @ingroup RTEMSScore + * + * @brief This group contains the Futex Handler implementation. * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * <rtems@embedded-brains.de> + * The behaviour of the futex operations is defined by Linux, see also: * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. + * https://man7.org/linux/man-pages/man2/futex.2.html */ #ifdef HAVE_CONFIG_H @@ -84,6 +110,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 +155,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 +185,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; |