Start adopting C11 atomics

This commit is contained in:
Cameron Gutman committed 2026-11-10 22:17:55 -06:00
1 parent 3b6ee9d916
commit b0deb0a265
3 files changed
+12 -7

No files matched your search

+9 -5
View File
@@ -2,7 +2,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;
@@ -159,13 +159,17 @@ static void ClInternalConnectionTerminated(int errorCode)
{
int err;
// Avoid recursion and issuing multiple callbacks
if (alreadyTerminated || ConnectionInterrupted) {
// Ensure only one thread triggers connection termination
if (atomic_exchange_explicit(&alreadyTerminated, true, memory_order_acq_rel)) {
return;
}
// If the connection is being stopped, no callback is needed
if (ConnectionInterrupted) {
return;
}
terminationCallbackErrorCode = errorCode;
alreadyTerminated = true;
// Invoke the termination callback on a separate thread
err = PltCreateThread("AsyncTerm", terminationCallbackThreadFunc, NULL, &terminationCallbackThread);
+2 -1
View File
@@ -12,6 +12,7 @@
#include "ByteBuffer.h"
#include <enet/enet.h>
#include <stdatomic.h>
// Common globals
extern char* RemoteAddrString;
@@ -24,7 +25,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;