Revert "[libc] Breakup freelist_malloc into separate files" (#119749)
[llvm-project.git] / libc / src / __support / threads / callonce.h
blob5392722045c94bf14147899a7fc12221e54240b2
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 //===----------------------------------------------------------------------===//
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
19 #ifdef __linux__
20 #include "src/__support/threads/linux/callonce.h"
21 #else
22 #error "callonce is not supported on this platform"
23 #endif
25 namespace LIBC_NAMESPACE_DECL {
27 // Common definitions
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)))
35 return 0;
37 return callonce_impl::callonce_slowpath(flag, callback);
39 } // namespace LIBC_NAMESPACE_DECL
41 #endif // LLVM_LIBC_SRC___SUPPORT_THREADS_CALLONCE_H