LeechCraft 0.6.70-18808-g3467692359
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
defaulthandlers.h
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#pragma once
10
11#include <atomic>
12#include <coroutine>
13#include <stdexcept>
14
15namespace LC::Util::detail
16{
17 template<typename E>
18 concept IsAwaiterHandler = E::IsAwaiterHandler;
19
20 template<typename...>
22 {
23 std::atomic<std::coroutine_handle<>> Continuation_ {};
24
25 struct DoubleAwaitError : std::logic_error
26 {
28 : std::logic_error { "double await" }
29 {
30 }
31 };
32
33 void AddAwaiter (std::coroutine_handle<> handle)
34 {
35 if (this->Continuation_.exchange (handle))
36 throw DoubleAwaitError {};
37 }
38
39 void RemoveAwaiter (std::coroutine_handle<>) noexcept
40 {
41 this->Continuation_.exchange ({});
42 }
43
44 auto GetAwaiters (this auto&& self) noexcept
45 {
46 return self.Continuation_.exchange ({});
47 }
48 };
49
50 template<typename... Extensions>
51 requires (IsAwaiterHandler<Extensions> || ...)
52 struct DefaultAwaiterHandler<Extensions...> {};
53
54
55 template<typename E>
56 concept IsLockingHandler = E::IsLockingHandler;
57
58 template<typename...>
60 {
61 static void lock () {}
62 static void unlock () {}
63 };
64
65 template<typename... Extensions>
66 requires (IsLockingHandler<Extensions> || ...)
67 struct DefaultLockingHandler<Extensions...> {};
68
69
70 template<typename E>
71 concept IsResumeValueHandler = E::IsResumeValueHandler;
72
73 template<typename...>
75 {
76 template<typename R>
77 static R&& ResumeValue (R& ret) noexcept
78 {
79 return std::move (ret);
80 }
81 };
82
83 template<typename... Extensions>
84 requires (IsResumeValueHandler<Extensions> || ...)
85 struct DefaultResumeValueHandler<Extensions...> {};
86}
auto GetAwaiters(this auto &&self) noexcept
void RemoveAwaiter(std::coroutine_handle<>) noexcept
void AddAwaiter(std::coroutine_handle<> handle)
std::atomic< std::coroutine_handle<> > Continuation_
static R && ResumeValue(R &ret) noexcept