cesium-native 0.44.2
Loading...
Searching...
No Matches
ThreadPool.h
1#pragma once
2
3#include "Impl/ImmediateScheduler.h"
4#include "Impl/cesium-async++.h"
5
6#include <CesiumAsync/Library.h>
7
8#include <memory>
9
10namespace CesiumAsync {
11
19class CESIUMASYNC_API ThreadPool {
20public:
26 ThreadPool(int32_t numberOfThreads);
27
28private:
29 struct Scheduler {
30 Scheduler(int32_t numberOfThreads);
31 void schedule(async::task_run_handle t);
32
33 CesiumImpl::ImmediateScheduler<Scheduler> immediate{this};
34
35 async::threadpool_scheduler scheduler;
36 };
37
38 static auto createPreRun(ThreadPool::Scheduler* pScheduler) {
39 return
40 [pScheduler]() { ThreadPool::_scope = pScheduler->immediate.scope(); };
41 }
42
43 static auto createPostRun() noexcept {
44 return []() noexcept { ThreadPool::_scope.reset(); };
45 }
46
47 static thread_local CesiumImpl::ImmediateScheduler<Scheduler>::SchedulerScope
48 _scope;
49
50 std::shared_ptr<Scheduler> _pScheduler;
51
52 template <typename T> friend class Future;
53 template <typename T> friend class SharedFuture;
54 friend class AsyncSystem;
55};
56
57} // namespace CesiumAsync
A thread pool created by AsyncSystem::createThreadPool.
Definition ThreadPool.h:19
ThreadPool(int32_t numberOfThreads)
Creates a new thread pool with the given number of threads.
Classes that support asynchronous operations.