...
 
Commits (10)
...@@ -122,7 +122,8 @@ template< class T > void ITABufferedDataLogger< T >::setOutputFile( const std::s ...@@ -122,7 +122,8 @@ template< class T > void ITABufferedDataLogger< T >::setOutputFile( const std::s
m_sOutputFile = sFilename; m_sOutputFile = sFilename;
}; };
template< class T > void ITABufferedDataLogger< T >::clear() { template< class T > void ITABufferedDataLogger< T >::clear()
{
m_vLogItems.clear(); m_vLogItems.clear();
}; };
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
* *
*/ */
#ifndef INCLUDE_WATCHER_ITA_SAMPLEFRAME #ifndef INCLUDE_WATCHER_ITA_SAMPLE_FRAME
#define INCLUDE_WATCHER_ITA_SAMPLEFRAME #define INCLUDE_WATCHER_ITA_SAMPLE_FRAME
// ITABase // ITABase
#include <ITABaseDefinitions.h> #include <ITABaseDefinitions.h>
...@@ -114,10 +114,12 @@ public: ...@@ -114,10 +114,12 @@ public:
* \param bZeroinit Samples mit Nullen initialisieren? * \param bZeroinit Samples mit Nullen initialisieren?
*/ */
void Init( int iChannels, int iLength, bool bZeroinit ); void Init( int iChannels, int iLength, bool bZeroinit );
//! Legacy Init with small caps style
inline void init( int iChannels, int iLength, bool bZeroinit ) inline void init( int iChannels, int iLength, bool bZeroinit )
{ {
return Init( iChannels, iLength, bZeroinit ); return Init( iChannels, iLength, bZeroinit );
} };
void Load( const std::string& sFilePath ); void Load( const std::string& sFilePath );
void Load( const std::string& sFilePath, double& dSampleRate ); void Load( const std::string& sFilePath, double& dSampleRate );
...@@ -360,4 +362,4 @@ private: ...@@ -360,4 +362,4 @@ private:
typedef std::vector<ITASampleBuffer>::iterator ch_it; typedef std::vector<ITASampleBuffer>::iterator ch_it;
}; };
#endif // INCLUDE_WATCHER_ITA_SAMPLEFRAME #endif // INCLUDE_WATCHER_ITA_SAMPLE_FRAME
...@@ -66,11 +66,7 @@ public: ...@@ -66,11 +66,7 @@ public:
/** /**
* \note Wurde bereits die Zeitnahme gestartet, wird eine Ausnahme ausgelöst * \note Wurde bereits die Zeitnahme gestartet, wird eine Ausnahme ausgelöst
*/ */
inline void start() void start();
{
m_dStart = m_pClock->getTime();
m_bStarted = true;
}
//! Zeitnahme stoppen //! Zeitnahme stoppen
/** /**
......
/*
+-----------------------------------------------------------------------+
| |
| ITAToolkit |
| |
| (c) Copyright Institut für technische Akustik (ITA) |
| Aachen university of technology (RWTH), 2005-2008 |
| |
+-----------------------------------------------------------------------+
| |
| File: ITAAtomicOps.cpp |
| Purpose: Atomare Grundfunktionen für non-blocking concurrency |
| Authors: Frank Wefers (Frank.Wefers@akustik.rwth-aachen.de |
| |
+-----------------------------------------------------------------------+
*/
// $Id: ITAAtomicOpsGCCBuiltinsImpl.cpp 3454 2013-08-21 14:40:16Z stienen $
#include "ITAAtomicOps.h" #include "ITAAtomicOps.h"
#include <stdint.h> #include <stdint.h>
typedef union { typedef union
{
int32_t i32Value; int32_t i32Value;
float floatValue; float floatValue;
} ConvI32Float; } ConvI32Float;
int atomic_read_int(volatile const int* src)
int atomic_read_int( volatile const int* src )
{ {
/* /*
* Trick: Realisierung mittels CAS! * Trick: Realisierung mittels CAS!
* Falls der Wert schon 0, dann wird er gegen 0 ausgetauscht... * Falls der Wert schon 0, dann wird er gegen 0 ausgetauscht...
* Also keine Änderung! * Also keine Änderung!
*/ */
return __sync_val_compare_and_swap( (int*) src, 0, 0 ); return __sync_val_compare_and_swap( ( int* ) src, 0, 0 );
} }
float atomic_read_float(volatile const float* src) { long atomic_read_long( volatile const long* src )
{
/*
* Trick: Realisierung mittels CAS!
* Falls der Wert schon 0, dann wird er gegen 0 ausgetauscht...
* Also keine Änderung!
*/
return __sync_val_compare_and_swap( ( long* ) src, 0, 0 );
}
float atomic_read_float( volatile const float* src )
{
/* /*
* Trick: Realisierung mittels CAS! * Trick: Realisierung mittels CAS!
* Falls der Wert schon 0, dann wird er gegen 0 ausgetauscht... * Falls der Wert schon 0, dann wird er gegen 0 ausgetauscht...
...@@ -45,59 +40,74 @@ float atomic_read_float(volatile const float* src) { ...@@ -45,59 +40,74 @@ float atomic_read_float(volatile const float* src) {
*/ */
ConvI32Float c; ConvI32Float c;
c.i32Value = __sync_val_compare_and_swap((volatile int32_t*) src, 0, 0); c.i32Value = __sync_val_compare_and_swap( ( volatile int32_t* ) src, 0, 0 );
return c.floatValue; return c.floatValue;
} }
void* atomic_read_ptr(volatile const void** src) { void* atomic_read_ptr( volatile const void** src )
{
/* /*
* Trick: Realisierung mittels CAS! * Trick: Realisierung mittels CAS!
* Falls der Wert schon 0, dann wird er gegen 0 ausgetauscht... * Falls der Wert schon 0, dann wird er gegen 0 ausgetauscht...
* Also keine Änderung! * Also keine Änderung!
*/ */
return __sync_val_compare_and_swap((void**) src, 0, 0); return __sync_val_compare_and_swap( ( void** ) src, 0, 0 );
} }
void atomic_write_int(volatile int* dest, int value) { void atomic_write_int( volatile int* dest, int value )
__sync_lock_test_and_set(dest, value); {
__sync_lock_test_and_set( dest, value );
} }
void atomic_write_float(volatile float* dest, float value) { void atomic_write_long( volatile long* dest, long value )
{
__sync_lock_test_and_set( dest, value );
}
void atomic_write_float( volatile float* dest, float value )
{
ConvI32Float c; ConvI32Float c;
c.floatValue = value; c.floatValue = value;
__sync_lock_test_and_set((volatile int32_t*) dest, c.i32Value); __sync_lock_test_and_set( ( volatile int32_t* ) dest, c.i32Value );
} }
void atomic_write_ptr(volatile void** dest, void* value) { void atomic_write_ptr( volatile void** dest, void* value )
__sync_lock_test_and_set(dest, value); {
__sync_lock_test_and_set( dest, value );
} }
bool atomic_cas_int(volatile int* dest, int expected_value, int new_value) { bool atomic_cas_int( volatile int* dest, int expected_value, int new_value )
return __sync_bool_compare_and_swap(dest, expected_value, new_value); {
return __sync_bool_compare_and_swap( dest, expected_value, new_value );
} }
/* /*
bool atomic_cas_double(volatile double* dest, double expected_value, double new_value) { bool atomic_cas_double(volatile double* dest, double expected_value, double new_value) {
return __sync_bool_compare_and_swap(dest, expected_value, new_value); return __sync_bool_compare_and_swap(dest, expected_value, new_value);
} }
*/ */
bool atomic_cas_ptr(volatile void** dest, void* expected_value, void* new_value) { bool atomic_cas_ptr( volatile void** dest, void* expected_value, void* new_value )
return __sync_bool_compare_and_swap(dest, expected_value, new_value); {
return __sync_bool_compare_and_swap( dest, expected_value, new_value );
} }
void atomic_read32(volatile void* src, void* dest) { void atomic_read32( volatile void* src, void* dest )
*((int32_t*) dest) = __sync_val_compare_and_swap((volatile int32_t*) src, 0, 0); {
*( ( int32_t* ) dest ) = __sync_val_compare_and_swap( ( volatile int32_t* ) src, 0, 0 );
} }
bool atomic_cas32(volatile void* dest, void* expected_value, void* new_value) { bool atomic_cas32( volatile void* dest, void* expected_value, void* new_value )
return __sync_bool_compare_and_swap((volatile int32_t*)dest, *(int32_t*)expected_value, *(int32_t*)new_value); {
return __sync_bool_compare_and_swap( ( volatile int32_t* ) dest, *( int32_t* ) expected_value, *( int32_t* ) new_value );
} }
int atomic_inc_int(volatile int* dest) { int atomic_inc_int( volatile int* dest )
return __sync_fetch_and_add(dest, 1); {
return __sync_fetch_and_add( dest, 1 );
} }
int atomic_dec_int(volatile int* dest) { int atomic_dec_int( volatile int* dest )
return __sync_fetch_and_sub(dest, 1); {
return __sync_fetch_and_sub( dest, 1 );
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <ITAAudiofileWriter.h> #include <ITAAudiofileWriter.h>
#include <ITAConstants.h> #include <ITAConstants.h>
#include <ITAFilesystemUtils.h> #include <ITAFileSystemUtils.h>
#include <ITAHDFTSpectrum.h> #include <ITAHDFTSpectrum.h>
#include <ITASampleFrame.h> #include <ITASampleFrame.h>
#include <ITAStringUtils.h> #include <ITAStringUtils.h>
......
...@@ -215,6 +215,6 @@ std::string convertTimeToHumanReadableString(double dSeconds) { ...@@ -215,6 +215,6 @@ std::string convertTimeToHumanReadableString(double dSeconds) {
return buf; return buf;
} }
*/ */
sprintf(buf, "%0.3f s ", dSeconds); sprintf(buf, "%0.3f s", dSeconds);
return std::string(buf); return std::string(buf);
} }
\ No newline at end of file
...@@ -10,17 +10,17 @@ ...@@ -10,17 +10,17 @@
bool ITAStopWatch::m_bInstanceCreated = false; bool ITAStopWatch::m_bInstanceCreated = false;
double ITAStopWatch::m_dStartStopLatency = 0; double ITAStopWatch::m_dStartStopLatency = 0;
ITAStopWatch::ITAStopWatch() ITAStopWatch::ITAStopWatch()
: m_pClock( ITAClock::getDefaultClock() ) : m_pClock( ITAClock::getDefaultClock() )
{ {
// Falls dies die erste Stopwatch ist die erzeugt wird: Latenz messen // Falls dies die erste Stopwatch ist die erzeugt wird: Latenz messen
if (!m_bInstanceCreated) { if( !m_bInstanceCreated ) {
ITACriticalSection cs; ITACriticalSection cs;
cs.enter(); cs.enter();
start(); start();
stop(); stop();
reset(); reset();
for (unsigned int i=0; i<100; i++) { for( unsigned int i = 0; i < 100; i++ ) {
start(); start();
stop(); stop();
} }
...@@ -29,7 +29,7 @@ ITAStopWatch::ITAStopWatch() ...@@ -29,7 +29,7 @@ ITAStopWatch::ITAStopWatch()
/* DEBUG: /* DEBUG:
printf("%s: Measured start/stop latency: %0.3f ns\n", printf("%s: Measured start/stop latency: %0.3f ns\n",
__FUNCTION__, _dStartStopLatency * 1000000000); __FUNCTION__, _dStartStopLatency * 1000000000);
*/ */
m_bInstanceCreated = true; m_bInstanceCreated = true;
...@@ -38,38 +38,36 @@ ITAStopWatch::ITAStopWatch() ...@@ -38,38 +38,36 @@ ITAStopWatch::ITAStopWatch()
reset(); reset();
} }
ITAStopWatch::ITAStopWatch(ITAClock* pClock) ITAStopWatch::ITAStopWatch( ITAClock* pClock )
: m_pClock(pClock) { : m_pClock( pClock )
{
if (pClock == NULL) if( !pClock )
ITA_EXCEPT1(INVALID_PARAMETER, "Clock must not be NULL"); ITA_EXCEPT1( INVALID_PARAMETER, "Clock must not be NULL" );
// Falls dies die erste Stopwatch ist die erzeugt wird: Latenz messen // Falls dies die erste Stopwatch ist die erzeugt wird: Latenz messen
if (!m_bInstanceCreated) { if( !m_bInstanceCreated )
{
ITACriticalSection cs; ITACriticalSection cs;
cs.enter(); cs.enter();
start(); start();
stop(); stop();
reset(); reset();
for (unsigned int i=0; i<100; i++) { for( unsigned int i = 0; i < 100; i++ )
{
start(); start();
stop(); stop();
} }
cs.leave(); cs.leave();
m_dStartStopLatency = minimum(); m_dStartStopLatency = minimum();
/* DEBUG:
printf("%s: Measured start/stop latency: %0.3f ns\n",
__FUNCTION__, _dStartStopLatency * 1000000000);
*/
m_bInstanceCreated = true; m_bInstanceCreated = true;
} }
reset(); reset();
} }
void ITAStopWatch::reset() void ITAStopWatch::reset()
{ {
m_csReadWrite.enter(); m_csReadWrite.enter();
m_uiCycles = 0; m_uiCycles = 0;
...@@ -82,91 +80,117 @@ void ITAStopWatch::reset() ...@@ -82,91 +80,117 @@ void ITAStopWatch::reset()
m_csReadWrite.leave(); m_csReadWrite.leave();
} }
bool ITAStopWatch::started() const { return m_bStarted; } void ITAStopWatch::start()
{
m_dStart = m_pClock->getTime();
m_bStarted = true;
}
bool ITAStopWatch::started() const
{
return m_bStarted;
}
double ITAStopWatch::stop()
{
m_dStop = m_pClock->getTime();
double t = m_dStop - m_dStart - m_dStartStopLatency;
unsigned int ITAStopWatch::cycles() const
{
m_csReadWrite.enter(); m_csReadWrite.enter();
unsigned int uiResult = m_uiCycles;
m_dMin = ( std::min )( m_dMin, t );
m_dMax = ( std::max )( m_dMax, t );
m_dSum += t;
m_dSquareSum += ( t*t );
m_uiCycles++;
m_bStarted = false;
m_csReadWrite.leave(); m_csReadWrite.leave();
return uiResult; return t;
} }
/* unsigned int ITAStopWatch::cycles() const
void ITAStopWatch::setMaxCycles(unsigned int uiMaxCycles)
{ {
m_uiMaxCycles = uiMaxCycles; m_csReadWrite.enter();
unsigned int uiResult = m_uiCycles;
m_csReadWrite.leave();
return uiResult;
} }
*/
double ITAStopWatch::minimum() const double ITAStopWatch::minimum() const
{ {
return (m_uiCycles == 0 ? 0 : m_dMin); return ( m_uiCycles == 0 ? 0 : m_dMin );
} }
double ITAStopWatch::maximum() const { double ITAStopWatch::maximum() const
{
return m_dMax; return m_dMax;
} }
double ITAStopWatch::mean() const double ITAStopWatch::mean() const
{ {
if (m_csReadWrite.tryenter() == true) { if( m_csReadWrite.tryenter() == true )
if (m_uiCycles == 0) { {
if( m_uiCycles == 0 )
{
m_csReadWrite.leave(); m_csReadWrite.leave();
return -1; return 0;
} }
double dResult = m_dSum / m_uiCycles; double dResult = m_dSum / m_uiCycles;
m_csReadWrite.leave(); m_csReadWrite.leave();
return dResult; return dResult;
} }
return -1; return 0;
} }
double ITAStopWatch::variance() const double ITAStopWatch::variance() const
{ {
if (m_csReadWrite.tryenter() == true) { if( m_csReadWrite.tryenter() == true )
if (m_uiCycles == 0) { {
if( m_uiCycles == 0 ) {
m_csReadWrite.leave(); m_csReadWrite.leave();
return -1; return 0;
} }
// Formel: sigma = E(X^2) - E(X)^2 // Formel: sigma = E(X^2) - E(X)^2
double x = (m_dSum / m_uiCycles); double x = ( m_dSum / m_uiCycles );
double dResult = (m_dSquareSum / m_uiCycles) - (x*x); double dResult = ( m_dSquareSum / m_uiCycles ) - ( x*x );
m_csReadWrite.leave(); m_csReadWrite.leave();
return dResult; return dResult;
} }
return -1; return 0;
} }
double ITAStopWatch::std_deviation() const double ITAStopWatch::std_deviation() const
{ {
return sqrt(variance()); return sqrt( variance() );
} }
double ITAStopWatch::selftest() double ITAStopWatch::selftest()
{ {
ITAStopWatch sw; ITAStopWatch sw;
sw.start(); sw.start();
sw.stop(); sw.stop();
sw.reset(); sw.reset();
for (int i=0; i<1000; i++) { for( int i = 0; i < 1000; i++ )
{
sw.start(); sw.start();
sw.stop(); sw.stop();
} }
return sw.mean(); return sw.mean();
} }
std::string TimeToString( double dTimeSeconds) std::string TimeToString( double dTimeSeconds )
{ {
std::stringstream ss; std::stringstream ss;
if( dTimeSeconds < 1e-6 ) if( dTimeSeconds < 1e-6 )
ss << dTimeSeconds / 1e-9 << "us"; ss << dTimeSeconds / 1e-9 << "us";
else if (dTimeSeconds < 1e-3) else if( dTimeSeconds < 1e-3 )
ss << dTimeSeconds / 1e-6 << "ns"; ss << dTimeSeconds / 1e-6 << "ns";
else if (dTimeSeconds < 1e-0) else if( dTimeSeconds < 1e-0 )
ss << dTimeSeconds / 1e-3 << "ms"; ss << dTimeSeconds / 1e-3 << "ms";
else else
ss << dTimeSeconds << "s"; ss << dTimeSeconds << "s";
...@@ -177,30 +201,11 @@ std::string TimeToString( double dTimeSeconds) ...@@ -177,30 +201,11 @@ std::string TimeToString( double dTimeSeconds)
std::string ITAStopWatch::ToString() const std::string ITAStopWatch::ToString() const
{ {
std::ostringstream ss; std::ostringstream ss;
ss << "avg=" << TimeToString(mean()) << ", "; ss << "avg=" << TimeToString( mean() ) << ", ";
ss << "stddev=" << TimeToString(std_deviation()) << ", "; ss << "stddev=" << TimeToString( std_deviation() ) << ", ";
ss << "min=" << TimeToString(minimum()) << ", "; ss << "min=" << TimeToString( minimum() ) << ", ";
ss << "max=" << TimeToString(maximum()) << ", "; ss << "max=" << TimeToString( maximum() ) << ", ";
ss << "cycles=" << cycles(); ss << "cycles=" << cycles();
return ss.str(); return ss.str();
} }
double ITAStopWatch::stop()
{
m_dStop = m_pClock->getTime();
double t = m_dStop - m_dStart - m_dStartStopLatency;
m_csReadWrite.enter();
m_dMin = (std::min)(m_dMin, t);
m_dMax = (std::max)(m_dMax, t);
m_dSum += t;
m_dSquareSum += (t*t);
m_uiCycles++;
m_bStarted = false;
m_csReadWrite.leave();
return t;
}
...@@ -30,3 +30,6 @@ if( ITA_BASE_WITH_SNDFILE ) ...@@ -30,3 +30,6 @@ if( ITA_BASE_WITH_SNDFILE )
set_property( TARGET SampleFrameTest PROPERTY FOLDER "ITACoreLibs/Tests/ITABase" ) set_property( TARGET SampleFrameTest PROPERTY FOLDER "ITACoreLibs/Tests/ITABase" )
endif( ) endif( )
add_subdirectory( "VistaTests" )
cmake_minimum_required( VERSION 2.8 )
project( VistaTests )
list( APPEND CMAKE_MODULE_PATH "$ENV{VISTA_CMAKE_COMMON}" )
include( VistaCommon )
vista_use_package( VistaCoreLibs REQUIRED COMPONENTS VistaInterProcComm FIND_DEPENDENCIES )
add_executable( VistaTickerTest VistaTickerTest.cpp )
target_link_libraries( VistaTickerTest ${VISTA_USE_PACKAGE_LIBRARIES} )
vista_configure_app( VistaTickerTest )
vista_install( VistaTickerTest )
vista_create_default_info_file( VistaTickerTest )
set_property( TARGET VistaTickerTest PROPERTY FOLDER "ITACoreLibs/Tests/Vista" )
#include <VistaInterProcComm/Concurrency/VistaTicker.h>
#include <VistaBase/VistaTimeUtils.h>
#include <iostream>
using namespace std;
class TickerCallback : public VistaTicker::AfterPulseFunctor
{
public:
inline bool operator()()
{
cout << "Ticker callback called, text is: " << sText << endl;
return true;
};
int nGranularityMS;
std::string sText;
};
int main( int, char** )
{
VistaTicker oTicker;
TickerCallback oCallback;
oCallback.sText = "First call";
oCallback.nGranularityMS = oTicker.GetGranularity();
VistaTicker::TriggerContext oTickerContext( oTicker.GetGranularity(), true );
oTicker.SetAfterPulseFunctor( &oCallback );
oTicker.AddTrigger( &oTickerContext );
oTicker.StartTicker();
VistaTimeUtils::Sleep( int( 2*1e3 ) );
oTicker.StopTicker();
oTicker.RemTrigger( &oTickerContext );
oTicker.SetAfterPulseFunctor( NULL ); // Otherwise Ticker will delete callback instance
oCallback.sText = "Second call";
VistaTicker* pTicker = new VistaTicker( 100 );
pTicker->AddTrigger( new VistaTicker::TriggerContext( 100, true ) );
pTicker->SetAfterPulseFunctor( &oCallback );
pTicker->StartTicker();
VistaTimeUtils::Sleep( int( 2 * 1e3 ) );
pTicker->StopTicker();
pTicker->SetAfterPulseFunctor( NULL ); // Otherwise Ticker will delete callback instance
delete pTicker;
return 0;
}