Changeset f7386f7
- Timestamp:
- Dec 4, 2020, 8:25:37 AM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 4f649cb
- Parents:
- 1ac1f0b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/bits/multi_list.cfa
r1ac1f0b rf7386f7 2 2 #include <stdlib.hfa> 3 3 #include "sequence.hfa" 4 #include "queue.hfa" 4 5 #include "stack.hfa" 5 6 … … 8 9 struct TaskDL { 9 10 inline Seqable; 10 Task & task_;11 Task & node; 11 12 }; 12 13 void ?{}( TaskDL & this, Task & task ) with( this ) { 13 14 ((Seqable &)this){}; 14 & task_= &task; // pointer to containing node15 &node = &task; // pointer to containing node 15 16 } 16 17 Task & task( TaskDL & this ) with( this ) { // getter routine for containing node 17 return task_; 18 return node; 19 } 20 21 struct TaskSL { 22 inline Colable; 23 Task & node; 24 }; 25 void ?{}( TaskSL & this, Task & task ) with( this ) { 26 ((Colable &)this){}; 27 &node = &task; // pointer to containing node 28 } 29 Task & task( TaskSL & this ) with( this ) { // getter routine for containing node 30 return node; 18 31 } 19 32 … … 21 34 TaskDL clusterRef; // list of tasks on cluster 22 35 TaskDL readyRef; // list of tasks on ready queue 23 // other stuff 36 TaskSL mutexRef; // list of tasks on mutex queue 37 int id; 24 38 }; 25 void ?{}( Task & this ) with( this ) {39 void ?{}( Task & this, int id ) with( this ) { 26 40 ((TaskDL &)clusterRef){ this }; 27 41 ((TaskDL &)readyRef){ this }; 42 ((TaskSL &)mutexRef){ this }; 43 this.id = id; 28 44 } 29 45 30 46 int main() { 31 47 Sequence(TaskDL) clustList, readyList; // task lists 48 Queue(TaskSL) mutexList; 32 49 enum { Lnth = 10 }; 33 50 34 for ( Lnth ) {35 Task & task = *new( );// create task node51 for ( id; Lnth ) { 52 Task & task = *new( id ); // create task node 36 53 addHead( clustList, task.clusterRef ); // insert on lists in opposite directions 37 54 addTail( readyList, task.readyRef ); 55 addHead( mutexList, task.mutexRef ); 38 56 } 39 57 40 58 SeqIter(TaskDL) sqiter; 41 59 TaskDL & dl; 60 TaskSL & sl; 42 61 43 62 sout | nlOff; 44 for ( over( sqiter, clustList ); sqiter >> dl; ) { // print lists 63 for ( over( sqiter, clustList ); sqiter >> dl; ) { // print lists 64 Task & fred = task( dl ); 65 sout | fred.id; // works 66 sout | task( dl ).id; // does not work 67 } 68 sout | nl; 69 for ( over( sqiter, readyList ); sqiter >> dl; ) { 45 70 sout | &task( dl ); 46 71 } 47 72 sout | nl; 48 for ( SeqIter(TaskDL) iter = { readyList }; iter >> dl; ) {49 sout | &task( dl );73 for ( QueueIter(TaskSL) qiter = { mutexList }; qiter >> sl; ) { // print lists 74 sout | &task( sl ); 50 75 } 51 76 sout | nl; 52 77 for ( Lnth ) { // remove nodes from clustList 53 78 dropHead( clustList ); 79 drop( mutexList ); 54 80 } 55 81 for ( Lnth ) { // remove nodes from readyList and safe to delete nodes … … 59 85 // Re-purpose Seqable as Colable 60 86 Stack(TaskDL) mutexStack; 61 for ( Lnth ) {62 Task & task = *new( );// create task node87 for ( id; Lnth ) { 88 Task & task = *new( id ); // create task node 63 89 push( mutexStack, task.clusterRef ); // insert on lists in opposite directions 64 90 }
Note: See TracChangeset
for help on using the changeset viewer.