summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/buffer_queue_circ.cpp13
-rw-r--r--lib/circular_buffer.cpp16
2 files changed, 21 insertions, 8 deletions
diff --git a/lib/buffer_queue_circ.cpp b/lib/buffer_queue_circ.cpp
index a75e0b0..60a2b51 100644
--- a/lib/buffer_queue_circ.cpp
+++ b/lib/buffer_queue_circ.cpp
@@ -9,6 +9,11 @@ using namespace gras;
SBuffer make_circular_buffer(const size_t num_bytes); //circular_buffer.cpp
+static void buffer_dummy_delete(SBuffer &, const SBuffer /*ref holder*/)
+{
+ //NOP
+}
+
struct BufferQueueCirc : BufferQueue
{
BufferQueueCirc(const SBufferConfig &config, const size_t num);
@@ -52,16 +57,20 @@ BufferQueueCirc::BufferQueueCirc(const SBufferConfig &config, const size_t num_b
_write_ptr = (char *)_circ_buff.get_actual_memory();
_bytes_avail = _circ_buff.get_actual_length();
+ //create dummy deleter to hold ref to circ buff
+ SBufferDeleter deleter = boost::bind(&buffer_dummy_delete, _1, _circ_buff);
+
//allocate pool of sbuffers
_available_buffers.set_capacity(num_buffs);
_returned_buffers.resize(num_buffs);
_outgone_bytes.resize(num_buffs, 0);
SBufferConfig sconfig = config;
+ sconfig.deleter = deleter;
sconfig.memory = _circ_buff.get_actual_memory();
- for (size_t i = 0; i < _available_buffers.size(); i++)
+ for (size_t i = 0; i < num_buffs; i++)
{
sconfig.user_index = i;
- SBuffer(sconfig);
+ SBuffer buff(sconfig);
//buffer derefs and returns to this queue thru token callback
}
}
diff --git a/lib/circular_buffer.cpp b/lib/circular_buffer.cpp
index 179e650..1021a12 100644
--- a/lib/circular_buffer.cpp
+++ b/lib/circular_buffer.cpp
@@ -6,13 +6,15 @@
#include <boost/bind.hpp>
#include <boost/interprocess/shared_memory_object.hpp>
#include <boost/interprocess/mapped_region.hpp>
-#include <boost/uuid/uuid.hpp>
-#include <boost/uuid/uuid_io.hpp>
-#include <ctime>
+#include <boost/lexical_cast.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/thread/mutex.hpp>
using namespace gras;
namespace ipc = boost::interprocess;
+static boost::mutex alloc_mutex;
+
/*!
* This routine generates an incredibly unique name for the allocation.
*
@@ -24,9 +26,9 @@ namespace ipc = boost::interprocess;
*/
static std::string omg_so_unique(void)
{
- boost::uuids::uuid u1; // initialize uuid
- return boost::str(boost::format("shmem-%s-%u-%u-%u")
- % to_string(u1) % std::rand() % clock() % time(NULL));
+ const std::string tid = boost::lexical_cast<std::string>(boost::this_thread::get_id());
+ static size_t count = 0;
+ return boost::str(boost::format("shmem-%s-%u") % tid % count++);
}
struct CircularBuffer
@@ -48,6 +50,8 @@ struct CircularBuffer
CircularBuffer::CircularBuffer(const size_t num_bytes)
{
+ boost::mutex::scoped_lock lock(alloc_mutex);
+
const size_t chunk = ipc::mapped_region::get_page_size();
const size_t len = chunk*((num_bytes + chunk - 1)/chunk);
actual_length = len;