medfall

A super great game engine
Log | Files | Refs

relacy.cc (1292B)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "libs/relacy/relacy/pch.hpp"
#include "libs/relacy/relacy/relacy_std.hpp"
#include "intrinsics.h"
#include "nonblocking_fixed_spsc_queue.h"

#define QUEUE_SIZE 67
#define ITERS 256

struct NonblockingFixedSPSCQueueTest : rl::test_suite< NonblockingFixedSPSCQueueTest, 2 > {
	NonblockingFixedSPSCQueue< int, QUEUE_SIZE > q;

	void thread( unsigned int thread_index ) {
		if( thread_index == 0 ) {
			for( int i = 0; i < ITERS; i++ ) {
				int x;
				while( !q.dequeue( &x ) ) continue;
				RL_ASSERT( x == i );
			}
		}
		else {
			for( int i = 0; i < ITERS; i++ ) {
				while( !q.enqueue( i ) ) continue;
			}
		}
	}
};

struct NonblockingFixedSPSCQueueTestNoCopy : rl::test_suite< NonblockingFixedSPSCQueueTestNoCopy, 2 > {
	NonblockingFixedSPSCQueue< int, QUEUE_SIZE > q;

	void thread( unsigned int thread_index ) {
		if( thread_index == 0 ) {
			for( int i = 0; i < ITERS; i++ ) {
				for( ;; ) {
					int * x = q.dequeue_acquire();
					if( x == NULL ) continue;
					RL_ASSERT( *x == i );
					q.dequeue_release();
					break;
				}
			}
		}
		else {
			for( int i = 0; i < ITERS; i++ ) {
				while( !q.enqueue( i ) ) continue;
			}
		}
	}
};

int main() {
	rl::simulate< NonblockingFixedSPSCQueueTest >();
	rl::simulate< NonblockingFixedSPSCQueueTestNoCopy >();

	return 0;
}