xref: /aosp_15_r20/external/llvm-libc/src/threads/linux/Futex.h (revision 71db0c75aadcf003ffe3238005f61d7618a3fead)
1*71db0c75SAndroid Build Coastguard Worker //===-- Linux futex related definitions -------------------------*- C++ -*-===//
2*71db0c75SAndroid Build Coastguard Worker //
3*71db0c75SAndroid Build Coastguard Worker // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*71db0c75SAndroid Build Coastguard Worker // See https://llvm.org/LICENSE.txt for license information.
5*71db0c75SAndroid Build Coastguard Worker // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*71db0c75SAndroid Build Coastguard Worker //
7*71db0c75SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
8*71db0c75SAndroid Build Coastguard Worker 
9*71db0c75SAndroid Build Coastguard Worker #ifndef LLVM_LIBC_SRC_THREADS_LINUX_FUTEX_H
10*71db0c75SAndroid Build Coastguard Worker #define LLVM_LIBC_SRC_THREADS_LINUX_FUTEX_H
11*71db0c75SAndroid Build Coastguard Worker 
12*71db0c75SAndroid Build Coastguard Worker #include "src/__support/macros/config.h"
13*71db0c75SAndroid Build Coastguard Worker #include "src/__support/macros/properties/architectures.h" // Architecture macros
14*71db0c75SAndroid Build Coastguard Worker 
15*71db0c75SAndroid Build Coastguard Worker namespace LIBC_NAMESPACE_DECL {
16*71db0c75SAndroid Build Coastguard Worker 
17*71db0c75SAndroid Build Coastguard Worker #if (defined(LIBC_TARGET_ARCH_IS_AARCH64) ||                                   \
18*71db0c75SAndroid Build Coastguard Worker      defined(LIBC_TARGET_ARCH_IS_X86_64))
19*71db0c75SAndroid Build Coastguard Worker // The futex data has to be exactly 4 bytes long. However, we use a uint type
20*71db0c75SAndroid Build Coastguard Worker // here as we do not want to use `uint32_t` type to match the public definitions
21*71db0c75SAndroid Build Coastguard Worker // of types which include a field for a futex word. With public definitions, we
22*71db0c75SAndroid Build Coastguard Worker // cannot include <stdint.h> so we stick to the `unsigned int` type for x86_64
23*71db0c75SAndroid Build Coastguard Worker // and aarch64
24*71db0c75SAndroid Build Coastguard Worker using FutexWordType = unsigned int;
25*71db0c75SAndroid Build Coastguard Worker static_assert(sizeof(FutexWordType) == 4,
26*71db0c75SAndroid Build Coastguard Worker               "Unexpected size of unsigned int type.");
27*71db0c75SAndroid Build Coastguard Worker #else
28*71db0c75SAndroid Build Coastguard Worker #error "Futex word base type not defined for the target architecture."
29*71db0c75SAndroid Build Coastguard Worker #endif
30*71db0c75SAndroid Build Coastguard Worker 
31*71db0c75SAndroid Build Coastguard Worker } // namespace LIBC_NAMESPACE_DECL
32*71db0c75SAndroid Build Coastguard Worker 
33*71db0c75SAndroid Build Coastguard Worker #endif // LLVM_LIBC_SRC_THREADS_LINUX_FUTEX_H
34