1 //===-- Types related to the callonce function ----------------------------===//
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_SRC___SUPPORT_THREADS_CALLONCE_H
10 #define LLVM_LIBC_SRC___SUPPORT_THREADS_CALLONCE_H
12 #include "src/__support/macros/config.h"
13 #include "src/__support/macros/optimization.h" // LIBC_LIKELY
15 // Plaform specific routines, provides:
16 // - OnceFlag definition
17 // - callonce_impl::callonce_fastpath for fast path check
18 // - callonce_impl::callonce_slowpath for slow path execution
20 #include "src/__support/threads/linux/callonce.h"
22 #error "callonce is not supported on this platform"
25 namespace LIBC_NAMESPACE_DECL
{
28 using CallOnceCallback
= void(void);
29 namespace callonce_impl
{
30 int callonce_slowpath(CallOnceFlag
*flag
, CallOnceCallback
*callback
);
31 } // namespace callonce_impl
33 LIBC_INLINE
int callonce(CallOnceFlag
*flag
, CallOnceCallback
*callback
) {
34 if (LIBC_LIKELY(callonce_impl::callonce_fastpath(flag
)))
37 return callonce_impl::callonce_slowpath(flag
, callback
);
39 } // namespace LIBC_NAMESPACE_DECL
41 #endif // LLVM_LIBC_SRC___SUPPORT_THREADS_CALLONCE_H