cesium-native  0.41.0
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 
9 namespace CesiumAsync {
10 
18 class CESIUMASYNC_API ThreadPool {
19 public:
20  ThreadPool(int32_t numberOfThreads);
21 
22 private:
23  struct Scheduler {
24  Scheduler(int32_t numberOfThreads);
25  void schedule(async::task_run_handle t);
26 
28 
29  async::threadpool_scheduler scheduler;
30  };
31 
32  static auto createPreRun(ThreadPool::Scheduler* pScheduler) {
33  return
34  [pScheduler]() { ThreadPool::_scope = pScheduler->immediate.scope(); };
35  }
36 
37  static auto createPostRun() noexcept {
38  return []() noexcept { ThreadPool::_scope.reset(); };
39  }
40 
42  _scope;
43 
44  std::shared_ptr<Scheduler> _pScheduler;
45 
46  template <typename T> friend class Future;
47  template <typename T> friend class SharedFuture;
48  friend class AsyncSystem;
49 };
50 
51 } // namespace CesiumAsync
A system for managing asynchronous requests and tasks.
Definition: AsyncSystem.h:36
A value that will be available in the future, as produced by AsyncSystem.
Definition: Future.h:29
A value that will be available in the future, as produced by AsyncSystem. Unlike Future,...
Definition: SharedFuture.h:31
A thread pool created by AsyncSystem::createThreadPool.
Definition: ThreadPool.h:18
Classes that support asynchronous operations.