Bug:UdpCmdDemux: Add SpinLock for races around stop()
This commit is contained in:
@@ -44,8 +44,11 @@ void UdpCommandDemuxer::start()
|
||||
try
|
||||
{
|
||||
setupSockets();
|
||||
isActive.store(true);
|
||||
shouldStop.store(false);
|
||||
{
|
||||
smo::SpinLock::Guard lock(isActiveAndShouldStopLock);
|
||||
isActive.store(true);
|
||||
shouldStop.store(false);
|
||||
}
|
||||
|
||||
// Start the async receive loop
|
||||
startAsyncReceive();
|
||||
@@ -66,10 +69,13 @@ void UdpCommandDemuxer::start()
|
||||
|
||||
void UdpCommandDemuxer::stop()
|
||||
{
|
||||
if (!isActive.load())
|
||||
{ return; }
|
||||
{
|
||||
smo::SpinLock::Guard lock(isActiveAndShouldStopLock);
|
||||
if (!isActive.load())
|
||||
{ return; }
|
||||
|
||||
shouldStop.store(true);
|
||||
shouldStop.store(true);
|
||||
}
|
||||
|
||||
// Close socket and cleanup
|
||||
if (cmdEndpointFdDesc)
|
||||
@@ -232,6 +238,8 @@ void UdpCommandDemuxer::onDataReady(const boost::system::error_code &error)
|
||||
return;
|
||||
}
|
||||
|
||||
smo::SpinLock::Guard lock(isActiveAndShouldStopLock);
|
||||
|
||||
if (!isActive.load() || shouldStop.load())
|
||||
{ return; }
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <memory>
|
||||
#include <boost/asio/posix/stream_descriptor.hpp>
|
||||
#include <componentThread.h>
|
||||
#include <spinLock.h>
|
||||
|
||||
namespace livoxProto1 {
|
||||
|
||||
@@ -81,6 +82,7 @@ private:
|
||||
uint16_t dataPort;
|
||||
|
||||
// State management
|
||||
smo::SpinLock isActiveAndShouldStopLock;
|
||||
std::atomic<bool> isActive{false};
|
||||
std::atomic<bool> shouldStop{false};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user