Last change
on this file since 3ef5905 was
77fd9fe2,
checked in by caparsons <caparson@…>, 14 months ago
|
refactored actor tests to use bar operator
|
-
Property mode set to
100644
|
File size:
1.4 KB
|
Rev | Line | |
---|
[dab2b6a] | 1 | #include <actor.hfa> |
---|
| 2 | #include <fstream.hfa> |
---|
| 3 | #include <stdlib.hfa> |
---|
| 4 | #include <string.h> |
---|
| 5 | #include <stdio.h> |
---|
| 6 | |
---|
[1f35220] | 7 | int Times = 1000000; // default values |
---|
[dab2b6a] | 8 | |
---|
[4933f18] | 9 | struct derived_actor { inline actor; }; |
---|
[dab2b6a] | 10 | struct derived_msg { |
---|
| 11 | inline message; |
---|
| 12 | int cnt; |
---|
| 13 | }; |
---|
| 14 | |
---|
| 15 | void ?{}( derived_msg & this, int cnt ) { |
---|
| 16 | ((message &) this){ Delete }; |
---|
| 17 | this.cnt = cnt; |
---|
| 18 | } |
---|
| 19 | void ?{}( derived_msg & this ) { ((derived_msg &)this){ 0 }; } |
---|
| 20 | |
---|
[c880a7b] | 21 | allocation receive( derived_actor & receiver, derived_msg & msg ) { |
---|
[dab2b6a] | 22 | if ( msg.cnt >= Times ) { |
---|
| 23 | sout | "Done"; |
---|
| 24 | return Delete; |
---|
| 25 | } |
---|
| 26 | derived_msg * d_msg = alloc(); |
---|
| 27 | (*d_msg){ msg.cnt + 1 }; |
---|
| 28 | derived_actor * d_actor = alloc(); |
---|
| 29 | (*d_actor){}; |
---|
[77fd9fe2] | 30 | *d_actor | *d_msg; |
---|
[dab2b6a] | 31 | return Delete; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | int main( int argc, char * argv[] ) { |
---|
| 35 | switch ( argc ) { |
---|
| 36 | case 2: |
---|
| 37 | if ( strcmp( argv[1], "d" ) != 0 ) { // default ? |
---|
| 38 | Times = atoi( argv[1] ); |
---|
| 39 | if ( Times < 1 ) goto Usage; |
---|
| 40 | } // if |
---|
| 41 | case 1: // use defaults |
---|
| 42 | break; |
---|
| 43 | default: |
---|
| 44 | Usage: |
---|
| 45 | sout | "Usage: " | argv[0] | " [ times (> 0) ]"; |
---|
| 46 | exit( EXIT_FAILURE ); |
---|
| 47 | } // switch |
---|
| 48 | |
---|
| 49 | printf("starting\n"); |
---|
| 50 | |
---|
| 51 | executor e{ 0, 1, 1, false }; |
---|
| 52 | start_actor_system( e ); |
---|
| 53 | |
---|
| 54 | printf("started\n"); |
---|
| 55 | |
---|
| 56 | derived_msg * d_msg = alloc(); |
---|
| 57 | (*d_msg){}; |
---|
| 58 | derived_actor * d_actor = alloc(); |
---|
| 59 | (*d_actor){}; |
---|
[77fd9fe2] | 60 | *d_actor | *d_msg; |
---|
[dab2b6a] | 61 | |
---|
| 62 | printf("stopping\n"); |
---|
| 63 | |
---|
| 64 | stop_actor_system(); |
---|
| 65 | |
---|
| 66 | printf("stopped\n"); |
---|
| 67 | |
---|
| 68 | return 0; |
---|
| 69 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.