CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Win32RunLoop.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
11
14
15#include <asio/execution.hpp>
16
17namespace CeresEngine {
18
20 class Win32RunLoop : public RunLoop {
21 public:
24 class Executor {
25 friend class Win32RunLoop;
26
27 private:
30
32 ExecutorBlocking mBlockingProperty = ExecutorBlocking::never;
33
34 private:
41
42 public:
43 Executor(const Executor&) = default;
44 Executor& operator=(const Executor&) = default;
45 Executor(Executor&&) = default;
47
48 public:
51
57
63
64 public:
66 [[nodiscard]] friend bool operator==(const Executor&, const Executor&) noexcept { return true; }
67
69 [[nodiscard]] friend bool operator!=(const Executor&, const Executor&) noexcept { return false; }
70
71 private:
72 friend struct asio_query_fn::impl;
73 friend struct asio::execution::detail::context_t<0>;
74 friend struct asio::execution::detail::mapping_t<0>;
75 friend struct asio::execution::detail::blocking_t<0>;
76 friend struct asio::execution::detail::relationship_t<0>;
77 friend struct asio::execution::detail::outstanding_work_t<0>;
78 friend struct asio::execution::detail::bulk_guarantee_t<0>;
79 friend struct asio::execution::detail::occupancy_t<0>;
80
83
85 [[nodiscard]] static constexpr ExecutorMapping query(ExecutorMapping) noexcept { return ExecutorMapping::other; }
86
89
91 [[nodiscard]] static constexpr ExecutorRelationship query(ExecutorRelationship) noexcept { return ExecutorRelationship::continuation; }
92
94 [[nodiscard]] static constexpr ExecutorOutstandingWork query(ExecutorOutstandingWork) noexcept { return ExecutorOutstandingWork::tracked; }
95
97 [[nodiscard]] static constexpr ExecutorBulkGuarantee query(ExecutorBulkGuarantee) noexcept { return ExecutorBulkGuarantee::sequenced; }
98
101 [[nodiscard]] std::size_t query(ExecutorOccupancy) const noexcept { return 1; }
102
104 template<typename OtherAllocator> [[nodiscard]] std::allocator<void> query(ExecutorAllocator<OtherAllocator>) const noexcept {
105 static std::allocator<void> allocator;
106 return allocator;
107 }
108
110 [[nodiscard]] std::allocator<void> query(ExecutorAllocator<void>) const noexcept {
111 static std::allocator<void> allocator;
112 return allocator;
113 }
114
115 private: // Prefer
117 friend struct asio_prefer_fn::impl;
118
130
131 private:
133
135 template<typename Function> void execute(ASIO_MOVE_ARG(Function) f) const {
136 CE_ASSERT(mExecutionContext != nullptr);
138 }
139 };
140
141 private:
144
145 public:
148
151
152 public:
155
157 void stop() final;
158
160 void run() final;
161
162 private: // Executor interface
165
168
172
173 public: // ASIO ExecutionContext concept
176
179 };
180
181} // namespace CeresEngine
#define CE_ASSERT(...)
Definition Macros.hpp:323
An ASIO execution context that wraps the operating system run loop.
Definition RunLoop.hpp:17
An executor object that dispatches calls to the CoreFoundation CFRunLoop.
Definition Win32RunLoop.hpp:24
std::allocator< void > query(ExecutorAllocator< OtherAllocator >) const noexcept
Query the current value of the allocator property.
Definition Win32RunLoop.hpp:104
static constexpr ExecutorMapping query(ExecutorMapping) noexcept
Query the current value of the mapping property.
Definition Win32RunLoop.hpp:85
Executor require(const ExecutorBlocking blocking) const
Obtain an executor with the given blocking property.
Definition Win32RunLoop.hpp:129
friend struct asio_prefer_fn::impl
Definition Win32RunLoop.hpp:117
std::size_t query(ExecutorOccupancy) const noexcept
Query the occupancy (recommended number of work items) for the system context.
Definition Win32RunLoop.hpp:101
Executor(Win32RunLoop *const executionContext, const ExecutorBlocking blockingProperty=ExecutorBlocking::never)
Creates a new Executor instance.
Definition Win32RunLoop.hpp:39
static constexpr ExecutorOutstandingWork query(ExecutorOutstandingWork) noexcept
Query the current value of the outstanding_work property.
Definition Win32RunLoop.hpp:94
Executor & operator=(const Executor &)=default
Win32RunLoop * mExecutionContext
The execution context that the executor will use.
Definition Win32RunLoop.hpp:29
Win32RunLoop & context() const noexcept
Obtain the underlying execution context.
Definition Win32RunLoop.hpp:50
Executor & operator=(Executor &&)=default
ExecutorBlocking query(ExecutorBlocking) const noexcept
Query the current value of the blocking property.
Definition Win32RunLoop.hpp:88
static constexpr ExecutorBulkGuarantee query(ExecutorBulkGuarantee) noexcept
Query the current value of the bulk_guarantee property.
Definition Win32RunLoop.hpp:97
friend struct asio_execution_execute_fn::impl
Definition Win32RunLoop.hpp:132
void on_work_finished() const noexcept
Inform the executor that some work is no longer outstanding.
Definition Win32RunLoop.hpp:59
friend struct asio_require_fn::impl
Definition Win32RunLoop.hpp:116
friend bool operator!=(const Executor &, const Executor &) noexcept
Compare two executors for inequality.
Definition Win32RunLoop.hpp:69
void on_work_started() const noexcept
Inform the executor that it has some outstanding work to do.
Definition Win32RunLoop.hpp:53
friend bool operator==(const Executor &, const Executor &) noexcept
Compare two executors for equality.
Definition Win32RunLoop.hpp:66
static constexpr ExecutorRelationship query(ExecutorRelationship) noexcept
Query the current value of the relationship property.
Definition Win32RunLoop.hpp:91
std::allocator< void > query(ExecutorAllocator< void >) const noexcept
Query the current value of the allocator property.
Definition Win32RunLoop.hpp:110
void execute(ASIO_MOVE_ARG(Function) f) const
Execution function.
Definition Win32RunLoop.hpp:135
friend struct asio_query_fn::impl
Definition Win32RunLoop.hpp:72
Executor(const Executor &)=default
Win32RunLoop & query(ExecutorExecutionContext) const noexcept
Query the current value of the context property.
Definition Win32RunLoop.hpp:82
ExecutorBlocking mBlockingProperty
A property that customizes the blocking behavior of the executor.
Definition Win32RunLoop.hpp:32
Abstracts a CoreFoundation CFRunLoop as an ASIO execution context.
Definition Win32RunLoop.hpp:20
executor_type get_executor() noexcept
Returns an executor that run execute scheduled commands on the context.
Definition Win32RunLoop.hpp:178
DWORD mThreadID
The Win32 thread ID.
Definition Win32RunLoop.hpp:143
void onWorkFinished() noexcept
Inform the executor that some work is no longer outstanding.
AnyExecutor getExecutor() noexcept final
Returns an executor that run execute scheduled commands on the context.
void run() final
Starts running the run loop.
void onWorkStarted() noexcept
Inform the executor that it has some outstanding work to do.
void schedule(UniqueFunction< void()> function, ExecutorBlocking blockingProperty)
Schedules a new function to be run in the run loop.
void stop() final
Stops the execution of the run loop.
Win32RunLoop() noexcept
Creates a new win32 run loop instance for the current thread.
Definition Application.hpp:19
asio::execution::context_t ExecutorExecutionContext
Definition ExecutionContext.hpp:208
asio::execution::relationship_t ExecutorRelationship
Definition ExecutionContext.hpp:215
asio::execution::mapping_t ExecutorMapping
Definition ExecutionContext.hpp:211
asio::execution::bulk_guarantee_t ExecutorBulkGuarantee
Definition ExecutionContext.hpp:214
asio::execution::occupancy_t ExecutorOccupancy
Definition ExecutionContext.hpp:212
FunctionBase< true, true, fu2::capacity_default, true, false, Signatures... > Function
An owning copyable function wrapper for arbitrary callable types.
Definition Function.hpp:54
asio::execution::allocator_t< T > ExecutorAllocator
Definition ExecutionContext.hpp:216
asio::execution::blocking_t ExecutorBlocking
Definition ExecutionContext.hpp:210
asio::execution::outstanding_work_t ExecutorOutstandingWork
Definition ExecutionContext.hpp:213
ASIO_MOVE_ARG(CompletionToken) token)
Definition IdleService.hpp:42
FunctionBase< true, false, fu2::capacity_default, true, false, Signatures... > UniqueFunction
An owning non copyable function wrapper for arbitrary callable types.
Definition Function.hpp:59
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25