123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- #ifndef CERES_INTERNAL_THREAD_POOL_H_
- #define CERES_INTERNAL_THREAD_POOL_H_
- #include <functional>
- #include <mutex>
- #include <thread>
- #include <vector>
- #include "ceres/concurrent_queue.h"
- #include "ceres/internal/export.h"
- namespace ceres::internal {
- class CERES_NO_EXPORT ThreadPool {
- public:
-
- static int MaxNumThreadsAvailable();
-
-
-
-
-
- ThreadPool();
-
-
- explicit ThreadPool(int num_threads);
-
-
- ~ThreadPool();
-
-
-
-
-
-
-
-
-
- void Resize(int num_threads);
-
-
-
-
-
- void AddTask(const std::function<void()>& func);
-
- int Size();
- private:
-
-
- void ThreadMainLoop();
-
-
- void Stop();
-
-
- ConcurrentQueue<std::function<void()>> task_queue_;
- std::vector<std::thread> thread_pool_;
- std::mutex thread_pool_mutex_;
- };
- }
- #endif
|