Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/concurrency/actors/executor.cfa

    r77fd9fe2 r7edf912  
    1010static int ids = 0;
    1111struct d_actor {
    12     inline actor;
    13     d_actor * gstart;
    14     int id, rounds, recs, sends;
     12        inline actor;
     13        d_actor * gstart;
     14        int id, rounds, recs, sends;
    1515};
    1616void ?{}( d_actor & this ) with(this) {
    17     id = ids++;
    18     gstart = (&this + (id / Set * Set - id)); // remember group-start array-element
    19     rounds = Set * Rounds;      // send at least one message to each group member
    20     recs = 0;
    21     sends = 0;
     17        id = ids++;
     18        gstart = (&this + (id / Set * Set - id)); // remember group-start array-element
     19        rounds = Set * Rounds;  // send at least one message to each group member
     20        recs = 0;
     21        sends = 0;
    2222}
    2323
     
    2525
    2626allocation receive( d_actor & this, d_msg & msg ) with( this ) {
    27     if ( recs == rounds ) return Finished;
    28     if ( recs % Batch == 0 ) {
    29         for ( i; Batch ) {
    30             gstart[sends % Set] | shared_msg;
    31             sends += 1;
    32         }
    33     }
    34     recs += 1;
    35     return Nodelete;
     27        if ( recs == rounds ) return Finished;
     28        if ( recs % Batch == 0 ) {
     29                for ( i; Batch ) {
     30                        gstart[sends % Set] | shared_msg;
     31                        sends += 1;
     32                }
     33        }
     34        recs += 1;
     35        return Nodelete;
    3636}
    3737
    3838int main( int argc, char * argv[] ) {
    39     switch ( argc ) {
     39        switch ( argc ) {
    4040          case 7:
    4141                if ( strcmp( argv[6], "d" ) != 0 ) {                    // default ?
    42                         BufSize = atoi( argv[6] );
    43                         if ( BufSize < 0 ) goto Usage;
     42                        BufSize = ato( argv[6] );
     43                        if ( BufSize < 0 ) fallthru default;
    4444                } // if
    4545          case 6:
    4646                if ( strcmp( argv[5], "d" ) != 0 ) {                    // default ?
    47                         Batch = atoi( argv[5] );
    48                         if ( Batch < 1 ) goto Usage;
     47                        Batch = ato( argv[5] );
     48                        if ( Batch < 1 ) fallthru default;
    4949                } // if
    5050          case 5:
    5151                if ( strcmp( argv[4], "d" ) != 0 ) {                    // default ?
    52                         Processors = atoi( argv[4] );
    53                         if ( Processors < 1 ) goto Usage;
     52                        Processors = ato( argv[4] );
     53                        if ( Processors < 1 ) fallthru default;
    5454                } // if
    5555          case 4:
    5656                if ( strcmp( argv[3], "d" ) != 0 ) {                    // default ?
    57                         Rounds = atoi( argv[3] );
    58                         if ( Rounds < 1 ) goto Usage;
     57                        Rounds = ato( argv[3] );
     58                        if ( Rounds < 1 ) fallthru default;
    5959                } // if
    6060          case 3:
    6161                if ( strcmp( argv[2], "d" ) != 0 ) {                    // default ?
    62                         Set = atoi( argv[2] );
    63                         if ( Set < 1 ) goto Usage;
     62                        Set = ato( argv[2] );
     63                        if ( Set < 1 ) fallthru default;
    6464                } // if
    6565          case 2:
    6666                if ( strcmp( argv[1], "d" ) != 0 ) {                    // default ?
    67                         Actors = atoi( argv[1] );
    68                         if ( Actors < 1 || Actors <= Set || Actors % Set != 0 ) goto Usage;
     67                        Actors = ato( argv[1] );
     68                        if ( Actors < 1 || Actors <= Set || Actors % Set != 0 ) fallthru default;
    6969                } // if
    7070          case 1:                                                                                       // use defaults
    7171                break;
    7272          default:
    73           Usage:
    74                 sout | "Usage: " | argv[0]
    75              | " [ actors (> 0 && > set && actors % set == 0 ) | 'd' (default " | Actors
     73                exit | "Usage: " | argv[0]
     74                         | " [ actors (> 0 && > set && actors % set == 0 ) | 'd' (default " | Actors
    7675                         | ") ] [ set (> 0) | 'd' (default " | Set
    7776                         | ") ] [ rounds (> 0) | 'd' (default " | Rounds
     
    8079                         | ") ] [ buffer size (>= 0) | 'd' (default " | BufSize
    8180                         | ") ]" ;
    82                 exit( EXIT_FAILURE );
    8381        } // switch
    8482
    85     executor e{ Processors, Processors, Processors == 1 ? 1 : Processors * 512, true };
     83        executor e{ Processors, Processors, Processors == 1 ? 1 : Processors * 512, true };
    8684
    87     printf("starting\n");
     85        sout | "starting";
    8886
    89     start_actor_system( e );
     87        start_actor_system( e );
    9088
    91     printf("started\n");
     89        sout | "started";
    9290
    93     d_actor actors[ Actors ];
     91        d_actor actors[ Actors ];
    9492
    9593        for ( i; Actors ) {
     
    9795        } // for
    9896
    99     printf("stopping\n");
     97        sout | "stopping";
    10098
    101     stop_actor_system();
     99        stop_actor_system();
    102100
    103     printf("stopped\n");
    104 
    105     return 0;
     101        sout | "stopped";
    106102}
Note: See TracChangeset for help on using the changeset viewer.