brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · 7b2a712 Raw
55 lines · c
1//===-- A platform independent abstraction layer for cond vars --*- C++ -*-===//2//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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_LIBC___SUPPORT_SRC_THREADS_LINUX_CNDVAR_H10#define LLVM_LIBC___SUPPORT_SRC_THREADS_LINUX_CNDVAR_H11 12#include "hdr/stdint_proxy.h" // uint32_t13#include "src/__support/macros/config.h"14#include "src/__support/threads/linux/futex_utils.h" // Futex15#include "src/__support/threads/linux/raw_mutex.h"   // RawMutex16#include "src/__support/threads/mutex.h"             // Mutex17 18namespace LIBC_NAMESPACE_DECL {19 20class CndVar {21  enum CndWaiterStatus : uint32_t {22    WS_Waiting = 0xE,23    WS_Signalled = 0x5,24  };25 26  struct CndWaiter {27    Futex futex_word = WS_Waiting;28    CndWaiter *next = nullptr;29  };30 31  CndWaiter *waitq_front;32  CndWaiter *waitq_back;33  RawMutex qmtx;34 35public:36  LIBC_INLINE static int init(CndVar *cv) {37    cv->waitq_front = cv->waitq_back = nullptr;38    RawMutex::init(&cv->qmtx);39    return 0;40  }41 42  LIBC_INLINE static void destroy(CndVar *cv) {43    cv->waitq_front = cv->waitq_back = nullptr;44  }45 46  // Returns 0 on success, -1 on error.47  int wait(Mutex *m);48  void notify_one();49  void broadcast();50};51 52} // namespace LIBC_NAMESPACE_DECL53 54#endif // LLVM_LIBC_SRC___SUPPORT_THREADS_LINUX_CNDVAR_H55