bugfix: listener stops randomly (2)

detail:
- _runPendingMessagesTask is assigned after the task has started, then
- _runPendingMessagesTask.SafeRelease() has no visible effect, then
- _runPendingMessagesTask is true for ever
This commit is contained in:
monsieurgustav
2016-02-29 22:19:10 +01:00
parent b33fc3bfdf
commit 2de2178523
2 changed files with 8 additions and 5 deletions
@@ -9,7 +9,8 @@ UOscDispatcher::UOscDispatcher()
: _listening(FIPv4Address(0), 0),
_socket(nullptr),
_socketReceiver(nullptr),
_pendingMessages(1024) // arbitrary max message count per frame
_pendingMessages(1024), // arbitrary max message count per frame
_taskSpawned(0)
{
}
@@ -182,9 +183,10 @@ void UOscDispatcher::Callback(const FArrayReaderPtr& data, const FIPv4Endpoint&)
}
// Set a single callback in the main thread per frame.
if(!_pendingMessages.IsEmpty() && !_runPendingMessagesTask)
if(!_pendingMessages.IsEmpty() && !FPlatformAtomics::InterlockedCompareExchange(&_taskSpawned, 1, 0))
{
_runPendingMessagesTask = FSimpleDelegateGraphTask::CreateAndDispatchWhenReady(
check(_taskSpawned == 1);
FSimpleDelegateGraphTask::CreateAndDispatchWhenReady(
FSimpleDelegateGraphTask::FDelegate::CreateUObject(this, &UOscDispatcher::CallbackMainThread),
TStatId(),
nullptr,
@@ -206,7 +208,8 @@ void UOscDispatcher::CallbackMainThread()
// Release before dequeue.
// If it was released after dequeue, when a message arrives after the while
// loop and before the release, it would not be processed.
_runPendingMessagesTask.SafeRelease();
check(_taskSpawned == 1);
FPlatformAtomics::InterlockedCompareExchange(&_taskSpawned, 0, 1);
FScopeLock ScopeLock(&_receiversMutex);
@@ -50,7 +50,7 @@ private:
FSocket * _socket;
FUdpSocketReceiver * _socketReceiver;
TCircularQueue<std::pair<FName, TArray<FOscDataElemStruct>>> _pendingMessages;
FGraphEventRef _runPendingMessagesTask;
int32 _taskSpawned;
/// Protects _receivers
FCriticalSection _receiversMutex;