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 | |
25 | namespace LIBC_NAMESPACE_DECL { |
26 | |
27 | // Common definitions |
28 | using CallOnceCallback = void(void); |
29 | namespace callonce_impl { |
30 | int callonce_slowpath(CallOnceFlag *flag, CallOnceCallback *callback); |
31 | } // namespace callonce_impl |
32 | |
33 | LIBC_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.