medfall

A super great game engine
Log | Files | Refs

spsc_relacy.cc (571B)


      1 #include "libs/relacy/relacy_cli.hpp"
      2 #include "spsc.h"
      3 
      4 struct FixedSPSCTest : rl::test_suite< FixedSPSCTest, 2 > {
      5 	FixedSPSC< int, 4 > spsc;
      6 
      7 	void thread( unsigned int thread_id ) {
      8 		if( thread_id == 0 ) {
      9 			int i = 0;
     10 			while( i < 10 ) {
     11 				if( spsc.enqueue( i ) )
     12 					i++;
     13 			}
     14 		}
     15 
     16 		if( thread_id == 1 ) {
     17 			int i = 0;
     18 			while( i < 10 ) {
     19 				int x;
     20 				if( spsc.dequeue( &x ) ) {
     21 					ATOMIC_ASSERT( x == i );
     22 					i++;
     23 				}
     24 			}
     25 		}
     26 	}
     27 };
     28 
     29 int main() {
     30 	rl::test_params p;
     31 	p.iteration_count = 200000;
     32 	rl::simulate< FixedSPSCTest >( p );
     33 	return 0;
     34 }
     35