Ignore:
Timestamp:
May 2, 2018, 4:18:37 PM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, with_gc
Children:
68e9ace
Parents:
6d539f83
Message:

use forall distribution for buffer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tests/concurrent/examples/boundedBufferEXT.c

    r6d539f83 r623c16a  
    88// Created On       : Wed Apr 18 22:52:12 2018
    99// Last Modified By : Peter A. Buhr
    10 // Last Modified On : Fri Apr 20 22:25:14 2018
    11 // Update Count     : 6
     10// Last Modified On : Wed May  2 16:12:58 2018
     11// Update Count     : 7
    1212//
    1313
     
    2222enum { BufferSize = 50 };
    2323
    24 forall( otype T )
    25 monitor Buffer {
    26         int front, back, count;
    27         T elements[BufferSize];
    28 };
     24forall( otype T ) {
     25        monitor Buffer {
     26                int front, back, count;
     27                T elements[BufferSize];
     28        }; // Buffer
    2929
    30 forall( otype T )
    31 void ?{}( Buffer(T) & buffer ) with( buffer ) { [front, back, count] = 0; }
     30        void ?{}( Buffer(T) & buffer ) with( buffer ) { [front, back, count] = 0; }
    3231
    33 forall( otype T )
    34 int query( Buffer(T) & buffer ) { return buffer.count; }
     32        int query( Buffer(T) & buffer ) { return buffer.count; } // read-only, no mutual exclusion
    3533
    36 forall( otype T )                                                                               // forward
    37 T remove( Buffer(T) & mutex buffer );
     34        T remove( Buffer(T) & mutex buffer );                           // forward
    3835
    39 forall( otype T )
    40 void insert( Buffer(T) & mutex buffer, T elem ) with( buffer ) {
    41         if ( count == BufferSize ) waitfor( remove, buffer );
    42         elements[back] = elem;
    43         back = ( back + 1 ) % BufferSize;
    44         count += 1;
    45 }
     36        void insert( Buffer(T) & mutex buffer, T elem ) with( buffer ) {
     37                if ( count == BufferSize ) waitfor( remove, buffer );
     38                elements[back] = elem;
     39                back = ( back + 1 ) % BufferSize;
     40                count += 1;
     41        } // insert
    4642
    47 forall( otype T )
    48 T remove( Buffer(T) & mutex buffer ) with( buffer ) {
    49         if ( count == 0 ) waitfor( insert, buffer );
    50         T elem = elements[front];
    51         front = ( front + 1 ) % BufferSize;
    52         count -= 1;
    53         return elem;
     43        T remove( Buffer(T) & mutex buffer ) with( buffer ) {
     44                if ( count == 0 ) waitfor( insert, buffer );
     45                T elem = elements[front];
     46                front = ( front + 1 ) % BufferSize;
     47                count -= 1;
     48                return elem;
     49        } // remove
    5450}
    5551
Note: See TracChangeset for help on using the changeset viewer.