nndeploy C++ API
0.2.0
nndeploy C++ API
framework
include
nndeploy
thread_pool
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
5
#include "
nndeploy/thread_pool/parallel.h
"
6
#include "
nndeploy/thread_pool/parallel_for_api.h
"
7
8
namespace
nndeploy
{
9
namespace
thread_pool {
10
11
class
ParallelJob;
12
class
WorkerThread;
13
14
class
ParallelPool
{
15
public
:
16
static
ParallelPool
&
getInstance
() {
17
static
ParallelPool
*instance =
new
ParallelPool
;
18
return
*instance;
19
}
20
21
ParallelPool
();
22
23
~ParallelPool
();
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
49
class
ParallelForApiDefault
:
public
ParallelForApi
{
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_ */
nndeploy::base::Range
Template class specifying a continuous subsequence (slice) of a sequence. The class is used to specif...
Definition:
type.h:403
nndeploy::thread_pool::ParallelForApiDefault
Definition:
parallel_for_api_default.h:49
nndeploy::thread_pool::ParallelForApiDefault::ParallelForApiDefault
ParallelForApiDefault()=default
nndeploy::thread_pool::ParallelForApiDefault::~ParallelForApiDefault
virtual ~ParallelForApiDefault()=default
nndeploy::thread_pool::ParallelForApiDefault::getThreadNum
virtual int getThreadNum()
nndeploy::thread_pool::ParallelForApiDefault::setThreadNum
virtual void setThreadNum(int num)
nndeploy::thread_pool::ParallelForApiDefault::parallelFor
virtual int parallelFor(const base::Range &range, const ParallelLoopBody &body, double nstripes=-1.0)
nndeploy::thread_pool::ParallelForApi
Definition:
parallel_for_api.h:9
nndeploy::thread_pool::ParallelLoopBody
Base class for parallel data processors.
Definition:
parallel.h:25
nndeploy::thread_pool::ParallelPool
Definition:
parallel_for_api_default.h:14
nndeploy::thread_pool::ParallelPool::mutex_notify_
std::mutex mutex_notify_
Definition:
parallel_for_api_default.h:38
nndeploy::thread_pool::ParallelPool::getThreadNum
int getThreadNum() const
nndeploy::thread_pool::ParallelPool::setThreadNum
void setThreadNum(int num)
nndeploy::thread_pool::ParallelPool::job_complete_
std::condition_variable job_complete_
Definition:
parallel_for_api_default.h:39
nndeploy::thread_pool::ParallelPool::parallelFor
void parallelFor(const base::Range &range, const ParallelLoopBody &body, double nstripes)
nndeploy::thread_pool::ParallelPool::getInstance
static ParallelPool & getInstance()
Definition:
parallel_for_api_default.h:16
nndeploy::thread_pool::ParallelPool::~ParallelPool
~ParallelPool()
nndeploy::thread_pool::ParallelPool::ParallelPool
ParallelPool()
nndeploy::thread_pool::ParallelPool::stop
void stop()
Definition:
parallel_for_api_default.h:32
nndeploy
Definition:
common.h:10
parallel.h
parallel_for_api.h
Generated by
1.9.1