acme
Foundational cross-platform layer of the ca2 framework
Toggle main menu visibility
Loading...
Searching...
No Matches
tools.h
1
#pragma once
2
3
4
#include "acme/parallelization/task.h"
5
#include "synchronization_array.h"
6
#include "synchronous_lock.h"
8
#include "acme/platform/system.h"
9
10
11
class
task_tool
;
12
13
// item of *task_tool* associated with each *tool_task*
14
// of a *task_group*
15
class
task_tool_item
;
16
17
18
// group of *tool_task*(s) that work together
19
// to perform a *task_tool* operation/task
20
class
task_group
;
21
22
// a group of *tool_task*s on a *task_group*(s)
23
// acts on single *task_tool_item* of a *task_tool*
24
// to perform a operation/task.
25
class
CLASS_DECL_ACME tool_task :
26
virtual
public
::task
27
{
28
public
:
29
30
31
::collection::index m_iThread;
32
task_group
* m_pgroup;
33
task_tool
* m_ptool;
34
task_tool_item
* m_pitem;
35
::pointer<manual_reset_happening> m_pevStart;
36
::pointer<manual_reset_happening> m_pevReady;
37
void
* m_pdata;
38
::collection::index m_cCount;
39
::collection::index m_iIndex;
40
::collection::count m_iScan;
41
::collection::count m_iCount;
42
::procedure m_procedure;
43
::pointer<matter> m_pholdref;
44
45
46
tool_task();
47
48
49
virtual
void
initialize_tool_task(
::task_group
* pgroup);
50
51
52
virtual
void
run
()
override
;
53
54
55
bool
set_procedure(const ::procedure & procedure);
56
57
void
reset();
58
void
set_ready_to_start();
59
60
61
};
62
63
64
class
CLASS_DECL_ACME task_tool_item :
65
virtual
public
::matter
66
{
67
public
:
68
69
70
task_tool
* m_ptool;
71
tool_task
* m_ptask;
72
73
74
task_tool_item();
75
virtual
~task_tool_item();
76
77
78
virtual
void
run()
override
;
79
80
81
};
82
83
84
class
CLASS_DECL_ACME task_tool :
85
virtual
public
::matter
86
{
87
public
:
88
89
90
enum_task_tool m_etasktool;
91
task_group
* m_ptaskgroup;
92
93
94
HAVE_ARRAY_OF(
item
, m_itema,
task_tool_item
);
95
96
task_tool();
97
~task_tool()
override
;
98
99
};
100
101
102
class
CLASS_DECL_ACME task_group :
103
virtual
public
::matter
104
{
105
public
:
106
107
108
HAVE_ARRAY_OF(
task
, m_taska,
tool_task
);
109
110
synchronization_array
m_synchronizationa;
111
::collection::count m_cCount;
112
::collection::count m_cIteration;
113
::collection::count m_cSpan;
114
::enum_task_op m_etaskop;
115
::pointer<::task_tool> m_ptool;
116
::enum_priority m_epriority;
117
118
119
task_group(::matter * pmatter, ::enum_priority epriority);
120
~task_group()
override
;
121
122
123
124
125
::collection::count get_count()
const
{
return
m_taska.get_count(); }
126
bool
is_empty()
const
{
return
get_count() <= 0; }
127
bool
is_full()
const
{
return
m_cCount >= m_taska.get_count(); }
128
bool
fillable()
const
{
return
!is_full(); }
129
::collection::count get_span()
const
{
return
m_cSpan; }
130
bool
nok()
const
{
return
is_empty(); };
131
132
void
prepare(::enum_task_op eop, ::collection::count cIteration = 0);
133
virtual
void
set_ready_to_start();
134
::e_status
wait(const ::function <
bool
() > & functionShouldContinue = {})
override
;
135
virtual
void
process();
136
137
bool
add_procedure(const ::procedure & procedure);
138
139
140
void
select_tool(
task_tool
* ptool);
141
142
template
<
typename
PRED >
143
inline ::collection::count
fork_count_end
(
::property_object
* pparticle, ::collection::count iCount, PRED pred, ::collection::index iStart)
144
{
145
146
if
(iCount <= 0)
147
{
148
149
return
-1;
150
151
}
152
153
//auto psystem = ::apexacmesystem();
154
155
synchronous_lock
slGroup(system()->synchronization(), DEFAULT_SYNCHRONOUS_LOCK_SUFFIX);
156
158
159
if
(get_count() <= 1)
160
{
161
162
for
(::collection::index i = iStart; i < iCount; i++)
163
{
164
165
pred(i);
166
167
}
168
169
return
1;
170
171
}
172
173
prepare(::e_task_op_fork_count, iCount - iStart);
174
// {
175
//
176
// return -1;
177
//
178
// }
179
180
synchronization_array
ptra;
181
182
::collection::count iScan = maximum(1, minimum(iCount - iStart, task_count()));
183
184
for
(::collection::index iOrder = 0; iOrder < iScan; iOrder++)
185
{
186
187
throw ::exception(
todo
);
188
189
// ::pointer<predicate_holder_base>pusermessage = allocateø forking_count_predicate < PRED > (pparticle, iOrder, iOrder + iStart, iScan, iCount, pred);
190
//
191
// if (!add_predicate(pusermessage))
192
// {
193
//
194
// return -1;
195
//
196
// }
197
198
}
199
200
call();
201
// {
202
//
203
// return -1;
204
//
205
// }
206
207
return
iScan;
208
209
}
210
211
212
};
213
214
215
216
217
218
template
<
typename
PRED >
219
inline ::collection::count fork_count_end(
::particle
* pparticle, ::collection::count iCount, PRED pred, ::collection::index iStart = 0, ::enum_priority epriority = ::e_priority_none);
220
221
222
223
224
//::collection::count task_toolset::get_span() const
225
//{
226
// return m_ptasktools->get_span();
227
//}
228
229
//bool task_toolset::operator()()
230
//{
231
// return m_ptasktools->operator()();
232
//
233
//}
234
235
236
237
using
task_group_map = map_base < enum_priority, pointer_array < ::task_group > >;
238
using
task_tool_map = map_base < enum_task_tool, pointer_array < ::task_tool > >;
239
240
241
242
e_status
Definition
e_status.h:30
item
Definition
item.h:93
particle
Definition
particle.h:95
property_object
Definition
property_object.h:21
synchronization_array
Definition
synchronization_array.h:54
synchronous_lock
Definition
synchronous_lock.h:13
task_group
Definition
tools.h:104
task_group::fork_count_end
inline ::collection::count fork_count_end(::property_object *pparticle, ::collection::count iCount, PRED pred, ::collection::index iStart)
Definition
tools.h:143
task_tool_item
Definition
tools.h:66
task_tool
Definition
tools.h:86
task
Definition
task.h:117
todo
Definition
aaa_todo.h:6
tool_task
Definition
tools.h:27
tool_task::run
virtual void run() override
Definition
tools.cpp:326
parallelization
tools.h
Generated by
1.17.0