From acd85f06241b9492f96b6d512c547e574b4d9ae8 Mon Sep 17 00:00:00 2001 From: bernat Date: Fri, 19 Jun 2020 12:39:19 +0200 Subject: [PATCH] Made pointer to class method as atomic pointer --- LibCarla/source/carla/streaming/Stream.h | 2 +- LibCarla/source/carla/streaming/detail/MultiStreamState.h | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/LibCarla/source/carla/streaming/Stream.h b/LibCarla/source/carla/streaming/Stream.h index c0016c17f..09ca7644b 100644 --- a/LibCarla/source/carla/streaming/Stream.h +++ b/LibCarla/source/carla/streaming/Stream.h @@ -13,7 +13,7 @@ namespace carla { namespace streaming { /// A stream represents an unidirectional channel for sending data from server - /// to client. A **single** client can subscribe to this stream using the + /// to client. **Multiple** clients can subscribe to this stream using the /// stream token. If no client is subscribed, the data flushed down the stream /// is discarded. using Stream = detail::Stream; diff --git a/LibCarla/source/carla/streaming/detail/MultiStreamState.h b/LibCarla/source/carla/streaming/detail/MultiStreamState.h index 983dbc61a..46348256d 100644 --- a/LibCarla/source/carla/streaming/detail/MultiStreamState.h +++ b/LibCarla/source/carla/streaming/detail/MultiStreamState.h @@ -13,6 +13,7 @@ #include #include +#include namespace carla { namespace streaming { @@ -25,6 +26,7 @@ namespace detail { public: using StreamStateBase::StreamStateBase; + using WriteMethodPointer = void (MultiStreamState::*)(std::shared_ptr); MultiStreamState(const token_type &token) : StreamStateBase(token), @@ -52,7 +54,6 @@ namespace detail { else if (_sessions.size() > 1) { _writeFunction = &MultiStreamState::WriteMulti; } - (_writeFunction == &MultiStreamState::WriteSingle) ? log_debug("Pointer to single stream") : log_debug("Pointer to multi stream"); } void DisconnectSession(std::shared_ptr session) final { @@ -63,7 +64,6 @@ namespace detail { DEBUG_ASSERT(session == _session.load()); _session.store(nullptr); _sessions.clear(); - _writeFunction = &MultiStreamState::WriteSingle; } else { _sessions.erase( std::remove(_sessions.begin(), _sessions.end(), session), @@ -77,7 +77,6 @@ namespace detail { _writeFunction = &MultiStreamState::WriteSingle; } log_debug("Disconnecting multistream sessions:", _sessions.size()); - (_writeFunction == &MultiStreamState::WriteSingle) ? log_debug("Pointer to single stream") : log_debug("Pointer to multi stream"); } void ClearSessions() final { @@ -86,7 +85,6 @@ namespace detail { _session.store(nullptr); _writeFunction = &MultiStreamState::WriteSingle; log_debug("Disconnecting all multistream sessions"); - (_writeFunction == &MultiStreamState::WriteSingle) ? log_debug("Pointer to single stream") : log_debug("Pointer to multi stream"); } void WriteSingle(std::shared_ptr message) { @@ -114,7 +112,7 @@ namespace detail { // if there are more than one session, we use vector of sessions with mutex std::vector> _sessions; // write function pointer (by default write single stream) - void (MultiStreamState::*_writeFunction)(std::shared_ptr); + std::atomic _writeFunction; }; } // namespace detail