Last change
on this file since 8941b6b was ee9ad40, checked in by caparsons <caparson@…>, 2 years ago |
Changed cofor files to support the corun statement
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[1ed5e9e] | 1 | #include <thread.hfa>
|
---|
| 2 |
|
---|
| 3 | //////////////////////////////////////////////////////////////////////////////////////////
|
---|
| 4 | // cofor ( uC++ COFOR )
|
---|
[e4c3819] | 5 | typedef void (*__cofor_body_t)( ssize_t );
|
---|
[1ed5e9e] | 6 |
|
---|
[11ab0b4a] | 7 | void __Cofor__( ssize_t low, ssize_t high, __cofor_body_t loop_body );
|
---|
[1ed5e9e] | 8 |
|
---|
[e4c3819] | 9 | #define COFOR( lidname, low, high, loopbody ) \
|
---|
| 10 | { \
|
---|
| 11 | void __CFA_loopLambda__( ssize_t lidname ) { \
|
---|
| 12 | loopbody \
|
---|
| 13 | } \
|
---|
[11ab0b4a] | 14 | __Cofor__( low, high, __CFA_loopLambda__ ); \
|
---|
[e4c3819] | 15 | }
|
---|
[334e0cf2] | 16 |
|
---|
[1ed5e9e] | 17 | //////////////////////////////////////////////////////////////////////////////////////////
|
---|
[ee9ad40] | 18 | // corun
|
---|
| 19 |
|
---|
| 20 | //
|
---|
| 21 | typedef void (*__CFA_corun_lambda_t)( void );
|
---|
| 22 |
|
---|
| 23 | // used to run a corun statement in parallel
|
---|
| 24 | thread co_runner {
|
---|
| 25 | __CFA_corun_lambda_t body;
|
---|
| 26 | };
|
---|
| 27 |
|
---|
| 28 | // wraps a co_runner to provide RAII deallocation
|
---|
| 29 | struct runner_block {
|
---|
| 30 | co_runner * runner;
|
---|
| 31 | };
|
---|
| 32 | static inline void ?{}( co_runner & this, __CFA_corun_lambda_t body ) { this.body = body; }
|
---|
| 33 |
|
---|
| 34 | void main( co_runner & this ) with( this ) { body(); }
|
---|
| 35 |
|
---|
| 36 | static inline void ?{}( runner_block & this ) {}
|
---|
| 37 | static inline void ?{}( runner_block & this, __CFA_corun_lambda_t body ) {
|
---|
| 38 | (*(this.runner = malloc())){ body };
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | static inline void ^?{}( runner_block & this ) {
|
---|
| 42 | delete( this.runner );
|
---|
| 43 | }
|
---|
[1ed5e9e] | 44 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.