source: tests/concurrency/actors/dynamic.cfa @ c2d728c

Last change on this file since c2d728c was 7edf912, checked in by Peter A. Buhr <pabuhr@…>, 14 months ago

formatting, replace constructor calls with set_allocation calls

  • Property mode set to 100644
File size: 1.3 KB
Line 
1#include <actor.hfa>
2#include <fstream.hfa>
3#include <stdlib.hfa>
4#include <string.h>
5#include <stdio.h>
6
7int Times = 1000000;                                                            // default values
8
9struct derived_actor { inline actor; };
10struct derived_msg {
11        inline message;
12        int cnt;
13};
14
15void ?{}( derived_msg & this, int cnt ) {
16        set_allocation( this, Delete );
17        this.cnt = cnt;
18}
19void ?{}( derived_msg & this ) { ((derived_msg &)this){ 0 }; }
20
21allocation receive( derived_actor & receiver, derived_msg & msg ) {
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){};
30        *d_actor | *d_msg;
31        return Delete;
32}
33
34int main( int argc, char * argv[] ) {
35        switch ( argc ) {
36          case 2:
37                if ( strcmp( argv[1], "d" ) != 0 ) {                    // default ?
38                        Times = ato( argv[1] );
39                        if ( Times < 1 ) fallthru default;
40                } // if
41          case 1:                                                                                       // use defaults
42                break;
43          default:
44                exit | "Usage: " | argv[0] | " [ times (> 0) ]";
45        } // switch
46
47        sout | "starting";
48
49        executor e{ 0, 1, 1, false };
50        start_actor_system( e );
51
52        sout | "started";
53
54        derived_msg * d_msg = alloc();
55        (*d_msg){};
56        derived_actor * d_actor = alloc();
57        (*d_actor){};
58        *d_actor | *d_msg;
59
60        sout | "stopping";
61
62        stop_actor_system();
63
64        sout | "stopped";
65}
Note: See TracBrowser for help on using the repository browser.