Warning: This file is not a C or C++ file. It does not have highlighting.

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-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC___SUPPORT_THREADS_CALLONCE_H
10#define LLVM_LIBC_SRC___SUPPORT_THREADS_CALLONCE_H
11
12#include "src/__support/macros/config.h"
13#include "src/__support/macros/optimization.h" // LIBC_LIKELY
14
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
19#ifdef __linux__
20#include "src/__support/threads/linux/callonce.h"
21#else
22#error "callonce is not supported on this platform"
23#endif
24
25namespace LIBC_NAMESPACE_DECL {
26
27// Common definitions
28using CallOnceCallback = void(void);
29namespace callonce_impl {
30int callonce_slowpath(CallOnceFlag *flag, CallOnceCallback *callback);
31} // namespace callonce_impl
32
33LIBC_INLINE int callonce(CallOnceFlag *flag, CallOnceCallback *callback) {
34 if (LIBC_LIKELY(callonce_impl::callonce_fastpath(flag)))
35 return 0;
36
37 return callonce_impl::callonce_slowpath(flag, callback);
38}
39} // namespace LIBC_NAMESPACE_DECL
40
41#endif // LLVM_LIBC_SRC___SUPPORT_THREADS_CALLONCE_H
42

Warning: This file is not a C or C++ file. It does not have highlighting.

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of libc/src/__support/threads/callonce.h