|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r84387 - in trunk: boost/lockfree libs/lockfree/test
From: tim_at_[hidden]
Date: 2013-05-20 05:28:57
Author: timblechmann
Date: 2013-05-20 05:28:56 EDT (Mon, 20 May 2013)
New Revision: 84387
URL: http://svn.boost.org/trac/boost/changeset/84387
Log:
lockfree: spsc-queue - capacity should take the internal marker object into account
fixes #8560
Text files modified:
trunk/boost/lockfree/spsc_queue.hpp | 9 +++++----
trunk/libs/lockfree/test/spsc_queue_test.cpp | 21 ++++++++++++++++++---
2 files changed, 23 insertions(+), 7 deletions(-)
Modified: trunk/boost/lockfree/spsc_queue.hpp
==============================================================================
--- trunk/boost/lockfree/spsc_queue.hpp (original)
+++ trunk/boost/lockfree/spsc_queue.hpp 2013-05-20 05:28:56 EDT (Mon, 20 May 2013)
@@ -284,11 +284,12 @@
}
};
-template <typename T, std::size_t max_size>
+template <typename T, std::size_t MaxSize>
class compile_time_sized_ringbuffer:
public ringbuffer_base<T>
{
typedef std::size_t size_t;
+ static const std::size_t max_size = MaxSize + 1;
boost::array<T, max_size> array_;
public:
@@ -349,7 +350,7 @@
public:
explicit runtime_sized_ringbuffer(size_t max_elements):
- max_elements_(max_elements)
+ max_elements_(max_elements + 1)
{
// TODO: we don't necessarily need to construct all elements
array_ = Alloc::allocate(max_elements);
@@ -359,7 +360,7 @@
template <typename U>
runtime_sized_ringbuffer(typename Alloc::template rebind<U>::other const & alloc, size_t max_elements):
- Alloc(alloc), max_elements_(max_elements)
+ Alloc(alloc), max_elements_(max_elements + 1)
{
// TODO: we don't necessarily need to construct all elements
array_ = Alloc::allocate(max_elements);
@@ -368,7 +369,7 @@
}
runtime_sized_ringbuffer(Alloc const & alloc, size_t max_elements):
- Alloc(alloc), max_elements_(max_elements)
+ Alloc(alloc), max_elements_(max_elements + 1)
{
// TODO: we don't necessarily need to construct all elements
array_ = Alloc::allocate(max_elements);
Modified: trunk/libs/lockfree/test/spsc_queue_test.cpp
==============================================================================
--- trunk/libs/lockfree/test/spsc_queue_test.cpp (original)
+++ trunk/libs/lockfree/test/spsc_queue_test.cpp 2013-05-20 05:28:56 EDT (Mon, 20 May 2013)
@@ -131,6 +131,21 @@
output_iterator_
};
+BOOST_AUTO_TEST_CASE( spsc_queue_capacity_test )
+{
+ spsc_queue<int, capacity<2> > f;
+
+ BOOST_REQUIRE(f.push(1));
+ BOOST_REQUIRE(f.push(2));
+ BOOST_REQUIRE(!f.push(3));
+
+ spsc_queue<int> g(2);
+
+ BOOST_REQUIRE(g.push(1));
+ BOOST_REQUIRE(g.push(2));
+ BOOST_REQUIRE(!g.push(3));
+}
+
template <int EnqueueMode>
void spsc_queue_buffer_push_return_value(void)
@@ -162,15 +177,15 @@
switch (EnqueueMode) {
case pointer_and_size:
- BOOST_REQUIRE_EQUAL(rb.push(data, xqueue_size), buffer_size - xqueue_size - 1);
+ BOOST_REQUIRE_EQUAL(rb.push(data, xqueue_size), buffer_size - xqueue_size);
break;
case reference_to_array:
- BOOST_REQUIRE_EQUAL(rb.push(data), buffer_size - xqueue_size - 1);
+ BOOST_REQUIRE_EQUAL(rb.push(data), buffer_size - xqueue_size);
break;
case iterator_pair:
- BOOST_REQUIRE_EQUAL(rb.push(data, data + xqueue_size), data + buffer_size - xqueue_size - 1);
+ BOOST_REQUIRE_EQUAL(rb.push(data, data + xqueue_size), data + buffer_size - xqueue_size);
break;
default:
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk