Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,14 +631,12 @@ bool CClient::GetAndResetbJitterBufferOKFlag()
// get the socket buffer put status flag and reset it
const bool bSocketJitBufOKFlag = Socket.GetAndResetbJitterBufferOKFlag();

if ( !bJitterBufferOK )
// atomically read our own get status flag and reset it to OK
if ( !bJitterBufferOK.exchange ( true ) )
{
// our jitter buffer get status is not OK so the overall status of the
// jitter buffer is also not OK (we do not have to consider the status
// of the socket buffer put status flag)

// reset flag before returning the function
bJitterBufferOK = true;
return false;
}

Expand Down
7 changes: 4 additions & 3 deletions src/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include <QString>
#include <QDateTime>
#include <QMutex>
#include <atomic>
#ifdef USE_OPUS_SHARED_LIB
# include "opus/opus_custom.h"
#else
Expand Down Expand Up @@ -431,9 +432,9 @@ class CClient : public QObject
bool bEnableAudioAlerts;
bool bEnableOPUS64;

bool bJitterBufferOK;
bool bMuteMeInPersonalMix;
QMutex MutexDriverReinit;
std::atomic<bool> bJitterBufferOK;
bool bMuteMeInPersonalMix;
QMutex MutexDriverReinit;

// server settings
int iServerSockBufNumFrames;
Expand Down
15 changes: 4 additions & 11 deletions src/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,17 +518,10 @@ void CSocket::SendPacket ( const CVector<uint8_t>& vecbySendBuf, const CHostAddr

bool CSocket::GetAndResetbJitterBufferOKFlag()
{
// check jitter buffer status
if ( !bJitterBufferOK )
{
// reset flag and return "not OK" status
bJitterBufferOK = true;
return false;
}

// the buffer was OK, we do not have to reset anything and just return the
// OK status
return true;
// atomically read the jitter buffer status and reset it to OK so that a
// "not OK" set by the socket thread between a separate read and reset
// cannot be lost
return bJitterBufferOK.exchange ( true );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice, and more concise than the original!

}

void CSocket::OnDataReceived()
Expand Down
3 changes: 2 additions & 1 deletion src/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include <QThread>
#include <QMutex>
#include <vector>
#include <atomic>
#include "global.h"
#include "protocol.h"
#include "util.h"
Expand Down Expand Up @@ -124,7 +125,7 @@ class CSocket : public QObject

bool bIsClient;

bool bJitterBufferOK;
std::atomic<bool> bJitterBufferOK;

// This is a reference to CClient::bIPv6Available or CServer::bIPv6Available,
// to inform the Client or Server which type of socket was created at startup.
Expand Down
9 changes: 5 additions & 4 deletions src/sound/soundbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include <QThread>
#include <QString>
#include <QMutex>
#include <atomic>
#ifndef HEADLESS
# include <QMessageBox>
#endif
Expand Down Expand Up @@ -193,10 +194,10 @@ class CSoundBase : public QThread
( *fpProcessCallback ) ( psData, pProcessCallbackArg );
}

bool bRun;
bool bCallbackEntered;
QMutex MutexAudioProcessCallback;
QMutex MutexDevProperties;
std::atomic<bool> bRun;
std::atomic<bool> bCallbackEntered;
QMutex MutexAudioProcessCallback;
QMutex MutexDevProperties;

QString strSystemDriverTechniqueName;
int iCtrlMIDIChannel;
Expand Down
7 changes: 4 additions & 3 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#pragma once
#include <vector>
#include <algorithm>
#include <atomic>
#ifdef _WIN32
# include <winsock2.h>
# include <ws2tcpip.h>
Expand Down Expand Up @@ -1352,11 +1353,11 @@ class CHighPrecisionTimer : public QThread
protected:
virtual void run();

bool bRun;
std::atomic<bool> bRun;

# if defined( __APPLE__ ) || defined( __MACOSX )
uint64_t Delay;
uint64_t NextEnd;
uint64_t Delay;
uint64_t NextEnd;
# else
long Delay;
timespec NextEnd;
Expand Down
Loading