1 //===-- A platform independent abstraction layer for cond vars --*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC___SUPPORT_SRC_THREADS_LINUX_CNDVAR_H
10 #define LLVM_LIBC___SUPPORT_SRC_THREADS_LINUX_CNDVAR_H
12 #include "src/__support/macros/config.h"
13 #include "src/__support/threads/linux/futex_utils.h" // Futex
14 #include "src/__support/threads/linux/raw_mutex.h" // RawMutex
15 #include "src/__support/threads/mutex.h" // Mutex
17 #include <stdint.h> // uint32_t
19 namespace LIBC_NAMESPACE_DECL
{
22 enum CndWaiterStatus
: uint32_t {
28 Futex futex_word
= WS_Waiting
;
29 CndWaiter
*next
= nullptr;
32 CndWaiter
*waitq_front
;
33 CndWaiter
*waitq_back
;
37 LIBC_INLINE
static int init(CndVar
*cv
) {
38 cv
->waitq_front
= cv
->waitq_back
= nullptr;
39 RawMutex::init(&cv
->qmtx
);
43 LIBC_INLINE
static void destroy(CndVar
*cv
) {
44 cv
->waitq_front
= cv
->waitq_back
= nullptr;
47 // Returns 0 on success, -1 on error.
53 } // namespace LIBC_NAMESPACE_DECL
55 #endif // LLVM_LIBC_SRC___SUPPORT_THREADS_LINUX_CNDVAR_H