diff --git a/src/Connection.c b/src/Connection.c index f1d87f6..4db64e0 100644 --- a/src/Connection.c +++ b/src/Connection.c @@ -3,7 +3,7 @@ static int stage = STAGE_NONE; static ConnListenerConnectionTerminated originalTerminationCallback; -static bool alreadyTerminated; +static atomic_bool alreadyTerminated; static PLT_THREAD terminationCallbackThread; static int terminationCallbackErrorCode; @@ -17,7 +17,7 @@ CONNECTION_LISTENER_CALLBACKS ListenerCallbacks; DECODER_RENDERER_CALLBACKS VideoCallbacks; AUDIO_RENDERER_CALLBACKS AudioCallbacks; int NegotiatedVideoFormat; -volatile bool ConnectionInterrupted; +atomic_bool ConnectionInterrupted; bool HighQualitySurroundSupported; bool HighQualitySurroundEnabled; OPUS_MULTISTREAM_CONFIGURATION NormalQualityOpusConfig; diff --git a/src/ControlStream.c b/src/ControlStream.c index c8a30e5..c9eb87f 100644 --- a/src/ControlStream.c +++ b/src/ControlStream.c @@ -33,9 +33,9 @@ static PLT_THREAD invalidateRefFramesThread; static PLT_THREAD controlReceiveThread; static PLT_EVENT invalidateRefFramesEvent; static int lossCountSinceLastReport; -static int lastGoodFrame; -static int lastSeenFrame; -static bool stopping; +static atomic_int lastGoodFrame; +static atomic_int lastSeenFrame; +static atomic_bool stopping; static bool disconnectPending; static int intervalGoodFrameCount; @@ -44,7 +44,7 @@ static uint64_t intervalStartTimeMs; static int lastIntervalLossPercentage; static int lastConnectionStatusUpdate; -static bool idrFrameRequired; +static atomic_bool idrFrameRequired; static LINKED_BLOCKING_QUEUE invalidReferenceFrameTuples; #define CONN_IMMEDIATE_POOR_LOSS_RATE 30 diff --git a/src/InputStream.c b/src/InputStream.c index 4280a8e..972c2b8 100644 --- a/src/InputStream.c +++ b/src/InputStream.c @@ -8,7 +8,7 @@ static SOCKET inputSock = INVALID_SOCKET; static unsigned char currentAesIv[16]; -static bool initialized; +static atomic_bool initialized; static EVP_CIPHER_CTX* cipherContext; static bool cipherInitialized; diff --git a/src/Limelight-internal.h b/src/Limelight-internal.h index e76012f..237b3e4 100644 --- a/src/Limelight-internal.h +++ b/src/Limelight-internal.h @@ -19,7 +19,7 @@ extern CONNECTION_LISTENER_CALLBACKS ListenerCallbacks; extern DECODER_RENDERER_CALLBACKS VideoCallbacks; extern AUDIO_RENDERER_CALLBACKS AudioCallbacks; extern int NegotiatedVideoFormat; -extern volatile bool ConnectionInterrupted; +extern atomic_bool ConnectionInterrupted; extern bool HighQualitySurroundSupported; extern bool HighQualitySurroundEnabled; extern OPUS_MULTISTREAM_CONFIGURATION NormalQualityOpusConfig; diff --git a/src/LinkedBlockingQueue.c b/src/LinkedBlockingQueue.c index 20be12a..ac38d4b 100644 --- a/src/LinkedBlockingQueue.c +++ b/src/LinkedBlockingQueue.c @@ -106,7 +106,7 @@ int LbqPeekQueueElement(PLINKED_BLOCKING_QUEUE queueHead, void** data) { return LBQ_INTERRUPTED; } - if (queueHead->head == NULL) { + if (queueHead->currentSize == 0) { return LBQ_NO_ELEMENT; } @@ -131,7 +131,7 @@ int LbqPollQueueElement(PLINKED_BLOCKING_QUEUE queueHead, void** data) { return LBQ_INTERRUPTED; } - if (queueHead->head == NULL) { + if (queueHead->currentSize == 0) { return LBQ_NO_ELEMENT; } diff --git a/src/LinkedBlockingQueue.h b/src/LinkedBlockingQueue.h index 7df7ff3..46e6570 100644 --- a/src/LinkedBlockingQueue.h +++ b/src/LinkedBlockingQueue.h @@ -18,8 +18,8 @@ typedef struct _LINKED_BLOCKING_QUEUE { PLT_MUTEX mutex; PLT_EVENT containsDataEvent; int sizeBound; - int currentSize; - bool shutdown; + atomic_int currentSize; + atomic_bool shutdown; int lifetimeSize; PLINKED_BLOCKING_QUEUE_ENTRY head; PLINKED_BLOCKING_QUEUE_ENTRY tail; diff --git a/src/Platform.h b/src/Platform.h index 598a1a4..130c9b4 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -3,6 +3,7 @@ #include #include #include +#include #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN diff --git a/src/PlatformThreads.h b/src/PlatformThreads.h index a72420f..4fcc361 100644 --- a/src/PlatformThreads.h +++ b/src/PlatformThreads.h @@ -10,18 +10,18 @@ typedef HANDLE PLT_MUTEX; typedef HANDLE PLT_EVENT; typedef struct _PLT_THREAD { HANDLE handle; - bool cancelled; + atomic_bool cancelled; } PLT_THREAD; #elif defined(__vita__) typedef int PLT_MUTEX; typedef struct _PLT_EVENT { int mutex; int cond; - bool signalled; + atomic_bool signalled; } PLT_EVENT; typedef struct _PLT_THREAD { int handle; - int cancelled; + atomic_bool cancelled; void *context; bool alive; } PLT_THREAD; @@ -30,11 +30,11 @@ typedef pthread_mutex_t PLT_MUTEX; typedef struct _PLT_EVENT { pthread_mutex_t mutex; pthread_cond_t cond; - bool signalled; + atomic_bool signalled; } PLT_EVENT; typedef struct _PLT_THREAD { pthread_t thread; - bool cancelled; + atomic_bool cancelled; } PLT_THREAD; #else #error Unsupported platform diff --git a/src/VideoStream.c b/src/VideoStream.c index ecdad94..093c070 100644 --- a/src/VideoStream.c +++ b/src/VideoStream.c @@ -22,7 +22,7 @@ static PLT_THREAD decoderThread; static bool receivedDataFromPeer; static uint64_t firstDataTimeMs; -static bool receivedFullFrame; +static atomic_bool receivedFullFrame; // We can't request an IDR frame until the depacketizer knows // that a packet was lost. This timeout bounds the time that