[rtsan] Remove mkfifoat interceptor (#116997)
[llvm-project.git] / libcxx / include / __coroutine / noop_coroutine_handle.h
blobda13d579604b55ca33d040617adfb09cab863681
1 //===----------------------------------------------------------------------===//
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 _LIBCPP___COROUTINE_NOOP_COROUTINE_HANDLE_H
10 #define _LIBCPP___COROUTINE_NOOP_COROUTINE_HANDLE_H
12 #include <__config>
13 #include <__coroutine/coroutine_handle.h>
15 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16 # pragma GCC system_header
17 #endif
19 #if _LIBCPP_STD_VER >= 20
21 _LIBCPP_BEGIN_NAMESPACE_STD
23 # if __has_builtin(__builtin_coro_noop) || defined(_LIBCPP_COMPILER_GCC)
25 // [coroutine.noop]
26 // [coroutine.promise.noop]
27 struct noop_coroutine_promise {};
29 // [coroutine.handle.noop]
30 template <>
31 struct _LIBCPP_TEMPLATE_VIS coroutine_handle<noop_coroutine_promise> {
32 public:
33 // [coroutine.handle.noop.conv], conversion
34 _LIBCPP_HIDE_FROM_ABI constexpr operator coroutine_handle<>() const noexcept {
35 return coroutine_handle<>::from_address(address());
38 // [coroutine.handle.noop.observers], observers
39 _LIBCPP_HIDE_FROM_ABI constexpr explicit operator bool() const noexcept { return true; }
40 _LIBCPP_HIDE_FROM_ABI constexpr bool done() const noexcept { return false; }
42 // [coroutine.handle.noop.resumption], resumption
43 _LIBCPP_HIDE_FROM_ABI constexpr void operator()() const noexcept {}
44 _LIBCPP_HIDE_FROM_ABI constexpr void resume() const noexcept {}
45 _LIBCPP_HIDE_FROM_ABI constexpr void destroy() const noexcept {}
47 // [coroutine.handle.noop.promise], promise access
48 _LIBCPP_HIDE_FROM_ABI noop_coroutine_promise& promise() const noexcept {
49 return *static_cast<noop_coroutine_promise*>(
50 __builtin_coro_promise(this->__handle_, alignof(noop_coroutine_promise), false));
53 // [coroutine.handle.noop.address], address
54 _LIBCPP_HIDE_FROM_ABI constexpr void* address() const noexcept { return __handle_; }
56 private:
57 _LIBCPP_HIDE_FROM_ABI friend coroutine_handle<noop_coroutine_promise> noop_coroutine() noexcept;
59 # if __has_builtin(__builtin_coro_noop)
60 _LIBCPP_HIDE_FROM_ABI coroutine_handle() noexcept { this->__handle_ = __builtin_coro_noop(); }
62 void* __handle_ = nullptr;
64 # elif defined(_LIBCPP_COMPILER_GCC)
65 // GCC doesn't implement __builtin_coro_noop().
66 // Construct the coroutine frame manually instead.
67 struct __noop_coroutine_frame_ty_ {
68 static void __dummy_resume_destroy_func() {}
70 void (*__resume_)() = __dummy_resume_destroy_func;
71 void (*__destroy_)() = __dummy_resume_destroy_func;
72 struct noop_coroutine_promise __promise_;
75 static __noop_coroutine_frame_ty_ __noop_coroutine_frame_;
77 void* __handle_ = &__noop_coroutine_frame_;
79 _LIBCPP_HIDE_FROM_ABI coroutine_handle() noexcept = default;
81 # endif // __has_builtin(__builtin_coro_noop)
84 using noop_coroutine_handle = coroutine_handle<noop_coroutine_promise>;
86 # if defined(_LIBCPP_COMPILER_GCC)
87 inline noop_coroutine_handle::__noop_coroutine_frame_ty_ noop_coroutine_handle::__noop_coroutine_frame_{};
88 # endif
90 // [coroutine.noop.coroutine]
91 inline _LIBCPP_HIDE_FROM_ABI noop_coroutine_handle noop_coroutine() noexcept { return noop_coroutine_handle(); }
93 # endif // __has_builtin(__builtin_coro_noop) || defined(_LIBCPP_COMPILER_GCC)
95 _LIBCPP_END_NAMESPACE_STD
97 #endif // __LIBCPP_STD_VER >= 20
99 #endif // _LIBCPP___COROUTINE_NOOP_COROUTINE_HANDLE_H