medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 2344de768015b2fa90ae555e45474d7b58cc5539
parent f728e46141cf91b103e25b1557fbc8bc74cf6005
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Thu Sep  1 13:22:53 -0700

Allow any SPSC queue size

Diffstat:
nonblocking_fixed_spsc_queue.h | 14+++++---------
relacy.cc | 2+-
2 files changed, 6 insertions(+), 10 deletions(-)
diff --git a/nonblocking_fixed_spsc_queue.h b/nonblocking_fixed_spsc_queue.h @@ -8,10 +8,6 @@ template< typename T, u64 N > class NonblockingFixedSPSCQueue : public NonblockingQueue< T > { - // N really only needs to divide U64_MAX but requiring a power of 2 is - // not a problem - static_assert( is_power_of_2( N ) ); - public: NonblockingFixedSPSCQueue() { clear(); @@ -19,12 +15,12 @@ public: // returns true if x was enqueued, false if the queue was full bool enqueue( const T & x ) { - u64 w = VAR( writer_pos ) % N; + size_t w = VAR( writer_pos ); if( load_acquire( &nodes[ w ].last_op ) == WRITE ) return false; nodes[ w ].data = x; store_release( &nodes[ w ].last_op, WRITE ); - VAR( writer_pos )++; + VAR( writer_pos ) = ( w + 1 ) % N; return true; } @@ -35,7 +31,7 @@ public: T * dequeue_acquire() { // assert( !reader_acquired ); - u64 r = VAR( reader_pos ) % N; + size_t r = VAR( reader_pos ); if( load_acquire( &nodes[ r ].last_op ) == READ ) return NULL; VAR( reader_acquired ) = true; @@ -46,9 +42,9 @@ public: // assert( reader_acquired ); VAR( reader_acquired ) = false; - u64 r = VAR( reader_pos ) % N; + size_t r = VAR( reader_pos ); store_release( &nodes[ r ].last_op, READ ); - VAR( reader_pos )++; + VAR( reader_pos ) = ( r + 1 ) % N; } void clear() { diff --git a/relacy.cc b/relacy.cc @@ -3,7 +3,7 @@ #include "intrinsics.h" #include "nonblocking_fixed_spsc_queue.h" -#define QUEUE_SIZE 64 +#define QUEUE_SIZE 67 #define ITERS 256 struct NonblockingFixedSPSCQueueTest : rl::test_suite< NonblockingFixedSPSCQueueTest, 2 > {