Changeset 3c6480b7 for libcfa/src/bits/multi_list.cfa
- Timestamp:
- Dec 4, 2020, 11:49:34 AM (3 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- fe3d9ab
- Parents:
- 36ec816 (diff), 54f89d5 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/bits/multi_list.cfa
r36ec816 r3c6480b7 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 SeqIter(TaskDL) iter;58 SeqIter(TaskDL) sqiter; 41 59 TaskDL & dl; 60 TaskSL & sl; 42 61 43 62 sout | nlOff; 44 for ( over( iter, clustList ); iter >> dl; ) { // print lists 45 sout | &task( dl ); 63 for ( over( sqiter, clustList ); sqiter >> dl; ) { // print lists 64 Task & tmp = task( dl ); sout | tmp.id; 65 // sout | task( dl ).id; 46 66 } 47 67 sout | nl; 48 for ( SeqIter(TaskDL) iter = { readyList }; iter >> dl; ) { 49 sout | &task( dl ); 68 for ( over( sqiter, readyList ); sqiter >> dl; ) { 69 Task & tmp = task( dl ); sout | tmp.id; 70 // sout | task( dl ).id; 50 71 } 51 72 sout | nl; 52 for ( Lnth ) { // remove nodes from clustList 73 for ( QueueIter(TaskSL) qiter = { mutexList }; qiter >> sl; ) { // print lists 74 Task & tmp = task( sl ); sout | tmp.id; 75 // sout | task( sl ).id; 76 } 77 sout | nl; 78 for ( Lnth ) { // remove nodes from clustList. mutexList 53 79 dropHead( clustList ); 80 drop( mutexList ); 54 81 } 82 // Simultaneous deletion only safe if all nodes are traversed in same direction. 55 83 for ( Lnth ) { // remove nodes from readyList and safe to delete nodes 56 84 delete( &task( dropHead( readyList ) ) ); 57 85 } 58 86 59 // Stack(TaskDL) fredStack; 60 // for ( Lnth ) { 61 // Task & task = *new(); // create task node 62 // push( fredStack, task.clusterRef ); // insert on lists in opposite directions 63 // } 87 // Re-purpose Seqable as Colable 88 Stack(TaskDL) mutexStack; 89 for ( id; Lnth ) { 90 Task & task = *new( id ); // create task node 91 push( mutexStack, task.clusterRef ); // insert on lists in opposite directions 92 } 93 for ( StackIter(TaskDL) stiter = { mutexStack }; stiter >> dl; ) { 94 Task & tmp = task( dl ); sout | tmp.id; 95 // sout | task( dl ).id; 96 } 97 sout | nl; 98 for ( Lnth ) { // remove nodes from readyList and safe to delete nodes 99 delete( &task( pop( mutexStack ) ) ); 100 } 64 101 }
Note: See TracChangeset
for help on using the changeset viewer.