2 //=============================================================================
3 // File : DataFlowBase_FiniteStateMachine.cxx
5 // Author : Jean Rahuel, CEA
8 //=============================================================================
15 #include "DataFlowExecutor_FiniteStateMachine.hxx"
17 void * start_function( void *p ) ;
20 #define VoidState SUPERV::VoidState
21 #define ToSuspendStartState SUPERV::ToSuspendStartState
22 #define ToSuspendState SUPERV::ToSuspendState
23 #define ToSuspendDoneState SUPERV::ToSuspendDoneState
24 #define ToKillState SUPERV::ToKillState
25 #define ToKillDoneState SUPERV::ToKillDoneState
26 #define ToStopState SUPERV::ToStopState
29 #define UnKnownState SUPERV::UnKnownState
30 #define DataUndefState SUPERV::DataUndefState
31 #define DataWaitingState SUPERV::DataWaitingState
32 #define DataReadyState SUPERV::DataReadyState
33 #define SuspendedReadyState SUPERV::SuspendedReadyState
34 #define SuspendedReadyToResumeState SUPERV::SuspendedReadyToResumeState
35 #define ResumedReadyState SUPERV::ResumedReadyState
36 #define KilledReadyState SUPERV::KilledReadyState
37 #define StoppedReadyState SUPERV::StoppedReadyState
38 #define ExecutingState SUPERV::ExecutingState
39 #define SuspendedExecutingState SUPERV::SuspendedExecutingState
40 #define ResumedExecutingState SUPERV::ResumedExecutingState
41 #define KilledExecutingState SUPERV::KilledExecutingState
42 #define StoppedExecutingState SUPERV::StoppedExecutingState
43 #define SuccessedExecutingState SUPERV::SuccessedExecutingState
44 #define ErroredExecutingState SUPERV::ErroredExecutingState
45 #define SuspendedSuccessedState SUPERV::SuspendedSuccessedState
46 #define SuspendedErroredState SUPERV::SuspendedErroredState
47 #define SuspendedSuccessedToReStartState SUPERV::SuspendedSuccessedToReStartState
48 #define SuspendedErroredToReStartState SUPERV::SuspendedErroredToReStartState
49 #define ResumedSuccessedState SUPERV::ResumedSuccessedState
50 #define ResumedErroredState SUPERV::ResumedErroredState
51 #define KilledSuccessedState SUPERV::KilledSuccessedState
52 #define KilledErroredState SUPERV::KilledErroredState
53 #define StoppedSuccessedState SUPERV::StoppedSuccessedState
54 #define StoppedErroredState SUPERV::StoppedErroredState
55 #define SuccessedState SUPERV::SuccessedState
56 #define ErroredState SUPERV::ErroredState
57 #define SuspendedState SUPERV::SuspendedState
58 #define KilledState SUPERV::KilledState
59 #define StoppedState SUPERV::StoppedState
60 #define ReRunnedState SUPERV::ReRunnedState
61 #define ReStartedState SUPERV::ReStartedState
62 #define NumberOfAutomatonStates SUPERV::NumberOfAutomatonStates
65 #define UndefinedEvent GraphExecutor::UndefinedEvent
66 #define NewThreadEvent GraphExecutor::NewThreadEvent
67 #define SuspendEvent GraphExecutor::SuspendEvent
68 #define ToResumeEvent GraphExecutor::ToResumeEvent
69 #define ResumeEvent GraphExecutor::ResumeEvent
70 #define KillEvent GraphExecutor::KillEvent
71 #define StopEvent GraphExecutor::StopEvent
72 #define ExecuteEvent GraphExecutor::ExecuteEvent
73 #define SuccessEvent GraphExecutor::SuccessEvent
74 #define ErrorEvent GraphExecutor::ErrorEvent
75 #define ReStartEvent GraphExecutor::ReStartEvent
76 #define ReStartAndSuspendEvent GraphExecutor::ReStartAndSuspendEvent
77 #define NoDataReadyEvent GraphExecutor::NoDataReadyEvent
78 #define SomeDataReadyEvent GraphExecutor::SomeDataReadyEvent
79 #define NotAllDataReadyEvent GraphExecutor::NotAllDataReadyEvent
80 #define AllDataReadyEvent GraphExecutor::AllDataReadyEvent
81 #define ReadyEvent GraphExecutor::ReadyEvent
82 #define SuspendedReadyEvent GraphExecutor::SuspendedReadyEvent
83 #define ResumedReadyEvent GraphExecutor::ResumedReadyEvent
84 #define KilledReadyEvent GraphExecutor::KilledReadyEvent
85 #define StoppedReadyEvent GraphExecutor::StoppedReadyEvent
86 #define ExecutingEvent GraphExecutor::ExecutingEvent
87 #define SuspendedExecutingEvent GraphExecutor::SuspendedExecutingEvent
88 #define ResumedExecutingEvent GraphExecutor::ResumedExecutingEvent
89 #define KilledExecutingEvent GraphExecutor::KilledExecutingEvent
90 #define StoppedExecutingEvent GraphExecutor::StoppedExecutingEvent
91 #define SuccessedExecutingEvent GraphExecutor::SuccessedExecutingEvent
92 #define ErroredExecutingEvent GraphExecutor::ErroredExecutingEvent
93 #define SuspendedSuccessedEvent GraphExecutor::SuspendedSuccessedEvent
94 #define SuspendedErroredEvent GraphExecutor::SuspendedErroredEvent
95 #define ResumedSuccessedEvent GraphExecutor::ResumedSuccessedEvent
96 #define ResumedErroredEvent GraphExecutor::ResumedErroredEvent
97 #define KilledEvent GraphExecutor::KilledEvent
98 #define StoppedEvent GraphExecutor::StoppedEvent
99 #define ToReStartEvent GraphExecutor::ToReStartEvent
100 #define ReStartedEvent GraphExecutor::ReStartedEvent
101 #define ReStartedAndSuspendEvent GraphExecutor::ReStartedAndSuspendEvent
102 #define EndExecuteEvent GraphExecutor::EndExecuteEvent
103 #define NumberOfEvents GraphExecutor::NumberOfEvents
105 GraphExecutor::FiniteStateMachine::FiniteStateMachine() {
106 // cdebug_in << "FiniteStateMachine::FiniteStateMachine" << endl;
108 _ControlStateName[ VoidState ] = "VoidState" ;
109 _ControlStateName[ ToSuspendStartState ]= "ToSuspendStartState" ;
110 _ControlStateName[ ToSuspendState ] = "ToSuspendState" ;
111 _ControlStateName[ ToSuspendDoneState ] = "ToSuspendDoneState" ;
112 _ControlStateName[ ToKillState ] = "ToKillState" ;
113 _ControlStateName[ ToKillDoneState ] = "ToKillDoneState" ;
114 _ControlStateName[ ToStopState ] = "ToStopState" ;
116 _StateName[ UnKnownState ] = "UnKnownState" ;
117 _StateName[ DataUndefState ] = "DataUndefState" ;
118 _StateName[ DataWaitingState ] = "DataWaitingState" ;
119 _StateName[ DataReadyState ] = "DataReadyState" ;
120 _StateName[ SuspendedReadyState ] = "SuspendedReadyState" ;
121 _StateName[ SuspendedReadyToResumeState ] = "SuspendedReadyToResumeState" ;
122 _StateName[ ResumedReadyState ] = "ResumedReadyState" ;
123 _StateName[ KilledReadyState ] = "KilledReadyState" ;
124 _StateName[ StoppedReadyState ] = "StoppedReadyState" ;
125 _StateName[ ExecutingState ] = "ExecutingState" ;
126 _StateName[ SuspendedExecutingState ] = "SuspendedExecutingState" ;
127 _StateName[ ResumedExecutingState ] = "ResumedExecutingState" ;
128 _StateName[ KilledExecutingState ] = "KilledExecutingState" ;
129 _StateName[ StoppedExecutingState ] = "StoppedExecutingState" ;
130 _StateName[ SuccessedExecutingState ] = "SuccessedExecutingState" ;
131 _StateName[ ErroredExecutingState ] = "ErroredExecutingState" ;
132 _StateName[ SuspendedSuccessedState ] = "SuspendedSuccessedState" ;
133 _StateName[ SuspendedErroredState ] = "SuspendedErroredState" ;
134 _StateName[ SuspendedSuccessedToReStartState ] = "SuspendedSuccessedToReStartState" ;
135 _StateName[ SuspendedErroredToReStartState ] = "SuspendedErroredToReStartState" ;
136 _StateName[ ResumedSuccessedState ] = "ResumedSuccessedState" ;
137 _StateName[ ResumedErroredState ] = "ResumedErroredState" ;
138 _StateName[ KilledSuccessedState ] = "KilledSuccessedState" ;
139 _StateName[ KilledErroredState ] = "KilledErroredState" ;
140 _StateName[ StoppedSuccessedState ] = "StoppedSuccessedState" ;
141 _StateName[ StoppedErroredState ] = "StoppedErroredState" ;
142 _StateName[ SuccessedState ] = "SuccessedState" ;
143 _StateName[ ErroredState ] = "ErroredState" ;
144 _StateName[ SuspendedState ] = "SuspendedState" ;
145 _StateName[ KilledState ] = "KilledState" ;
146 _StateName[ StoppedState ] = "StoppedState" ;
147 _StateName[ ReRunnedState ] = "ReRunnedState" ;
148 _StateName[ ReStartedState ] = "ReStartedState" ;
150 _EventName[ UndefinedEvent ] = "UndefinedEvent" ;
151 _EventName[ NewThreadEvent ] = "NewThreadEvent" ;
152 _EventName[ SuspendEvent ] = "SuspendEvent" ;
153 _EventName[ ToResumeEvent ] = "ToResumeEvent" ;
154 _EventName[ ResumeEvent ] = "ResumeEvent" ;
155 _EventName[ KillEvent ] = "KillEvent" ;
156 _EventName[ StopEvent ] = "StopEvent" ;
157 _EventName[ ExecuteEvent ] = "ExecuteEvent" ;
158 _EventName[ SuccessEvent ] = "SuccessEvent" ;
159 _EventName[ ErrorEvent ] = "ErrorEvent" ;
160 _EventName[ ToReStartEvent ] = "ToReStartEvent" ;
161 _EventName[ ReStartEvent ] = "ReStartEvent" ;
162 _EventName[ ReStartAndSuspendEvent ] = "ReStartAndSuspendEvent" ;
163 _EventName[ NoDataReadyEvent ] = "NoDataReadyEvent" ;
164 _EventName[ SomeDataReadyEvent ] = "SomeDataReadyEvent" ;
165 _EventName[ NotAllDataReadyEvent ] = "NotAllDataReadyEvent" ;
166 _EventName[ AllDataReadyEvent ] = "AllDataReadyEvent" ;
167 _EventName[ ReadyEvent ] = "ReadyEvent" ;
168 _EventName[ SuspendedReadyEvent ] = "SuspendedReadyEvent" ;
169 _EventName[ ResumedReadyEvent ] = "ResumedReadyEvent" ;
170 _EventName[ KilledReadyEvent ] = "KilledReadyEvent" ;
171 _EventName[ StoppedReadyEvent ] = "StoppedReadyEvent" ;
172 _EventName[ ExecutingEvent ] = "ExecutingEvent" ;
173 _EventName[ SuspendedExecutingEvent ] = "SuspendedExecutingEvent" ;
174 _EventName[ ResumedExecutingEvent ] = "ResumedExecutingEvent" ;
175 _EventName[ KilledExecutingEvent ] = "KilledExecutingEvent" ;
176 _EventName[ StoppedExecutingEvent ] = "StoppedExecutingEvent" ;
177 _EventName[ SuccessedExecutingEvent ] = "SuccessedExecutingEvent" ;
178 _EventName[ ErroredExecutingEvent ] = "ErroredExecutingEvent" ;
179 _EventName[ SuspendedSuccessedEvent ] = "SuspendedSuccessedEvent" ;
180 _EventName[ SuspendedErroredEvent ] = "SuspendedErroredEvent" ;
181 _EventName[ ResumedSuccessedEvent ] = "ResumedSuccessedEvent" ;
182 _EventName[ ResumedErroredEvent ] = "ResumedErroredEvent" ;
183 _EventName[ KilledEvent ] = "KilledEvent" ;
184 _EventName[ StoppedEvent ] = "StoppedEvent" ;
185 _EventName[ ReStartedEvent ] = "ReStartedEvent" ;
186 _EventName[ ReStartedAndSuspendEvent ]= "ReStartedAndSuspendEvent" ;
187 _EventName[ EndExecuteEvent ] = "EndExecuteEvent" ;
189 _ActionName[ ErrorAction ] = "ErrorAction" ;
190 _ActionName[ VoidAction ] = "VoidAction" ;
191 _ActionName[ executeAction ] = "executeAction" ;
192 _ActionName[ ExecuteAction ] = "ExecuteAction" ;
193 _ActionName[ DataWaiting_SomeDataReadyAction ] = "DataWaiting_SomeDataReadyAction" ;
194 _ActionName[ DataUndef_NotAllDataReadyAction ] = "DataUndef_NotAllDataReadyAction";
195 _ActionName[ DataUndef_AllDataReadyAction ] = "DataUndef_AllDataReadyAction" ;
197 _ActionName[ DataReady_SuspendAction ] = "DataReady_SuspendAction" ;
198 _ActionName[ SuspendedReady_ResumeAction ] = "SuspendedReady_ResumeAction" ;
199 _ActionName[ DataReady_KillAction ] = "DataReady_KillAction" ;
200 _ActionName[ DataReady_StopAction ] = "DataReady_StopAction" ;
202 _ActionName[ DataReady_ExecuteAction ] = "DataReady_ExecuteAction" ;
204 _ActionName[ Executing_SuspendAction ] = "Executing_SuspendAction" ;
205 _ActionName[ SuspendedExecuting_ResumeAction ] = "SuspendedExecuting_ResumeAction" ;
206 _ActionName[ Executing_KillAction ] = "Executing_KillAction" ;
207 _ActionName[ Executing_StopAction ] = "Executing_StopAction" ;
209 _ActionName[ Executing_SuccessAction ] = "Executing_SuccessAction" ;
210 _ActionName[ Executing_ErrorAction ] = "Executing_ErrorAction" ;
211 _ActionName[ Successed_SuccessAction ] = "Successed_SuccessAction" ;
212 _ActionName[ Errored_ErrorAction ] = "Errored_ErrorAction" ;
214 _ActionName[ Successed_SuspendAction ] = "Successed_SuspendAction" ;
215 _ActionName[ Errored_SuspendAction ] = "Errored_SuspendAction" ;
216 _ActionName[ SuspendedSuccessed_ResumeAction ] = "SuspendedSuccessed_ResumeAction" ;
217 _ActionName[ SuspendedErrored_ResumeAction ] = "SuspendedErrored_ResumeAction" ;
218 _ActionName[ Successed_KillAction ] = "Successed_KillAction" ;
219 _ActionName[ Errored_KillAction ] = "Errored_KillAction" ;
220 _ActionName[ Successed_StopAction ] = "Successed_StopAction" ;
221 _ActionName[ Errored_StopAction ] = "Errored_StopAction" ;
223 _ActionName[ SuspendedSuccessed_ReStartAction ] = "SuspendedSuccessed_ReStartAction" ;
224 _ActionName[ SuspendedErrored_ReStartAction ] = "SuspendedErrored_ReStartAction" ;
225 _ActionName[ SuspendedSuccessed_ReStartAndSuspendAction ] = "SuspendedSuccessed_ReStartAndSuspendAction" ;
226 _ActionName[ SuspendedErrored_ReStartAndSuspendAction ] = "SuspendedErrored_ReStartAndSuspendAction" ;
228 _GraphStateName[ SUPERV::UndefinedState ] = "UndefinedState" ;
229 _GraphStateName[ SUPERV::NoState ] = "NoState" ;
230 _GraphStateName[ SUPERV::EditingState ] = "EditingState" ;
231 _GraphStateName[ SUPERV::SuspendState ] = "SuspendState" ;
232 _GraphStateName[ SUPERV::WaitingState ] = "WaitingState" ;
233 _GraphStateName[ SUPERV::ReadyState ] = "ReadyState" ;
234 _GraphStateName[ SUPERV::SuspendReadyState ] = "SuspendReadyState" ;
235 _GraphStateName[ SUPERV::RunningState ] = "RunningState" ;
236 _GraphStateName[ SUPERV::DoneState ] = "DoneState" ;
237 _GraphStateName[ SUPERV::ErrorState ] = "ErrorState" ;
238 _GraphStateName[ SUPERV::SuspendDoneState ] = "SuspendDoneState" ;
239 _GraphStateName[ SUPERV::SuspendErroredState ] = "SuspendErroredState" ;
240 _GraphStateName[ SUPERV::KillState ] = "KillState" ;
241 _GraphStateName[ SUPERV::StopState ] = "StopState" ;
242 _GraphStateName[ SUPERV::ReRunState ] = "ReRunState" ;
243 _GraphStateName[ SUPERV::ReStartState ] = "ReStartState" ;
246 // NewStates = _TransitionTable[ States ] [ Events ]
247 // associated action = _ActionTable[ NewStates ] [ Events ]
248 for ( i = 0 ; i < NumberOfAutomatonStates ; i++ ) {
249 for ( j = 0 ; j < NumberOfEvents ; j++ ) {
250 // id est = SameState and VoidAction
251 _TransitionTable[ i ][ j ] = (SUPERV::AutomatonState ) i ;
252 _ActionTable[ i ][ j ] = GraphExecutor::ErrorAction ;
255 // OneEvent ===> Change of State and associated Action :
256 // _TransitionTable[ OldState ][ OneEvent ] gives a NewState
257 // _Action[ NewState ][ OneEvent ] gives what to do
260 // NoDataReadyEvent :
261 _TransitionTable[ DataUndefState ][ NoDataReadyEvent ] = DataWaitingState ;
262 _ActionTable[ DataWaitingState ][ NoDataReadyEvent ] = VoidAction ;
263 // SomeDataReadyEvent :
264 _TransitionTable[ DataWaitingState ][ SomeDataReadyEvent ] = DataUndefState ;
265 _ActionTable[ DataUndefState ][ SomeDataReadyEvent ] = DataWaiting_SomeDataReadyAction;
266 // NotAllDataReadyEvent :
267 _TransitionTable[ DataUndefState ][ NotAllDataReadyEvent ] = DataWaitingState ;
268 _ActionTable[ DataWaitingState ][ NotAllDataReadyEvent ] = DataUndef_NotAllDataReadyAction;
270 _TransitionTable[ DataUndefState ][ AllDataReadyEvent ] = DataReadyState ;
271 _ActionTable[ DataReadyState ][ AllDataReadyEvent ] = DataUndef_AllDataReadyAction ;
273 // DATAS-READY-CONTROL :
275 _TransitionTable[ DataReadyState ][ SuspendEvent ] = SuspendedReadyState ;
276 _ActionTable[ SuspendedReadyState ][ SuspendEvent ] = DataReady_SuspendAction;
278 _TransitionTable[ SuspendedReadyState ][ ToResumeEvent ] = SuspendedReadyToResumeState ;
279 _ActionTable[ SuspendedReadyToResumeState ][ ToResumeEvent ] = VoidAction ;
281 _TransitionTable[ SuspendedReadyToResumeState ][ ResumeEvent ] = ResumedReadyState ;
282 _ActionTable[ ResumedReadyState ][ ResumeEvent] = SuspendedReady_ResumeAction ;
284 _TransitionTable[ SuspendedReadyState ][ KillEvent ] = KilledReadyState ;
286 _TransitionTable[ SuspendedReadyState ][ StopEvent ] = StoppedReadyState ;
288 _TransitionTable[ DataReadyState ][ KillEvent ] = KilledReadyState ;
289 _ActionTable[ KilledReadyState ][ KillEvent] = DataReady_KillAction ;
291 _TransitionTable[ DataReadyState ][ StopEvent ] = StoppedReadyState ;
292 _ActionTable[ StoppedReadyState ][ StopEvent] = DataReady_StopAction ;
296 _TransitionTable[ SuspendedReadyToResumeState ][ ExecuteEvent ] = ExecutingState ;
298 _TransitionTable[ ResumedReadyState ][ ExecuteEvent ] = ExecutingState ;
300 _TransitionTable[ DataReadyState ][ ExecuteEvent ] = ExecutingState ;
302 _TransitionTable[ ReStartedState ][ ExecuteEvent ] = ExecutingState ;
303 _ActionTable[ ExecutingState ][ ExecuteEvent ] = DataReady_ExecuteAction;
307 _TransitionTable[ ExecutingState ][ SuspendEvent ] = SuspendedExecutingState ;
308 _ActionTable[ SuspendedExecutingState ][ SuspendEvent ] = Executing_SuspendAction;
310 _TransitionTable[ SuspendedExecutingState ][ ResumeEvent ] = ResumedExecutingState ;
311 _ActionTable[ ResumedExecutingState ][ ResumeEvent] = SuspendedExecuting_ResumeAction;
313 _TransitionTable[ ResumedExecutingState ][ ExecuteEvent ] = ExecutingState ;
315 _TransitionTable[ SuspendedExecutingState ][ KillEvent ] = KilledExecutingState ;
317 _TransitionTable[ SuspendedExecutingState ][ StopEvent ] = StoppedExecutingState ;
319 _TransitionTable[ ExecutingState ][ KillEvent ] = KilledExecutingState ;
320 _ActionTable[ KilledExecutingState ][ KillEvent] = Executing_KillAction;
321 _TransitionTable[ KilledExecutingState ][ KillEvent ] = KilledState ;
322 _ActionTable[ KilledState ][ KillEvent] = VoidAction;
324 _TransitionTable[ ExecutingState ][ StopEvent ] = StoppedExecutingState ;
325 _ActionTable[ StoppedExecutingState ][ StopEvent] = Executing_StopAction;
326 _TransitionTable[ StoppedExecutingState ][ StopEvent ] = StoppedState ;
327 _ActionTable[ StoppedState ][ StopEvent] = VoidAction;
331 _TransitionTable[ ExecutingState ][ SuccessEvent ] = SuccessedExecutingState ;
332 _ActionTable[ SuccessedExecutingState ][ SuccessEvent ] = Executing_SuccessAction;
333 // SuspendedExecutingState : NO ResumeEvent 13-03-2003
334 _TransitionTable[ SuspendedExecutingState ][ SuccessEvent ] = SuccessedExecutingState ;
335 _ActionTable[ SuccessedExecutingState ][ SuccessEvent ] = Executing_SuccessAction;
337 _TransitionTable[ ExecutingState ][ ErrorEvent ] = ErroredExecutingState ;
338 _ActionTable[ ErroredExecutingState ][ ErrorEvent ] = Executing_ErrorAction;
339 // SuspendedExecutingState : NO ResumeEvent 13-03-2003
340 _TransitionTable[ SuspendedExecutingState ][ ErrorEvent ] = ErroredExecutingState ;
341 _ActionTable[ ErroredExecutingState ][ ErrorEvent ] = Executing_ErrorAction;
344 // SuccessedExecutingState - SuccessEvent
345 _TransitionTable[ SuccessedExecutingState ][ SuccessEvent ] = SuccessedState ;
346 _ActionTable[ SuccessedState ][ SuccessEvent ] = Successed_SuccessAction ;
347 // ErroredExecutingState - ErrorEvent
348 _TransitionTable[ ErroredExecutingState ][ ErrorEvent ] = ErroredState ;
349 _ActionTable[ ErroredState ][ ErrorEvent ] = Errored_ErrorAction ;
351 // SuccessedState - SuspendEvent
352 _TransitionTable[ SuccessedExecutingState ][ SuspendEvent ] = SuspendedSuccessedState ;
353 _ActionTable[ SuspendedSuccessedState ][ SuspendEvent ] = Successed_SuspendAction;
354 // ErroredState - SuspendEvent
355 _TransitionTable[ ErroredExecutingState ][ SuspendEvent ] = SuspendedErroredState ;
356 _ActionTable[ SuspendedErroredState ][ SuspendEvent ] = Errored_SuspendAction;
358 // SuccessedState - KillEvent
359 _TransitionTable[ SuccessedExecutingState ][ KillEvent ] = KilledSuccessedState ;
360 _ActionTable[ KilledSuccessedState ][ KillEvent ] = Successed_KillAction;
361 // ErroredState - KillEvent
362 _TransitionTable[ ErroredExecutingState ][ KillEvent ] = KilledErroredState ;
363 _ActionTable[ KilledErroredState ][ KillEvent ] = Errored_KillAction;
365 // SuccessedState - StopEvent
366 _TransitionTable[ SuccessedExecutingState ][ StopEvent ] = StoppedSuccessedState ;
367 _ActionTable[ StoppedSuccessedState ][ StopEvent ] = Successed_StopAction;
368 // ErroredState - StopEvent
369 _TransitionTable[ ErroredExecutingState ][ StopEvent ] = StoppedErroredState ;
370 _ActionTable[ StoppedErroredState ][ StopEvent ] = Errored_StopAction;
372 // SuspendedSuccessedState - ResumeEvent
373 _TransitionTable[ SuspendedSuccessedState ][ ResumeEvent ] = ResumedSuccessedState ;
374 _ActionTable[ ResumedSuccessedState ][ ResumeEvent ] = SuspendedSuccessed_ResumeAction;
376 _TransitionTable[ ResumedSuccessedState ][ ResumedSuccessedEvent ] = SuccessedState ;
377 _ActionTable[ SuccessedState ][ ResumedSuccessedEvent] = Successed_SuccessAction;
379 // SuspendedErroredState - ResumeEvent
380 _TransitionTable[ SuspendedErroredState ][ ResumeEvent ] = ResumedErroredState ;
381 _ActionTable[ ResumedErroredState ][ ResumeEvent ] = SuspendedErrored_ResumeAction;
382 _TransitionTable[ ResumedErroredState ][ ResumedErroredEvent ] = ErroredState ;
383 _ActionTable[ ErroredState ][ ResumedErroredEvent ] = Errored_ErrorAction;
385 // SuccessedState - KillEvent
386 _TransitionTable[ SuccessedState ][ KillEvent ] = KilledSuccessedState ;
387 _ActionTable[ KilledSuccessedState ][ KillEvent] = Successed_KillAction;
388 _TransitionTable[ KilledSuccessedState ][ KillEvent ] = KilledState ;
389 _ActionTable[ KilledState ][ KillEvent ] = VoidAction;
390 // ErroredState - KillEvent
391 _TransitionTable[ ErroredState ][ KillEvent ] = KilledErroredState ;
392 _ActionTable[ KilledErroredState ][ KillEvent] = Errored_KillAction;
393 _TransitionTable[ KilledErroredState ][ KillEvent ] = KilledState ;
394 _ActionTable[ KilledState ][ KillEvent ] = VoidAction;
396 // SuccessedState - StopEvent
397 _TransitionTable[ SuccessedState ][ StopEvent ] = StoppedSuccessedState ;
398 _ActionTable[ StoppedSuccessedState ][ StopEvent] = Successed_StopAction;
399 _TransitionTable[ StoppedSuccessedState ][ StopEvent ] = StoppedState ;
400 _ActionTable[ StoppedState ][ StopEvent ] = VoidAction;
401 // ErroredState - StopEvent
402 _TransitionTable[ ErroredState ][ StopEvent ] = StoppedErroredState ;
403 _ActionTable[ StoppedErroredState ][ StopEvent] = Errored_StopAction;
404 _TransitionTable[ StoppedErroredState ][ StopEvent ] = StoppedState ;
405 _ActionTable[ StoppedState ][ StopEvent ] = VoidAction;
408 _TransitionTable[ SuspendedSuccessedState ][ ToReStartEvent ] = SuspendedSuccessedToReStartState ;
409 _ActionTable[ SuspendedSuccessedToReStartState ][ ToReStartEvent] = VoidAction ;
411 _TransitionTable[ SuspendedSuccessedToReStartState ][ ReStartEvent ] = ReStartedState ;
412 _TransitionTable[ SuspendedSuccessedToReStartState ][ ReStartAndSuspendEvent ] = ReStartedState ;
414 _TransitionTable[ SuspendedErroredState ][ ToReStartEvent ] = SuspendedErroredToReStartState ;
415 _ActionTable[ SuspendedErroredToReStartState ][ ToReStartEvent] = VoidAction ;
417 _TransitionTable[ SuspendedErroredToReStartState ][ ReStartEvent ] = ReStartedState ;
418 _TransitionTable[ SuspendedErroredToReStartState ][ ReStartAndSuspendEvent ] = ReStartedState ;
420 _ActionTable[ ReStartedState ][ ReStartEvent] = SuspendedSuccessed_ReStartAction;
421 _ActionTable[ ReStartedState ][ ReStartAndSuspendEvent] = SuspendedSuccessed_ReStartAndSuspendAction;
423 pthread_mutex_init( &_MutexJoinWait , NULL ) ;
424 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
425 perror("pthread_cond_init( &_JoinWait , NULL )") ;
429 if ( pthread_create( &_JoinThreadNo , NULL , start_function , this ) ) {
430 char * msg = "Cannot pthread_create " ;
434 // cdebug_out << "FiniteStateMachine::FiniteStateMachine _TransitionTable "
438 void * start_function( void *p ) {
439 GraphExecutor::FiniteStateMachine *anAutomaton = (GraphExecutor::FiniteStateMachine *) p;
440 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) ) {
441 perror("pthread_setcanceltype ") ;
444 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) ) {
445 perror("pthread_setcancelstate ") ;
448 anAutomaton->JoinThread() ;
449 pthread_exit( PTHREAD_CANCELED ) ;
452 void GraphExecutor::FiniteStateMachine::JoinThread() {
453 if ( pthread_mutex_lock( &_MutexJoinWait ) ) {
454 perror("Join pthread_mutex_lock ") ;
457 while ( _JoinThread ) {
458 while ( _ThreadList.size() == 0) {
459 // MESSAGE( pthread_self() << " Join pthread_cond_wait" );
460 if ( pthread_cond_wait( &_JoinWait , &_MutexJoinWait ) ) {
461 perror("Join pthread_cond_wait ") ;
464 pthread_t _Thread = _ThreadList.front() ;
465 // MESSAGE( pthread_self() << " Join pthread_cond_waited : " << _Thread )
466 _ThreadList.pop_front() ;
467 // MESSAGE( pthread_self() << " Join pthread_join : " << _Thread );
468 int joinsts = pthread_join( _Thread , NULL ) ;
469 // MESSAGE( pthread_self() << " Join pthread_joined : " << _Thread );
471 perror("Join pthread_join ") ;
475 if ( pthread_mutex_unlock( &_MutexJoinWait ) ) {
476 perror("Join pthread_mutex_unlock ") ;
481 void GraphExecutor::FiniteStateMachine::JoinThread( pthread_t aThread ) {
482 if ( pthread_mutex_lock( &_MutexJoinWait ) ) {
483 perror("Join pthread_mutex_lock ") ;
486 // MESSAGE(pthread_self() << " JoinThread pthread_cond_signal for " << aThread)
487 _ThreadList.push_back( aThread ) ;
488 if ( pthread_cond_signal( &_JoinWait ) ) {
489 perror("Join pthread_cond_signal ") ;
491 // MESSAGE( pthread_self() << " JoinThread pthread_cond_signaled for " << aThread)
493 if ( pthread_mutex_unlock( &_MutexJoinWait ) ) {
494 perror("Join pthread_mutex_unlock ") ;