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