Skip to content

Commit

Permalink
iox-eclipse-iceoryx#25 better error handling in TriggerQueue
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Eltzschig <christian.eltzschig2@de.bosch.com>
  • Loading branch information
elfenpiff committed Sep 29, 2020
1 parent 00a7013 commit 5ea18ca
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#ifndef IOX_UTILS_CONCURRENT_TRIGGER_QUEUE_INL
#define IOX_UTILS_CONCURRENT_TRIGGER_QUEUE_INL

#include "iceoryx_utils/cxx/helplets.hpp"
#include "iceoryx_utils/internal/concurrent/trigger_queue.hpp"

namespace iox
Expand Down Expand Up @@ -41,7 +42,7 @@ inline bool TriggerQueue<T, CAPACITY>::push(const T& in)
{
if (stl_queue_push(in))
{
m_semaphore->post();
cxx::Expects(!m_semaphore->post().has_error());
return true;
}
else
Expand All @@ -53,16 +54,17 @@ inline bool TriggerQueue<T, CAPACITY>::push(const T& in)
template <typename T, uint64_t CAPACITY>
inline bool TriggerQueue<T, CAPACITY>::blocking_pop(T& out)
{
m_semaphore->wait();
cxx::Expects(!m_semaphore->wait().has_error());
return stl_queue_pop(out);
}

template <typename T, uint64_t CAPACITY>
inline bool TriggerQueue<T, CAPACITY>::try_pop(T& out)
{
if (!m_semaphore->tryWait()
.or_else([](posix::SemaphoreError) { std::cerr << "working on corrupted semaphore"; })
.get_value())
auto result = m_semaphore->tryWait();
cxx::Expects(!result.has_error());

if (!*result)
{
return false;
}
Expand Down Expand Up @@ -91,7 +93,7 @@ inline uint64_t TriggerQueue<T, CAPACITY>::capacity()
template <typename T, uint64_t CAPACITY>
inline void TriggerQueue<T, CAPACITY>::send_wakeup_trigger()
{
m_semaphore->post();
cxx::Expects(!m_semaphore->post().has_error());
}

/// @todo remove with lockfree fifo START
Expand Down

0 comments on commit 5ea18ca

Please sign in to comment.