acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
sequence.h
1// Deeply refactored by camilo on 2024-10-07 07:24 <3ThomasBorregaardSorensen!!
2// More deep refactoring merging post_procedure_continuation by
3// camilo on 2024-10-09 11:31 <3ThomasBorregaardSorensen!!
4// post_procedure_continuation
5// camilo on 2024-10-08 08:45 <3ThomasBorregaardSorensen!!
6#pragma once
7
8
9//struct continuation_t {};
10
11using particle_pointer = ::pointer < ::particle >;
12//template < typename CONTEXT_TYPE >
13//class procedure_array_with_context;
14
15class sequence;
16// Deeply refactored by camilo on 2024-10-07 07:24 <3ThomasBorregaardSorensen!!
17// More deep refactoring merging post_procedure_continuation by
18// camilo on 2024-10-09 11:31 <3ThomasBorregaardSorensen!!
19// post_procedure_continuation
20// camilo on 2024-10-08 08:45 <3ThomasBorregaardSorensen!!
21#pragma once
22
23
24using particle_pointer = ::pointer < ::particle >;
25template < typename CONTEXT_TYPE >
27//struct continuation_t {};
28#include "acme/parallelization/task_context.h"
29
30//class task_context_base :
31// virtual public ::particle
32//{
33//public:
34//
35// ::pointer <task_context_base> m_pParent;
36//
37// inline static thread_local ::pointer <task_context_base> t_pRoot;
38// static task_context_base * current() { return t_pRoot; }
39// void push()
40// {
41//
42// auto pNewParent = t_pRoot;
43//
44// t_pRoot = this;
45//
46// t_pRoot->m_pParent = pNewParent;
47//
48// }
49//
50//
51// void pop()
52// {
53//
54// auto pParent = t_pRoot->m_pParent;
55//
56// t_pRoot = pParent;
57//
58// }
59//
60//};
61//
62//class stack_task_context_base
63//{
64//public:
65// task_context_base * m_p;
66//
67// stack_task_context_base(task_context_base * p) :
68// m_p(p)
69// {
70// m_p->push();
71//
72// }
73//
74// ~stack_task_context_base()
75// {
76//
77// m_p->pop();
78//
79// m_p = nullptr;
80// }
81//
82//};
83//
84//template < typename CONTEXT_TYPE >
85//class task_context :
86// virtual public ::task_context_base
87//{
88//public:
89//
90// task_context()
91// {
92//
93// }
94// ~task_context() override
95// {
96//
97// }
98//
99//};
100
102
103class CLASS_DECL_ACME sequence :
104 virtual public ::subparticle_array
105 //virtual public procedure_array_with_context<sequence>,
106 //virtual public property_object
107{
108public:
109
110 //::particle_pointer m_pparticleLast;
111 //::particle_pointer m_pparticle;
112 ::pointer < manual_reset_happening > m_pmanualresethappeningOnEndOfSequence;
113 class ::time m_timeLocked;
114 class ::time m_timeSet;
115 class ::time m_timeTimeout;
116 ::e_status m_estatusWait;
117
118 sequence();
119 ~sequence() override;
120
121
122#if defined(_DEBUG)
123
124 ::i64 increment_reference_count() override;
125 ::i64 decrement_reference_count() override;
126
127#endif
128
129
130 virtual void on_subparticle_sequence(::subparticle * psubparticle);
131
132// static sequence * current();
133// [[noreturn]] inline static void cancel()
134// {
135//
136// throw ::cancel_exception<sequence>();
137//
138// }
139 void run() override;
140// ::payload get_last_result();
141// void on_end_procedure() override;
142 void destroy() override;
143
144
145 virtual void on_end_of_sequence();
146 class ::time remaining_from_timeout() const;
147
148
149
150};
151//
152//
153//template < typename TARGET_TYPE >
154//class CLASS_DECL_ACME sequence_continuation
155//{
156//public:
157//
158// ::procedure m_procedure;
159// ::pointer < sequence > m_psequence;
160// ::pointer < TARGET_TYPE > m_ptarget;
161// void (TARGET_TYPE:: *)(const ::procedure &) m_pfnSequencer;
162//
163//
164// sequence_continuation(TARGET_TYPE * pparticleTarget, void (TARGET_TYPE:: *)(const ::procedure &) pfn);
165// sequence_continuation(::particle * pparticleTarget, const ::procedure & procedure);
166// sequence_continuation & operator << (const ::procedure & procedure);
167// ~sequence_continuation();
168//
169//};
170
171//#pragma once
172
173//enum enum_as
174//{
175// as
176//};
177
178//#include "acme/parallelization/synchronization.h"
179//#include "acme/parallelization/manual_reset_happening.h"
180//#include "acme/parallelization/critical_section.h"
181//#include "acme/user/user/conversation.h"
182//#include "acme/platform/application.h"
183//#include "acme/handler/step_function.h"
184//#include "acme/handler/aggregate.h"
185//template < typename SEQUENCE >
186//using sequence_step = ::function < void(SEQUENCE *) >;
187//
188//#include "acme/prototype/collection/list.h"
189
190//
191//class sequencer_payload :
192// virtual public ::list_base < ::sequencer_step >
193//{
194//public:
195//
196//
197// ::payload m_payload;
198// ::list_base < ::sequencer_step >::iterator m_iterator;
199// ::sequencer & m_sequencer;
200// //::pointer< ::particle > m_pparticleLast;
201// //::pointer< ::particle > m_pparticle;
202// //::collection::index m_iStep;
203//
204// sequencer_payload(::sequencer & sequencer);
205//
206// ~sequencer_payload();
207//
208//
209// void on_initialize_particle();
210//
211//
212// virtual void add_result(const ::payload & payload);
213//
214//
215// ///void set_object(const TYPE & result, const ::e_status & estatus = ::success);
216// //void set_status(const ::e_status & estatus = ::success);
217// void run() override;
218// ::e_status do_step();
219//
220// virtual void sequence_step();
221//
222// void add_step(const ::sequencer_step & step);
223//
224// //::sequencer & operator << (enum_as, ::sequence_aggregator::base * psequenceaggregatorbase);
225//
226// //::sequence & then(const ::sequence_aggregator & step);
227//
228// //::sequencer & then(enum_as, ::sequence_aggregator::base * psequenceaggregatorbase);
229//
230// //::sequencer & then(const ::sequence_aggregator & step);
231//
232// //virtual void do_asynchronously()
233// //{
234//
235// // m_psequence->do_asynchronously();
236//
237// //}
238// virtual ::payload last_result();
239//
240//};
241
242//class sequencer :
243// public ::pointer < sequencer_payload >
244//{
245//public:
246//
247// sequencer(::particle * pparticle);
248//
249//
250// ::sequencer & operator << (const ::sequencer_step & step);
251//
252//
253// ::payload last_result();
254//
255// void add_result(const ::payload & payload);
256//
257//};
258
259//sequence * sequence::then(const function & function)
260//{
261//
262// m_psequencer->then(function);
263//
264// return this;
265//
266//}
267//
268//sequence * sequence::then(const class time & time, const function & function);
269//{
270//
271// m_psequencer->then(time, function);
272// return this;
273//
274//}
275
276//CLASS_DECL_ACME critical_section* ::platform::get()->sequence_critical_section();
277
278//CLASS_DECL_ACME void initialize_sequence_critical_section();
279//
280//CLASS_DECL_ACME void finalize_sequence_critical_section();
281
282
283//template < typename TYPE /*, typename TRANSPORT = ::transport < TYPE >, typename SEQUENCE = ::sequence < TYPE, TRANSPORT >*/ >
284//class asynchronous :
285// virtual public matter
286//{
287//public:
288//
289//
290// ::pointer<TYPE> m_p;
291//
292//
293// //TYPE * ();
294//
295//
296//};
297
298
299
300
301//template < typename SEQUENCE >
302//sequencer < SEQUENCE > ::sequencer()
303//{
304//
305// //m_ptask = ::get_task();
306//
307// m_phappening = nullptr;
308//
309//}
310
311
312//template < typename TYPE >
313//void future < RESULT > ::set_object(const RESULT& result, const ::e_status & estatus)
314//{
315//
316// critical_section_lock lock(::platform::get()->sequence_critical_section());
317//
318// if (m_p.m_estatus == error_not_initialized)
319// {
320//
321// m_p.m_estatus = estatus;
322//
323// m_p.m_result = result;
324//
325// if (m_phappening)
326// {
327//
328// m_phappening->set_happening();
329//
330// }
331//
332// if (m_preceptor)
333// {
334//
335// m_preceptor->get(this);
336//
337// }
338//
339// }
340//
341//}
342
343//
344//template < typename SEQUENCE >
345//void sequencer < SEQUENCE > ::fork()
346//{
347//
348// fork(this, [this]()
349// {
350//
351// on_sequence();
352//
353// });
354//
355//}
356
357//
358//template < typename SEQUENCE >
359//void sequencer < SEQUENCE > ::on_sequence()
360//{
361//
362// critical_section_lock lock(::platform::get()->sequence_critical_section());
363//
364// if (m_phappening)
365// {
366//
367// m_phappening->set_happening();
368//
369// }
370//
371// if(m_stepa.has_element())
372// {
373//
374// ::pointer < sequencer < SEQUENCE > > psequencer(this);
375//
376// auto step = m_stepa.pop_first();
377//
378// lock.unlock();
379//
380// auto λ = [this, step, psequencer]
381// {
382//
383// step(m_psequence);
384//
385// psequencer->on_sequence();
386//
387// };
388//
389// m_papplication->post_procedure(λ);
390//
391// }
392// else
393// {
394//
395// m_psequence.release();
396//
397// }
398//
399//}
400//
401
402//template < typename SEQUENCE >
403//void sequencer < SEQUENCE > ::set_status(const ::e_status & estatus)
404//{
405//
406// critical_section_lock lock(::platform::get()->sequence_critical_section());
407//
408// m_p.m_estatus = estatus;
409//
410// if (m_phappening)
411// {
412//
413// m_phappening->set_happening();
414//
415// }
416//
417// increment_reference_count();
418//
419// system()->fork(__routine([this]()
420// {
421//
422// auto pHold = ::pointer_transfer(this);
423//
424// critical_section_lock lock(::platform::get()->sequence_critical_section());
425//
426// while (m_stepa.has_element())
427// {
428//
429// auto pfunction = m_stepa.pop_first();
430//
431// lock.unlock();
432//
433// pfunction->process(*this);
434//
435// lock.lock();
436//
437// }
438//
439// }));
440//
441//}
442
443
444//
445//template < typename SEQUENCE >
446//sequence < SEQUENCE > * sequencer < SEQUENCE > ::then(const sequence_step < SEQUENCE > & step)
447//{
448//
449// critical_section_lock lock(::platform::get()->sequence_critical_section());
450//
451// if (m_psequence.is_set())
452// {
453//
454// m_stepa.add(step);
455//
456// }
457// else
458// {
459//
460// lock.unlock();
461//
462// step(m_psequence);
463//
464// }
465//
466// return m_psequence;
467//
468//}
469//
470//
471//template < typename SEQUENCE >
472//sequence < SEQUENCE > * sequencer < SEQUENCE > ::then(const class time & timeWait, const sequence_step < SEQUENCE > & step)
473//{
474//
475// critical_section_lock lock(::platform::get()->sequence_critical_section());
476//
477// if (m_psequence.m_estatus == error_not_initialized)
478// {
479//
480// m_stepa.add(step);
481//
482// m_phappening = allocateø manual_reset_happening();
483//
484// lock.unlock();
485//
486// if (!m_phappening->wait(timeWait))
487// {
488//
489// lock.lock();
490//
491// if (m_psequence.m_estatus == error_not_initialized)
492// {
493//
494// m_psequence.m_estatus = error_timeout;
495//
496// }
497//
498// lock.unlock();
499//
500// if (m_psequence.m_estatus == error_timeout)
501// {
502//
503// step(m_psequence);
504//
505// }
506//
507// }
508//
509// }
510// else
511// {
512//
513// lock.unlock();
514//
515// step(m_psequence);
516//
517// }
518//
519// return m_psequence;
520//
521//}
522//
523//
524//template < typename SEQUENCE >
525//sequence < SEQUENCE > * sequencer < SEQUENCE > ::topic(const class time & timeWait)
526//{
527//
528// critical_section_lock lock(::platform::get()->sequence_critical_section());
529//
530// if (m_psequence.m_estatus == error_not_initialized)
531// {
532//
533// m_phappening = allocateø manual_reset_happening();
534//
535// if (!m_phappening->wait(timeWait))
536// {
537//
538// lock.lock();
539//
540// if (m_psequence.m_estatus == error_not_initialized)
541// {
542//
543// m_psequence.m_estatus = error_timeout;
544//
545// }
546//
547// lock.unlock();
548//
549// }
550//
551// }
552//
553// return this->m_p;
554//
555//}
556//
557//
558//template < typename SEQUENCE >
559//::e_status sequencer < SEQUENCE > ::wait(const class time & timeWait)
560//{
561//
562// critical_section_lock lock(::platform::get()->sequence_critical_section());
563//
564// if (m_psequence.m_estatus == error_not_initialized)
565// {
566//
567// m_phappening = allocateø manual_reset_happening();
568//
569// lock.unlock();
570//
571// if (!m_phappening->wait(timeWait))
572// {
573//
574// lock.lock();
575//
576// if (m_psequence.m_estatus == error_not_initialized)
577// {
578//
579// m_psequence.m_estatus = error_wait_timeout;
580//
581// }
582//
583// lock.unlock();
584//
585// }
586//
587// }
588//
589// return m_psequence.m_estatus;
590//
591//}
592//
593
594
595
596//#pragma once
597
598//enum enum_as
599//{
600// as
601//};
602
603//#include "acme/parallelization/synchronization.h"
604//#include "acme/parallelization/manual_reset_happening.h"
605//#include "acme/parallelization/critical_section.h"
606//#include "acme/user/user/conversation.h"
607//#include "acme/platform/application.h"
608//#include "acme/handler/step_function.h"
609//#include "acme/handler/aggregate.h"
610//template < typename SEQUENCE >
611//using sequence_step = ::function < void(SEQUENCE *) >;
612
613//#include "acme/prototype/collection/list.h"
614//
615//
616//class sequencer_payload :
617// virtual public ::list_base < ::sequencer_step >
618//{
619//public:
620//
621//
622// ::payload m_payload;
623// ::list_base < ::sequencer_step >::iterator m_iterator;
624// ::sequencer & m_sequencer;
625// //::pointer< ::particle > m_pparticleLast;
626// //::pointer< ::particle > m_pparticle;
627// //::collection::index m_iStep;
628//
629// sequencer_payload(::sequencer & sequencer);
630//
631// ~sequencer_payload();
632//
633//
634// void on_initialize_particle();
635//
636//
637// virtual void add_result(const ::payload & payload);
638//
639//
640// ///void set_object(const TYPE & result, const ::e_status & estatus = ::success);
641// //void set_status(const ::e_status & estatus = ::success);
642// void run() override;
643// ::e_status do_step();
644//
645// virtual void sequence_step();
646//
647// void add_step(const ::sequencer_step & step);
648//
649// //::sequencer & operator << (enum_as, ::sequence_aggregator::base * psequenceaggregatorbase);
650//
651// //::sequence & then(const ::sequence_aggregator & step);
652//
653// //::sequencer & then(enum_as, ::sequence_aggregator::base * psequenceaggregatorbase);
654//
655// //::sequencer & then(const ::sequence_aggregator & step);
656//
657// //virtual void do_asynchronously()
658// //{
659//
660// // m_psequence->do_asynchronously();
661//
662// //}
663// virtual ::payload last_result();
664//
665//};
666//
667//class sequencer :
668// public ::pointer < sequencer_payload >
669//{
670//public:
671//
672// sequencer(::particle * pparticle);
673//
674//
675// ::sequencer & operator << (const ::sequencer_step & step);
676//
677//
678// ::payload last_result();
679//
680// void add_result(const ::payload & payload);
681//
682//};
683
684//sequence * sequence::then(const function & function)
685//{
686//
687// m_psequencer->then(function);
688//
689// return this;
690//
691//}
692//
693//sequence * sequence::then(const class time & time, const function & function);
694//{
695//
696// m_psequencer->then(time, function);
697// return this;
698//
699//}
700
701//CLASS_DECL_ACME critical_section* ::platform::get()->sequence_critical_section();
702
703//CLASS_DECL_ACME void initialize_sequence_critical_section();
704//
705//CLASS_DECL_ACME void finalize_sequence_critical_section();
706
707
708//template < typename TYPE /*, typename TRANSPORT = ::transport < TYPE >, typename SEQUENCE = ::sequence < TYPE, TRANSPORT >*/ >
709//class asynchronous :
710// virtual public matter
711//{
712//public:
713//
714//
715// ::pointer<TYPE> m_p;
716//
717//
718// //TYPE * ();
719//
720//
721//};
722
723
724
725
726//template < typename SEQUENCE >
727//sequencer < SEQUENCE > ::sequencer()
728//{
729//
730// //m_ptask = ::get_task();
731//
732// m_phappening = nullptr;
733//
734//}
735
736
737//template < typename TYPE >
738//void future < RESULT > ::set_object(const RESULT& result, const ::e_status & estatus)
739//{
740//
741// critical_section_lock lock(::platform::get()->sequence_critical_section());
742//
743// if (m_p.m_estatus == error_not_initialized)
744// {
745//
746// m_p.m_estatus = estatus;
747//
748// m_p.m_result = result;
749//
750// if (m_phappening)
751// {
752//
753// m_phappening->set_happening();
754//
755// }
756//
757// if (m_preceptor)
758// {
759//
760// m_preceptor->get(this);
761//
762// }
763//
764// }
765//
766//}
767
768//
769//template < typename SEQUENCE >
770//void sequencer < SEQUENCE > ::fork()
771//{
772//
773// fork(this, [this]()
774// {
775//
776// on_sequence();
777//
778// });
779//
780//}
781
782//
783//template < typename SEQUENCE >
784//void sequencer < SEQUENCE > ::on_sequence()
785//{
786//
787// critical_section_lock lock(::platform::get()->sequence_critical_section());
788//
789// if (m_phappening)
790// {
791//
792// m_phappening->set_happening();
793//
794// }
795//
796// if(m_stepa.has_element())
797// {
798//
799// ::pointer < sequencer < SEQUENCE > > psequencer(this);
800//
801// auto step = m_stepa.pop_first();
802//
803// lock.unlock();
804//
805// auto λ = [this, step, psequencer]
806// {
807//
808// step(m_psequence);
809//
810// psequencer->on_sequence();
811//
812// };
813//
814// m_papplication->post_procedure(λ);
815//
816// }
817// else
818// {
819//
820// m_psequence.release();
821//
822// }
823//
824//}
825//
826
827//template < typename SEQUENCE >
828//void sequencer < SEQUENCE > ::set_status(const ::e_status & estatus)
829//{
830//
831// critical_section_lock lock(::platform::get()->sequence_critical_section());
832//
833// m_p.m_estatus = estatus;
834//
835// if (m_phappening)
836// {
837//
838// m_phappening->set_happening();
839//
840// }
841//
842// increment_reference_count();
843//
844// system()->fork(__routine([this]()
845// {
846//
847// auto pHold = ::pointer_transfer(this);
848//
849// critical_section_lock lock(::platform::get()->sequence_critical_section());
850//
851// while (m_stepa.has_element())
852// {
853//
854// auto pfunction = m_stepa.pop_first();
855//
856// lock.unlock();
857//
858// pfunction->process(*this);
859//
860// lock.lock();
861//
862// }
863//
864// }));
865//
866//}
867
868
869//
870//template < typename SEQUENCE >
871//sequence < SEQUENCE > * sequencer < SEQUENCE > ::then(const sequence_step < SEQUENCE > & step)
872//{
873//
874// critical_section_lock lock(::platform::get()->sequence_critical_section());
875//
876// if (m_psequence.is_set())
877// {
878//
879// m_stepa.add(step);
880//
881// }
882// else
883// {
884//
885// lock.unlock();
886//
887// step(m_psequence);
888//
889// }
890//
891// return m_psequence;
892//
893//}
894//
895//
896//template < typename SEQUENCE >
897//sequence < SEQUENCE > * sequencer < SEQUENCE > ::then(const class time & timeWait, const sequence_step < SEQUENCE > & step)
898//{
899//
900// critical_section_lock lock(::platform::get()->sequence_critical_section());
901//
902// if (m_psequence.m_estatus == error_not_initialized)
903// {
904//
905// m_stepa.add(step);
906//
907// m_phappening = allocateø manual_reset_happening();
908//
909// lock.unlock();
910//
911// if (!m_phappening->wait(timeWait))
912// {
913//
914// lock.lock();
915//
916// if (m_psequence.m_estatus == error_not_initialized)
917// {
918//
919// m_psequence.m_estatus = error_timeout;
920//
921// }
922//
923// lock.unlock();
924//
925// if (m_psequence.m_estatus == error_timeout)
926// {
927//
928// step(m_psequence);
929//
930// }
931//
932// }
933//
934// }
935// else
936// {
937//
938// lock.unlock();
939//
940// step(m_psequence);
941//
942// }
943//
944// return m_psequence;
945//
946//}
947//
948//
949//template < typename SEQUENCE >
950//sequence < SEQUENCE > * sequencer < SEQUENCE > ::topic(const class time & timeWait)
951//{
952//
953// critical_section_lock lock(::platform::get()->sequence_critical_section());
954//
955// if (m_psequence.m_estatus == error_not_initialized)
956// {
957//
958// m_phappening = allocateø manual_reset_happening();
959//
960// if (!m_phappening->wait(timeWait))
961// {
962//
963// lock.lock();
964//
965// if (m_psequence.m_estatus == error_not_initialized)
966// {
967//
968// m_psequence.m_estatus = error_timeout;
969//
970// }
971//
972// lock.unlock();
973//
974// }
975//
976// }
977//
978// return this->m_p;
979//
980//}
981//
982//
983//template < typename SEQUENCE >
984//::e_status sequencer < SEQUENCE > ::wait(const class time & timeWait)
985//{
986//
987// critical_section_lock lock(::platform::get()->sequence_critical_section());
988//
989// if (m_psequence.m_estatus == error_not_initialized)
990// {
991//
992// m_phappening = allocateø manual_reset_happening();
993//
994// lock.unlock();
995//
996// if (!m_phappening->wait(timeWait))
997// {
998//
999// lock.lock();
1000//
1001// if (m_psequence.m_estatus == error_not_initialized)
1002// {
1003//
1004// m_psequence.m_estatus = error_wait_timeout;
1005//
1006// }
1007//
1008// lock.unlock();
1009//
1010// }
1011//
1012// }
1013//
1014// return m_psequence.m_estatus;
1015//
1016//}
1017//
1018
Definition procedure_array.h:60
Definition waiting_call.h:10