OnixS C++ CME MDP Conflated UDP Handler 1.1.2
API documentation
Loading...
Searching...
No Matches
ThreadPool.h
Go to the documentation of this file.
1// Copyright Onix Solutions Limited [OnixS]. All rights reserved.
2//
3// This software owned by Onix Solutions Limited [OnixS] and is
4// protected by copyright law and international copyright treaties.
5//
6// Access to and use of the software is governed by the terms of the applicable
7// OnixS Software Services Agreement (the Agreement) and Customer end user license
8// agreements granting a non-assignable, non-transferable and non-exclusive license
9// to use the software for it's own data processing purposes under the terms defined
10// in the Agreement.
11//
12// Except as otherwise granted within the terms of the Agreement, copying or
13// reproduction of any part of this source code or associated reference material
14// to any other location for further reproduction or redistribution, and any
15// amendments to this copyright notice, are expressly prohibited.
16//
17// Any reproduction or redistribution for sale or hiring of the Software not in
18// accordance with the terms of the Agreement is a violation of copyright law.
19//
20
21#pragma once
22
23#include <vector>
24
28
30
33{
35 virtual void run() = 0;
36};
37
40
42typedef
45
48{
49 CpuIndices indices_;
50
51public:
54 {
55 }
56
59 const ThreadAffinity& other)
60 : indices_(other.indices_)
61 {
62 }
63
66 {
67 }
68
70 operator bool() const
71 {
72 return indices_.empty();
73 }
74
76 const CpuIndices& cpus() const
77 {
78 return indices_;
79 }
80
83 {
84 return indices_;
85 }
86};
87
89ONIXS_CONFLATEDUDP_EXPORTED
90void
92 std::string&,
93 const ThreadAffinity&);
94
96inline
97std::string
99 const ThreadAffinity& affinity)
100{
101 std::string str;
102
103 toStr(str, affinity);
104
105 return str;
106}
107
108//
109
111(
112 TaskRunner
113);
114
117{
118 typedef
119 std::vector<TaskRunner*>
120 Tasks;
121
122 Tasks tasks_;
123
124 const size_t capacity_;
125
126 ThreadPool(
127 const ThreadPool&);
128
129 ThreadPool&
130 operator =(
131 const ThreadPool&);
132
133public:
135 explicit
137 size_t capacity)
138 : capacity_(capacity)
139 {
140 tasks_.reserve(capacity);
141 }
142
147 {
148 joinAll();
149 }
150
153 size_t size() const
154 {
155 return tasks_.size();
156 }
157
159 size_t capacity() const
160 {
161 return capacity_;
162 }
163
168 void
170 Task& task)
171 {
172 start(
173 task,
175 }
176
184 void
186 Task&,
187 const ThreadAffinity&);
188
191 void
193};
194
200{
201 ThreadAffinity affinity_;
202 UInt32 size_;
203
204public:
208 : affinity_()
209 , size_(1)
210 {
211 }
212
215 {
216 }
217
223 const
225 affinity() const
226 {
227 return affinity_;
228 }
229
236 {
237 return affinity_;
238 }
239
243 UInt32
244 size() const
245 {
246 return size_;
247 }
248
250 void
252 UInt32 value)
253 {
254 size_ = value;
255 }
256};
257
259ONIXS_CONFLATEDUDP_EXPORTED
260void
262 std::string&,
263 const
265
267inline
268std::string
270 const
271 ThreadPoolSettings& settings)
272{
273 std::string str;
274
275 toStr(str, settings);
276
277 return str;
278}
279
#define ONIXS_CONFLATEDUDP_LTWT_EXPORTED
Definition Bootstrap.h:103
#define ONIXS_CONFLATEDUDP_LTWT_CLASS
Definition Bootstrap.h:95
#define ONIXS_CONFLATEDUDP_EXPORTED_STRUCT
Definition Bootstrap.h:59
#define ONIXS_CONFLATEDUDP_NAMESPACE_END
Definition Bootstrap.h:157
#define ONIXS_CONFLATEDUDP_INTERNAL_CLASS_DECL(typeName)
Definition Bootstrap.h:63
#define ONIXS_CONFLATEDUDP_NAMESPACE_BEGIN
Definition Bootstrap.h:153
Represents a set of CPU indices.
Definition ThreadPool.h:48
ThreadAffinity()
Initializes the empty set.
Definition ThreadPool.h:53
~ThreadAffinity()
Utilizes internal resources.
Definition ThreadPool.h:65
ThreadAffinity(const ThreadAffinity &other)
Initializes as a copy of the other set.
Definition ThreadPool.h:58
CpuIndices & cpus()
Collection of the CPU indices.
Definition ThreadPool.h:82
const CpuIndices & cpus() const
Read-only access to the indices.
Definition ThreadPool.h:76
const ThreadAffinity & affinity() const
Definition ThreadPool.h:225
void size(UInt32 value)
Defines the number of working threads in the pool.
Definition ThreadPool.h:251
ONIXS_CONFLATEDUDP_EXPORTED void joinAll()
Blocks until all threads accomplish their tasks.
size_t capacity() const
Maximal number of threads maintained by the given pool.
Definition ThreadPool.h:159
ONIXS_CONFLATEDUDP_EXPORTED void start(Task &, const ThreadAffinity &)
ThreadPool(size_t capacity)
Initializes the pool of the requested capacity.
Definition ThreadPool.h:136
ONIXS_CONFLATEDUDP_EXPORTED void toStr(std::string &, BookState::Enum)
Serializes book state value into a string.
Int32 Int32
int32.
Definition Fields.h:69
UInt32 UInt32
uInt32.
Definition Fields.h:261
TinySet< CpuIndex > CpuIndices
Alias for collection of CPU indices.
Definition ThreadPool.h:44
Int32 CpuIndex
Zero-based index of CPU.
Definition ThreadPool.h:39
Defines an abstraction for a task.
Definition ThreadPool.h:33
virtual void run()=0
Executes the given task.