3#include "cesium-async++.h"
5#include <CesiumUtility/Assert.h>
7#include <spdlog/spdlog.h>
14template <
typename TScheduler>
class ImmediateScheduler {
16 explicit ImmediateScheduler(TScheduler* pScheduler) noexcept
17 : _pScheduler(pScheduler) {}
19 void schedule(async::task_run_handle t) {
21 std::vector<TScheduler*>& inSuitable =
22 ImmediateScheduler<TScheduler>::getSchedulersCurrentlyDispatching();
23 if (std::find(inSuitable.begin(), inSuitable.end(), this->_pScheduler) !=
29 this->_pScheduler->schedule(std::move(t));
33 class SchedulerScope {
35 SchedulerScope(TScheduler* pScheduler =
nullptr) : _pScheduler(pScheduler) {
36 if (this->_pScheduler) {
37 std::vector<TScheduler*>& inSuitable =
38 ImmediateScheduler<TScheduler>::getSchedulersCurrentlyDispatching();
39 inSuitable.push_back(this->_pScheduler);
43 ~SchedulerScope() noexcept { this->reset(); }
45 SchedulerScope(SchedulerScope&& rhs) noexcept
46 : _pScheduler(rhs._pScheduler) {
47 rhs._pScheduler =
nullptr;
50 SchedulerScope& operator=(SchedulerScope&& rhs)
noexcept {
51 std::swap(this->_pScheduler, rhs._pScheduler);
55 void reset() noexcept {
56 if (this->_pScheduler) {
57 std::vector<TScheduler*>& inSuitable =
58 ImmediateScheduler<TScheduler>::getSchedulersCurrentlyDispatching();
59 CESIUM_ASSERT(!inSuitable.empty());
60 CESIUM_ASSERT(inSuitable.back() == this->_pScheduler);
61 inSuitable.pop_back();
63 this->_pScheduler =
nullptr;
67 SchedulerScope(
const SchedulerScope&) =
delete;
68 SchedulerScope& operator=(
const SchedulerScope&) =
delete;
71 TScheduler* _pScheduler;
74 SchedulerScope scope() {
return SchedulerScope(this->_pScheduler); }
77 TScheduler* _pScheduler;
82 static std::vector<TScheduler*>&
83 getSchedulersCurrentlyDispatching() noexcept {
89 static thread_local std::vector<TScheduler*> schedulersCurrentlyDispatching;
90 return schedulersCurrentlyDispatching;
Classes that support asynchronous operations.