From d1dedcb21e7ba074a0a83fad09a742e54a8d1525 Mon Sep 17 00:00:00 2001 From: Alberto Compagno Date: Wed, 13 Feb 2019 15:06:23 +0100 Subject: [HICN-60] Solved concurrent memory access which was leading to seg-fault Change-Id: I7b9fcf79bb97650346f7d92af8cbb419f0a5cb95 Signed-off-by: Alberto Compagno --- libtransport/src/hicn/transport/utils/epoll_event_reactor.cc | 10 ++++------ libtransport/src/hicn/transport/utils/object_pool.h | 1 + libtransport/src/hicn/transport/utils/ring_buffer.h | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) (limited to 'libtransport/src/hicn/transport/utils') diff --git a/libtransport/src/hicn/transport/utils/epoll_event_reactor.cc b/libtransport/src/hicn/transport/utils/epoll_event_reactor.cc index 81b471857..6df9e5656 100644 --- a/libtransport/src/hicn/transport/utils/epoll_event_reactor.cc +++ b/libtransport/src/hicn/transport/utils/epoll_event_reactor.cc @@ -51,10 +51,9 @@ int EpollEventReactor::addFileDescriptor(int fd, uint32_t events) { int EpollEventReactor::addFileDescriptor(int fd, uint32_t events, EventCallback &callback) { auto it = event_callback_map_.find(fd); - event_callback_map_[fd] = callback; - if (it != event_callback_map_.end()) { + + if (it == event_callback_map_.end()) { event_callback_map_[fd] = callback; - } else { return addFileDescriptor(fd, events); } @@ -64,10 +63,9 @@ int EpollEventReactor::addFileDescriptor(int fd, uint32_t events, int EpollEventReactor::addFileDescriptor(int fd, uint32_t events, EventCallback &&callback) { auto it = event_callback_map_.find(fd); - event_callback_map_[fd] = callback; - if (it != event_callback_map_.end()) { + + if (it == event_callback_map_.end()) { event_callback_map_[fd] = callback; - } else { return addFileDescriptor(fd, events); } diff --git a/libtransport/src/hicn/transport/utils/object_pool.h b/libtransport/src/hicn/transport/utils/object_pool.h index 9fda214cd..e34730e81 100644 --- a/libtransport/src/hicn/transport/utils/object_pool.h +++ b/libtransport/src/hicn/transport/utils/object_pool.h @@ -62,6 +62,7 @@ class ObjectPool { void add(T *object) { utils::SpinLock::Acquire locked(object_pool_lock_); + if (TRANSPORT_EXPECT_TRUE(!destructor_)) { object_pool_.emplace_back(makePtr(object)); } diff --git a/libtransport/src/hicn/transport/utils/ring_buffer.h b/libtransport/src/hicn/transport/utils/ring_buffer.h index 52bcd81c4..9babe56bd 100644 --- a/libtransport/src/hicn/transport/utils/ring_buffer.h +++ b/libtransport/src/hicn/transport/utils/ring_buffer.h @@ -86,7 +86,7 @@ bool CircularFifo::push(Element&& item) { // the tail must be accessed with at least acquire template bool CircularFifo::pop(Element& item) { - const auto current_head = head_.load(std::memory_order_relaxed); + const size_t current_head = head_.load(std::memory_order_relaxed); if (current_head == tail_.load(std::memory_order_acquire)) { return false; // empty queue } -- cgit 1.2.3-korg