Ignore:
File:
1 edited

Legend:

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

    r948887f r971d9f2  
    88// Created On       : Mon Oct 30 12:45:13 2017
    99// Last Modified By : Peter A. Buhr
    10 // Last Modified On : Mon Oct 30 23:02:46 2017
    11 // Update Count     : 9
     10// Last Modified On : Tue Dec  5 23:01:51 2017
     11// Update Count     : 10
    1212//
    1313
     
    3030int query( Buffer & buffer ) { return buffer.count; }
    3131
    32 void insert( Buffer & mutex buffer, int elem ) {
    33         if ( buffer.count == 20 ) wait( buffer.empty );
    34         buffer.elements[buffer.back] = elem;
    35         buffer.back = ( buffer.back + 1 ) % 20;
    36         buffer.count += 1;
    37         signal( buffer.full );
     32void insert( Buffer & mutex buffer, int elem ) with( buffer ) {
     33        if ( count == 20 ) wait( empty );
     34        elements[back] = elem;
     35        back = ( back + 1 ) % 20;
     36        count += 1;
     37        signal( full );
    3838}
    39 int remove( Buffer & mutex buffer ) {
    40         if ( buffer.count == 0 ) wait( buffer.full );
    41         int elem = buffer.elements[buffer.front];
    42         buffer.front = ( buffer.front + 1 ) % 20;
    43         buffer.count -= 1;
    44         signal( buffer.empty );
     39int remove( Buffer & mutex buffer ) with( buffer ) {
     40        if ( count == 0 ) wait( full );
     41        int elem = elements[front];
     42        front = ( front + 1 ) % 20;
     43        count -= 1;
     44        signal( empty );
    4545        return elem;
    4646}
Note: See TracChangeset for help on using the changeset viewer.