Moving from old atomic implementation to c++11 atomics and providing some copy...

Moving from old atomic implementation to c++11 atomics and providing some copy constructors for msvc14 compat
parent 4ecf4f6e
......@@ -22,7 +22,6 @@
#include <ITADataSourcesDefinitions.h>
#include <ITADataSource.h>
#include <ITAAtomicPrimitives.h>
#include <vector>
......@@ -233,10 +232,10 @@ private:
unsigned int m_uiBlocklength; // Streaming Puffergröße [Samples]
unsigned int m_uiCapacity; // Kapazität der Quelle
ITAAtomicInt m_iCursor; // Leseposition
std::atomic< int > m_iCursor; // Leseposition
ITAAtomicBool m_bPaused; // Wiedergabezustand
ITAAtomicBool m_bPausedInternal; // Wiedergabezustand (interne Variable)
std::atomic< bool> m_bPaused; // Wiedergabezustand
std::atomic< bool > m_bPausedInternal; // Wiedergabezustand (interne Variable)
bool m_bLoopMode, m_bNewLoopMode; // Wiederholungsmodusm, neuer Wiederholungsmodus
bool m_bChangeLoopMode; // true = Wiederholungsmodus soll geändert werden
bool m_bRewind; // Als nächstes Zurückspulen?
......
......@@ -21,7 +21,7 @@
#include <ITADataSourcesDefinitions.h>
#include <ITAAtomicPrimitives.h>
#include <atomic>
/*
Versionshistorie:
......@@ -247,7 +247,7 @@ protected:
ITADatasource();
private:
ITAAtomicInt m_iRefCount;
std::atomic< int > m_iRefCount;
};
#endif // INCLUDE_WATCHER_ITA_DATA_SOURCE
......@@ -23,7 +23,6 @@
#include <ITADataSource.h>
#include <ITAStreamProperties.h>
#include <ITAAtomicPrimitives.h>
// Vorwrtsdeklarationen
class ITADatasourceRealizationEventHandler;
......@@ -176,8 +175,8 @@ private:
unsigned int m_uiWriteCursor; // Schreibposition
float* m_pfBuffer; // Puffer (Kanle interleaved!)
ITAAtomicInt m_iGBPEntrances; // Anzahl paralleler Eintritte in GBP
ITAAtomicBool m_bGBPFirst; // Erster Eintritt in GBP seit letztem IBP (=> Daten produzieren)
std::atomic< int > m_iGBPEntrances; // Anzahl paralleler Eintritte in GBP
std::atomic< bool > m_bGBPFirst; // Erster Eintritt in GBP seit letztem IBP (=> Daten produzieren)
int m_iBufferUnderflows; // DEBUG: Zhler fr Buffer-Leerlufe
int m_iBufferOverflows; // DEBUG: Zhler fr Buffer-berlufe
int m_iGBPReentrances; // DEBUG: Zhler parallele Wiedereintritte in GBP
......
......@@ -21,7 +21,6 @@
#include <ITADataSourcesDefinitions.h>
#include <ITAAtomicPrimitives.h>
#include <ITADataSourceRealization.h>
#include <ITATypes.h>
......@@ -59,8 +58,8 @@ public:
protected:
ITADatasource* m_pInputDatasource;
ITAAtomicBool m_bMuted;
ITAAtomicFloat m_fCurGain;
std::atomic< bool > m_bMuted;
std::atomic< float > m_fCurGain;
float m_fPrevGain;
};
......
......@@ -22,6 +22,8 @@
#include <ITADataSourcesDefinitions.h>
#include <ITADataSourceRealization.h>
#include <atomic>
class ITA_DATA_SOURCES_API ITAStreamFunctionGenerator : public ITADatasourceRealization
{
public:
......@@ -102,12 +104,12 @@ public:
void SetAmplitude(float fAmplitude);
private:
ITAAtomicInt m_iFunction;
ITAAtomicBool m_bPeriodic;
ITAAtomicBool m_bMuted;
ITAAtomicInt m_iNumSamples;
ITAAtomicFloat m_fAmplitude;
ITAAtomicInt m_iPeriodLengthSamples; //!< Number of samples per period
std::atomic< int > m_iFunction;
std::atomic< bool > m_bPeriodic;
std::atomic< bool > m_bMuted;
std::atomic< int > m_iNumSamples;
std::atomic< float > m_fAmplitude;
std::atomic< int > m_iPeriodLengthSamples; //!< Number of samples per period
float m_fPhase; //!< Current phase information [radiants]
int m_iSampleCount; //!< Number of generated output samples
......
......@@ -21,9 +21,10 @@
#include <ITADataSourcesDefinitions.h>
#include <ITAAtomicPrimitives.h>
#include <ITADataSourceRealization.h>
#include <ITAUncopyable.h>
#include <atomic>
#include <set>
#include <string>
#include <vector>
......@@ -215,8 +216,8 @@ private:
{
public:
int iChannels; //!< Number of channels;
ITAAtomicFloat fCurrentGain, fNewGain; //!< Gain (amplification factor)
ITAAtomicBool bMuted; //!< Muted?
std::atomic< float > fCurrentGain, fNewGain; //!< Gain (amplification factor)
std::atomic< bool > bMuted; //!< Muted?
ITADatasource* pDatasource; //!< Datasource assigned to the input
std::vector< const float* > vpfInputData; //!< Pointers to the next stream blocks
......@@ -236,8 +237,8 @@ private:
public:
int iFirst; //!< Input index
int iSecond; //!< Input channel
ITAAtomicFloat fCurrentGain; //!< Gain (current block amplification factor)
ITAAtomicFloat fNewGain; //!< Gain (next block amplification factor)
std::atomic< float > fCurrentGain; //!< Gain (current block amplification factor)
std::atomic< float > fNewGain; //!< Gain (next block amplification factor)
inline Connection( const int iFirst, const int iSecond, const float fGain = 1.0f )
: iFirst( iFirst )
......@@ -246,6 +247,14 @@ private:
, fNewGain( fGain )
{
};
inline Connection(const Connection& oOther)
: iFirst( oOther.iFirst)
, iSecond( oOther.iSecond )
{
fCurrentGain.exchange(oOther.fCurrentGain);
fNewGain.exchange(oOther.fNewGain);
};
};
struct CompareConnection
......@@ -267,8 +276,8 @@ private:
{
public:
int iChannels; // Number of channels;
ITAAtomicFloat fCurrentGain, fNewGain; // Gain (amplification factor)
ITAAtomicBool bMuted; // Muted?
std::atomic< float > fCurrentGain, fNewGain; // Gain (amplification factor)
std::atomic< bool > bMuted; // Muted?
Connections conns; // Input -> Output assignments
inline OutputDesc( ITAStreamPatchbay* pParent, const int iChannels, const double dSamplerate, const int iBlockLength )
......@@ -291,8 +300,8 @@ private:
int m_iGainFadeLength;
std::vector< InputDesc* > m_vpInputs;
std::vector< OutputDesc* > m_vpOutputs;
ITAAtomicBool m_bProcessData;
ITAAtomicBool m_bProcessIncrement;
std::atomic< bool > m_bProcessData;
std::atomic< bool > m_bProcessIncrement;
float m_fTempGain;
//! Processes all the data for one streaming cycle
......
......@@ -23,9 +23,9 @@
#include <ITADataSource.h>
#include <ITASampleFrame.h>
#include <ITAAtomicPrimitives.h>
#include <ITABufferedAudiofileWriter.h>
#include <atomic>
#include <string>
#include <vector>
......@@ -79,7 +79,7 @@ protected:
int m_iChannels; //!< Number of channels
int m_iBlockLength; //!< Streaming buffer size [Samples]
ITAAtomicInt m_iRecordedSamples; //!< Number of recorded samples
std::atomic< int > m_iRecordedSamples; //!< Number of recorded samples
ITASampleFrame m_sfBuffer;
std::vector< bool > m_vbDataPresent;
......
......@@ -4,7 +4,6 @@
#include <ITADatasource.h>
#include <ITADatasourceRealization.h>
#include <ITAAtomicPrimitives.h>
#include <ITAClock.h>
#include <ITADatasource.h>
#include <ITAException.h>
......@@ -16,6 +15,7 @@
#include <windows.h>
#include <iostream>
#include <vector>
#include <atomic>
// Puffer-Vielfachheit (Doppelpuffer, Dreifachpuffer, etc.)
......@@ -137,7 +137,7 @@ int iInputBufferNrOffset = 0;
long lBuffersize = 0; // Ausgewählte Puffergröße
ITAAtomicInt iBufferswitchEntrances( 0 );
std::atomic< int > iBufferswitchEntrances( 0 );
ITAStopWatch g_swStreamOutputProcessing;
......
......@@ -278,7 +278,7 @@ const float* ITABufferDatasource::GetBlockPointer( unsigned int uiChannel, const
if( m_bGetBlockPointerTouched == false )
{
bool bIncRequired = Update();
m_bPausedInternal = m_bPaused;
m_bPausedInternal.exchange( m_bPaused );
m_bGetBlockPointerTouched = true;
}
......
......@@ -21,17 +21,18 @@ int ITADatasource::AddReference() {
return ++m_iRefCount;
}
int ITADatasource::RemoveReference() {
while (true) {
int ITADatasource::RemoveReference()
{
while (true)
{
int i = m_iRefCount;
if (i<=0)
// Da hat der Programmierer irgendwo ein Reference-Leak!
ITA_EXCEPT1(MODAL_EXCEPTION, "Datasource does not have any references.");
if (m_iRefCount.cas(i, i-1)) {
if (m_iRefCount.compare_exchange_weak(i, i - 1))
return i-1;
}
}
// Wird nie erreicht!
......
#include "ITAFileDataSource.h"
#include <ITAAudiofileReader.h>
#include <cassert>
#ifndef WIN32
#include <memory.h>
#endif
......
......@@ -4,6 +4,7 @@
#include <float.h>
#include <iostream>
#include <cmath>
#include <cassert>
#include <ITAFastMath.h>
#include <ITAException.h>
......@@ -510,7 +511,7 @@ void ITAStreamPatchbay::ProcessData( const ITAStreamInfo* pStreamInfo )
{
// Update connection gains
Connection& conn = *const_cast< Connection* >( &( *it ) );
conn.fCurrentGain = conn.fNewGain;
conn.fCurrentGain.exchange( conn.fNewGain );
continue;
}
......@@ -550,18 +551,18 @@ void ITAStreamPatchbay::ProcessData( const ITAStreamInfo* pStreamInfo )
// Update connection gains, do a dirty const removal
const Connection& cconn( *it );
Connection& conn = const_cast< Connection& >( cconn );
conn.fCurrentGain.set( conn.fNewGain.get() );
conn.fCurrentGain.exchange( conn.fNewGain );
}
}
// Update output gains (after processing data)
pOutput->fCurrentGain = pOutput->fNewGain;
pOutput->fCurrentGain.exchange( pOutput->fNewGain );
pOutput->IncrementWritePointer();
}
// Update input gains (can first be done after all outputs are processed!)
for( int i = 0; i < GetNumInputs(); i++ )
m_vpInputs[ i ]->fCurrentGain = m_vpInputs[ i ]->fNewGain;
m_vpInputs[ i ]->fCurrentGain.exchange( m_vpInputs[ i ]->fNewGain );
return;
}
......@@ -11,6 +11,8 @@
#include <ITASampleFrame.h>
#include <ITAStreamMultiplier1N.h>
#include <cassert>
using namespace std;
static string g_sServerName = "localhost";
......
......@@ -15,6 +15,7 @@
#include <VistaBase/VistaTimeUtils.h>
#include <VistaBase/VistaExceptionBase.h>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment