36 lines · c
1//===-- Types related to the callonce function ----------------------------===//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_SRC___SUPPORT_THREADS_CALLONCE_H10#define LLVM_LIBC_SRC___SUPPORT_THREADS_CALLONCE_H11 12#include "src/__support/macros/config.h"13#include "src/__support/macros/optimization.h" // LIBC_LIKELY14 15// Plaform specific routines, provides:16// - OnceFlag definition17// - callonce_impl::callonce_fastpath for fast path check18// - callonce_impl::callonce_slowpath for slow path execution19#ifdef __linux__20#include "src/__support/threads/linux/callonce.h"21#else22#error "callonce is not supported on this platform"23#endif24 25namespace LIBC_NAMESPACE_DECL {26template <class CallOnceCallback>27LIBC_INLINE int callonce(CallOnceFlag *flag, CallOnceCallback callback) {28 if (LIBC_LIKELY(callonce_impl::callonce_fastpath(flag)))29 return 0;30 31 return callonce_impl::callonce_slowpath(flag, callback);32}33} // namespace LIBC_NAMESPACE_DECL34 35#endif // LLVM_LIBC_SRC___SUPPORT_THREADS_CALLONCE_H36