From ea6ae75fccad52d116559f320d6f0069c1ad552b Mon Sep 17 00:00:00 2001 From: Determinant Date: Tue, 26 Mar 2019 03:59:47 -0400 Subject: use bounded send_buffer --- include/salticidae/buffer.h | 4 +++- include/salticidae/event.h | 22 ++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/include/salticidae/buffer.h b/include/salticidae/buffer.h index 3f415c9..2324d8b 100644 --- a/include/salticidae/buffer.h +++ b/include/salticidae/buffer.h @@ -131,7 +131,9 @@ struct MPSCWriteBuffer { } void push(bytearray_t &&data) { - buffer.enqueue(buffer_entry_t(std::move(data))); + buffer_entry_t d(std::move(data)); + // TODO: better bounded buffer impl + while (!buffer.try_enqueue(d)) {} } bytearray_t move_pop() { diff --git a/include/salticidae/event.h b/include/salticidae/event.h index 649cfdd..fafa884 100644 --- a/include/salticidae/event.h +++ b/include/salticidae/event.h @@ -578,14 +578,28 @@ class MPSCQueueEventDriven: public MPSCQueue { template bool enqueue(U &&e) { static const uint64_t dummy = 1; - bool ret = MPSCQueue::enqueue(std::forward(e)); + MPSCQueue::enqueue(std::forward(e)); // memory barrier here, so any load/store in enqueue must be finialized if (wait_sig.exchange(false, std::memory_order_acq_rel)) { SALTICIDAE_LOG_DEBUG("mpsc notify"); write(fd, &dummy, 8); } - return ret; + return true; + } + + template + bool try_enqueue(U &&e) { + static const uint64_t dummy = 1; + if (!MPMCQueue::try_enqueue(std::forward(e))) + return false; + // memory barrier here, so any load/store in enqueue must be finialized + if (wait_sig.exchange(false, std::memory_order_acq_rel)) + { + SALTICIDAE_LOG_DEBUG("mpsc notify"); + write(fd, &dummy, 8); + } + return true; } }; @@ -629,14 +643,14 @@ class MPMCQueueEventDriven: public MPMCQueue { template bool enqueue(U &&e) { static const uint64_t dummy = 1; - bool ret = MPMCQueue::enqueue(std::forward(e)); + MPMCQueue::enqueue(std::forward(e)); // memory barrier here, so any load/store in enqueue must be finialized if (wait_sig.exchange(false, std::memory_order_acq_rel)) { SALTICIDAE_LOG_DEBUG("mpsc notify"); write(fd, &dummy, 8); } - return ret; + return true; } }; -- cgit v1.2.3-70-g09d2