nndeploy C++ API  0.2.0
nndeploy C++ API
parallel_for_api_default.h
Go to the documentation of this file.
1 
2 #ifndef _NNDEPLOY_THREAD_POOL_PARALLEL_FOR_API_DEFAULT_H_
3 #define _NNDEPLOY_THREAD_POOL_PARALLEL_FOR_API_DEFAULT_H_
4 
7 
8 namespace nndeploy {
9 namespace thread_pool {
10 
11 class ParallelJob;
12 class WorkerThread;
13 
14 class ParallelPool {
15  public:
17  static ParallelPool *instance = new ParallelPool;
18  return *instance;
19  }
20 
22 
24 
25  void setThreadNum(int num);
26 
27  int getThreadNum() const;
28 
29  void parallelFor(const base::Range &range, const ParallelLoopBody &body,
30  double nstripes);
31 
32  void stop() { setWorkThreads(0); }
33 
34  private:
35  bool setWorkThreads(int num);
36 
37  public:
38  std::mutex mutex_notify_;
39  std::condition_variable job_complete_;
40 
41  private:
42  std::mutex pool_mutex_;
43  int thread_num_;
44  std::vector<std::shared_ptr<WorkerThread>> work_threads_;
45  std::shared_ptr<ParallelJob> job_ = nullptr;
46  const int active_wait_;
47 };
48 
50  public:
51  ParallelForApiDefault() = default;
52 
53  virtual ~ParallelForApiDefault() = default;
54 
55  virtual void setThreadNum(int num);
56 
57  virtual int getThreadNum();
58 
59  virtual int parallelFor(const base::Range &range,
60  const ParallelLoopBody &body, double nstripes = -1.0);
61 };
62 
63 } // namespace thread_pool
64 } // namespace nndeploy
65 
66 #endif /* _NNDEPLOY_THREAD_POOL_PARALLEL_FOR_API_H_ */
Template class specifying a continuous subsequence (slice) of a sequence. The class is used to specif...
Definition: type.h:403
virtual int parallelFor(const base::Range &range, const ParallelLoopBody &body, double nstripes=-1.0)
Base class for parallel data processors.
Definition: parallel.h:25
void parallelFor(const base::Range &range, const ParallelLoopBody &body, double nstripes)