Esempio n. 1
0
 /**
  * Get a copy of the Data (non allocating).
  * If pull has reserved enough memory to store the copy,
  * no memory will be allocated.
  *
  * @param pull A copy of the data.
  */
 virtual void Get( DataType& pull ) const
 {
     PtrType reading;
     // loop to combine Read/Modify of counter
     // This avoids a race condition where read_ptr
     // could become write_ptr ( then we would read corrupted data).
     do {
         reading = read_ptr;            // copy buffer location
         oro_atomic_inc(&reading->counter); // lock buffer, no more writes
         if ( reading != read_ptr )     // if read_ptr changed,
             oro_atomic_dec(&reading->counter); // better to start over.
         else
             break;
     } while ( true );
     // from here on we are sure that 'reading'
     // is a valid buffer to read from.
     pull = reading->data;               // takes some time
     oro_atomic_dec(&reading->counter);       // release buffer
 }
Esempio n. 2
0
 void dec() { oro_atomic_dec( &_val ); }