56 lines · c
1//===-- A platform independent abstraction layer for barriers --*- 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_BARRIER_H10#define LLVM_LIBC___SUPPORT_SRC_THREADS_LINUX_BARRIER_H11 12#include "hdr/pthread_macros.h"13#include "include/llvm-libc-types/pthread_barrier_t.h"14#include "include/llvm-libc-types/pthread_barrierattr_t.h"15#include "src/__support/threads/CndVar.h"16#include "src/__support/threads/mutex.h"17 18namespace LIBC_NAMESPACE_DECL {19 20// NOTE: if the size of this class changes, you must ensure that the size of21// pthread_barrier_t (found in include/llvm-libc/types/pthread_barrier_t.h) is22// the same size23class Barrier {24private:25 unsigned expected;26 unsigned waiting;27 bool blocking;28 CndVar entering;29 CndVar exiting;30 Mutex m;31 32public:33 static int init(Barrier *b, const pthread_barrierattr_t *attr,34 unsigned count);35 static int destroy(Barrier *b);36 int wait();37};38 39static_assert(sizeof(Barrier) <= sizeof(pthread_barrier_t),40 "The public pthread_barrier_t type cannot accommodate the "41 "internal barrier type.");42 43static_assert(alignof(Barrier) <= alignof(pthread_barrier_t),44 "The public pthread_barrier_t type has insufficient alignment "45 "for the internal barrier type.");46 47static_assert(sizeof(CndVar) <= 24,48 "CndVar size exceeds the size in __barrier_type.h");49 50static_assert(sizeof(Mutex) <= 24,51 "Mutex size exceeds the size in __barrier_type.h");52 53} // namespace LIBC_NAMESPACE_DECL54 55#endif // LLVM_LIBC___SUPPORT_SRC_THREADS_LINUX_BARRIER_H56