Ignore:
Timestamp:
Dec 4, 2020, 11:49:34 AM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/bits/multi_list.cfa

    r36ec816 r3c6480b7  
    22#include <stdlib.hfa>
    33#include "sequence.hfa"
     4#include "queue.hfa"
    45#include "stack.hfa"
    56
     
    89struct TaskDL {
    910        inline Seqable;
    10         Task & task_;
     11        Task & node;
    1112};
    1213void ?{}( TaskDL & this, Task & task ) with( this ) {
    1314        ((Seqable &)this){};
    14         &task_ = &task;                                                                         // pointer to containing node
     15        &node = &task;                                                                          // pointer to containing node
    1516}
    1617Task & task( TaskDL & this ) with( this ) {                             // getter routine for containing node
    17         return task_;
     18        return node;
     19}
     20
     21struct TaskSL {
     22        inline Colable;
     23        Task & node;
     24};
     25void ?{}( TaskSL & this, Task & task ) with( this ) {
     26        ((Colable &)this){};
     27        &node = &task;                                                                          // pointer to containing node
     28}
     29Task & task( TaskSL & this ) with( this ) {                             // getter routine for containing node
     30        return node;
    1831}
    1932
     
    2134        TaskDL clusterRef;                                                                      // list of tasks on cluster
    2235        TaskDL readyRef;                                                                        // list of tasks on ready queue
    23         // other stuff
     36        TaskSL mutexRef;                                                                        // list of tasks on mutex queue
     37        int id;
    2438};
    25 void ?{}( Task & this ) with( this ) {
     39void ?{}( Task & this, int id ) with( this ) {
    2640        ((TaskDL &)clusterRef){ this };
    2741        ((TaskDL &)readyRef){ this };
     42        ((TaskSL &)mutexRef){ this };
     43        this.id = id;
    2844}
    2945
    3046int main() {
    3147        Sequence(TaskDL) clustList, readyList;                          // task lists
     48        Queue(TaskSL) mutexList;
    3249        enum { Lnth = 10 };
    3350
    34         for ( Lnth ) {
    35                 Task & task = *new();                                                   // create task node
     51        for ( id; Lnth ) {
     52                Task & task = *new( id );                                               // create task node
    3653                addHead( clustList, task.clusterRef );                  // insert on lists in opposite directions
    3754                addTail( readyList, task.readyRef );
     55                addHead( mutexList, task.mutexRef );
    3856        }
    3957
    40         SeqIter(TaskDL) iter;
     58        SeqIter(TaskDL) sqiter;
    4159        TaskDL & dl;
     60        TaskSL & sl;
    4261
    4362        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;
    4666        }
    4767        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;
    5071        }
    5172        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
    5379                dropHead( clustList );
     80                drop( mutexList );
    5481        }
     82        // Simultaneous deletion only safe if all nodes are traversed in same direction.
    5583        for ( Lnth ) {                                                                          // remove nodes from readyList and safe to delete nodes
    5684                delete( &task( dropHead( readyList ) ) );
    5785        }
    5886
    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        }
    64101}
Note: See TracChangeset for help on using the changeset viewer.