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