Ignore:
Timestamp:
Oct 9, 2023, 1:02:03 PM (9 months ago)
Author:
caparsons <caparson@…>
Branches:
master
Children:
cf3da24
Parents:
72b518fc
Message:

Changed cofor files to support the corun statement

Location:
libcfa/src/concurrency
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/cofor.cfa

    r72b518fc ree9ad40  
    44// cofor ( uC++ COFOR )
    55
    6 thread co_runner {
     6thread cofor_runner {
    77        ssize_t low, high;
    88        __cofor_body_t loop_body;
    99};
    1010
    11 static void ?{}( co_runner & this, ssize_t low, ssize_t high, __cofor_body_t loop_body ) {
     11static void ?{}( cofor_runner & this, ssize_t low, ssize_t high, __cofor_body_t loop_body ) {
    1212        this.low = low;
    1313        this.high = high;
     
    1515}
    1616
    17 void main( co_runner & this ) with( this ) {
     17void main( cofor_runner & this ) with( this ) {
    1818        for ( ssize_t i = low; i < high; i++ )
    1919                loop_body(i);
     
    2929        ssize_t i = 0;
    3030        ssize_t stride_iter = low;
    31         co_runner * runners[ threads ];
     31        cofor_runner * runners[ threads ];
    3232        for ( i; threads ) {
    3333                runners[i] = alloc();
     
    4545}
    4646
    47 //////////////////////////////////////////////////////////////////////////////////////////
    48 // parallel (COBEGIN/COEND)
    4947
    50 thread para_runner {
    51         parallel_stmt_t body;
    52         void * arg;
    53 };
    54 
    55 static void ?{}( para_runner & this, parallel_stmt_t body, void * arg ) {
    56         this.body = body;
    57         this.arg = arg;
    58 }
    59 
    60 void main( para_runner & this ) with( this ) { body( arg ); }
    61 
    62 void parallel( parallel_stmt_t * stmts, void ** args, size_t num ) libcfa_public {
    63         para_runner * runners[ num ];
    64         for ( i; num )
    65                 (*(runners[i] = malloc())){ stmts[i], args[i] };
    66         for ( i; num )
    67                 delete( runners[i] );
    68 }
    69 
  • libcfa/src/concurrency/cofor.hfa

    r72b518fc ree9ad40  
    1616
    1717//////////////////////////////////////////////////////////////////////////////////////////
    18 // parallel (COBEGIN/COEND)
    19 typedef void (*parallel_stmt_t)( void * );
     18// corun
    2019
    21 void parallel( parallel_stmt_t * stmts, void ** args, size_t num );
     20//
     21typedef void (*__CFA_corun_lambda_t)( void );
     22
     23// used to run a corun statement in parallel
     24thread co_runner {
     25        __CFA_corun_lambda_t body;
     26};
     27
     28// wraps a co_runner to provide RAII deallocation
     29struct runner_block {
     30    co_runner * runner;
     31};
     32static inline void ?{}( co_runner & this, __CFA_corun_lambda_t body ) { this.body = body; }
     33
     34void main( co_runner & this ) with( this ) { body(); }
     35
     36static inline void ?{}( runner_block & this ) {}
     37static inline void ?{}( runner_block & this, __CFA_corun_lambda_t body ) {
     38    (*(this.runner = malloc())){ body };
     39}
     40
     41static inline void ^?{}( runner_block & this ) {
     42    delete( this.runner );
     43}
     44
Note: See TracChangeset for help on using the changeset viewer.