...
 
Commits (10)
......@@ -122,7 +122,8 @@ template< class T > void ITABufferedDataLogger< T >::setOutputFile( const std::s
m_sOutputFile = sFilename;
};
template< class T > void ITABufferedDataLogger< T >::clear() {
template< class T > void ITABufferedDataLogger< T >::clear()
{
m_vLogItems.clear();
};
......
......@@ -16,8 +16,8 @@
*
*/
#ifndef INCLUDE_WATCHER_ITA_SAMPLEFRAME
#define INCLUDE_WATCHER_ITA_SAMPLEFRAME
#ifndef INCLUDE_WATCHER_ITA_SAMPLE_FRAME
#define INCLUDE_WATCHER_ITA_SAMPLE_FRAME
// ITABase
#include <ITABaseDefinitions.h>
......@@ -114,10 +114,12 @@ public:
* \param bZeroinit Samples mit Nullen initialisieren?
*/
void Init( int iChannels, int iLength, bool bZeroinit );
//! Legacy Init with small caps style
inline void init( int iChannels, int iLength, bool bZeroinit )
{
return Init( iChannels, iLength, bZeroinit );
}
};
void Load( const std::string& sFilePath );
void Load( const std::string& sFilePath, double& dSampleRate );
......@@ -360,4 +362,4 @@ private:
typedef std::vector<ITASampleBuffer>::iterator ch_it;
};
#endif // INCLUDE_WATCHER_ITA_SAMPLEFRAME
#endif // INCLUDE_WATCHER_ITA_SAMPLE_FRAME
......@@ -66,11 +66,7 @@ public:
/**
* \note Wurde bereits die Zeitnahme gestartet, wird eine Ausnahme ausgelöst
*/
inline void start()
{
m_dStart = m_pClock->getTime();
m_bStarted = true;
}
void start();
//! 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 <stdint.h>
typedef union {
typedef union
{
int32_t i32Value;
float floatValue;
} ConvI32Float;
int atomic_read_int(volatile const int* src)
int atomic_read_int( volatile const int* 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( (int*) src, 0, 0 );
* Trick: Realisierung mittels CAS!
* Falls der Wert schon 0, dann wird er gegen 0 ausgetauscht...
* Also keine Änderung!
*/
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!
* Falls der Wert schon 0, dann wird er gegen 0 ausgetauscht...
......@@ -45,59 +40,74 @@ float atomic_read_float(volatile const float* src) {
*/
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;
}
void* atomic_read_ptr(volatile const void** src) {
void* atomic_read_ptr( volatile const void** 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((void**) src, 0, 0);
return __sync_val_compare_and_swap( ( void** ) src, 0, 0 );
}
void atomic_write_int(volatile int* dest, int value) {
__sync_lock_test_and_set(dest, value);
void atomic_write_int( volatile int* dest, int 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;
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) {
__sync_lock_test_and_set(dest, value);
void atomic_write_ptr( volatile void** dest, void* value )
{
__sync_lock_test_and_set( dest, 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);
bool atomic_cas_int( volatile int* dest, int expected_value, int 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) {
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) {
return __sync_bool_compare_and_swap(dest, expected_value, 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 );
}
void atomic_read32(volatile void* src, void* dest) {
*((int32_t*) dest) = __sync_val_compare_and_swap((volatile int32_t*) src, 0, 0);
void atomic_read32( volatile void* src, void* dest )
{
*( ( 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) {
return __sync_bool_compare_and_swap((volatile int32_t*)dest, *(int32_t*)expected_value, *(int32_t*)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 );
}
int atomic_inc_int(volatile int* dest) {
return __sync_fetch_and_add(dest, 1);
int atomic_inc_int( volatile int* dest )
{
return __sync_fetch_and_add( dest, 1 );
}
int atomic_dec_int(volatile int* dest) {
return __sync_fetch_and_sub(dest, 1);
int atomic_dec_int( volatile int* dest )
{
return __sync_fetch_and_sub( dest, 1 );
}
......@@ -2,7 +2,7 @@
#include <ITAAudiofileWriter.h>
#include <ITAConstants.h>
#include <ITAFilesystemUtils.h>
#include <ITAFileSystemUtils.h>
#include <ITAHDFTSpectrum.h>
#include <ITASampleFrame.h>
#include <ITAStringUtils.h>
......
......@@ -215,6 +215,6 @@ std::string convertTimeToHumanReadableString(double dSeconds) {
return buf;
}
*/
sprintf(buf, "%0.3f s ", dSeconds);
sprintf(buf, "%0.3f s", dSeconds);
return std::string(buf);
}
\ No newline at end of file
......@@ -10,17 +10,17 @@
bool ITAStopWatch::m_bInstanceCreated = false;
double ITAStopWatch::m_dStartStopLatency = 0;
ITAStopWatch::ITAStopWatch()
: m_pClock( ITAClock::getDefaultClock() )
ITAStopWatch::ITAStopWatch()
: m_pClock( ITAClock::getDefaultClock() )
{
// Falls dies die erste Stopwatch ist die erzeugt wird: Latenz messen
if (!m_bInstanceCreated) {
if( !m_bInstanceCreated ) {
ITACriticalSection cs;
cs.enter();
start();
stop();
reset();
for (unsigned int i=0; i<100; i++) {
for( unsigned int i = 0; i < 100; i++ ) {
start();
stop();
}
......@@ -29,7 +29,7 @@ ITAStopWatch::ITAStopWatch()
/* DEBUG:
printf("%s: Measured start/stop latency: %0.3f ns\n",
__FUNCTION__, _dStartStopLatency * 1000000000);
__FUNCTION__, _dStartStopLatency * 1000000000);
*/
m_bInstanceCreated = true;
......@@ -38,38 +38,36 @@ ITAStopWatch::ITAStopWatch()
reset();
}
ITAStopWatch::ITAStopWatch(ITAClock* pClock)
: m_pClock(pClock) {
ITAStopWatch::ITAStopWatch( ITAClock* pClock )
: m_pClock( pClock )
{
if (pClock == NULL)
ITA_EXCEPT1(INVALID_PARAMETER, "Clock must not be NULL");
if( !pClock )
ITA_EXCEPT1( INVALID_PARAMETER, "Clock must not be NULL" );
// Falls dies die erste Stopwatch ist die erzeugt wird: Latenz messen
if (!m_bInstanceCreated) {
if( !m_bInstanceCreated )
{
ITACriticalSection cs;
cs.enter();
start();
stop();
reset();
for (unsigned int i=0; i<100; i++) {
for( unsigned int i = 0; i < 100; i++ )
{
start();
stop();
}
cs.leave();
m_dStartStopLatency = minimum();
/* DEBUG:
printf("%s: Measured start/stop latency: %0.3f ns\n",
__FUNCTION__, _dStartStopLatency * 1000000000);
*/
m_bInstanceCreated = true;
}
reset();
}
void ITAStopWatch::reset()
void ITAStopWatch::reset()
{
m_csReadWrite.enter();
m_uiCycles = 0;
......@@ -82,91 +80,117 @@ void ITAStopWatch::reset()
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();
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();
return uiResult;
return t;
}
/*
void ITAStopWatch::setMaxCycles(unsigned int uiMaxCycles)
unsigned int ITAStopWatch::cycles() const
{
m_uiMaxCycles = uiMaxCycles;
m_csReadWrite.enter();
unsigned int uiResult = m_uiCycles;
m_csReadWrite.leave();
return uiResult;
}
*/
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;
}
double ITAStopWatch::mean() const
{
if (m_csReadWrite.tryenter() == true) {
if (m_uiCycles == 0) {
if( m_csReadWrite.tryenter() == true )
{
if( m_uiCycles == 0 )
{
m_csReadWrite.leave();
return -1;
return 0;
}
double dResult = m_dSum / m_uiCycles;
m_csReadWrite.leave();
return dResult;
}
return -1;
return 0;
}
double ITAStopWatch::variance() const
{
if (m_csReadWrite.tryenter() == true) {
if (m_uiCycles == 0) {
if( m_csReadWrite.tryenter() == true )
{
if( m_uiCycles == 0 ) {
m_csReadWrite.leave();
return -1;
return 0;
}
// Formel: sigma = E(X^2) - E(X)^2
double x = (m_dSum / m_uiCycles);
double dResult = (m_dSquareSum / m_uiCycles) - (x*x);
double x = ( m_dSum / m_uiCycles );
double dResult = ( m_dSquareSum / m_uiCycles ) - ( x*x );
m_csReadWrite.leave();
return dResult;
}
return -1;
return 0;
}
double ITAStopWatch::std_deviation() const
{
return sqrt(variance());
double ITAStopWatch::std_deviation() const
{
return sqrt( variance() );
}
double ITAStopWatch::selftest()
double ITAStopWatch::selftest()
{
ITAStopWatch sw;
sw.start();
sw.stop();
sw.reset();
for (int i=0; i<1000; i++) {
for( int i = 0; i < 1000; i++ )
{
sw.start();
sw.stop();
}
return sw.mean();
}
std::string TimeToString( double dTimeSeconds)
std::string TimeToString( double dTimeSeconds )
{
std::stringstream ss;
if( dTimeSeconds < 1e-6 )
ss << dTimeSeconds / 1e-9 << "us";
else if (dTimeSeconds < 1e-3)
else if( dTimeSeconds < 1e-3 )
ss << dTimeSeconds / 1e-6 << "ns";
else if (dTimeSeconds < 1e-0)
else if( dTimeSeconds < 1e-0 )
ss << dTimeSeconds / 1e-3 << "ms";
else
ss << dTimeSeconds << "s";
......@@ -177,30 +201,11 @@ std::string TimeToString( double dTimeSeconds)
std::string ITAStopWatch::ToString() const
{
std::ostringstream ss;
ss << "avg=" << TimeToString(mean()) << ", ";
ss << "stddev=" << TimeToString(std_deviation()) << ", ";
ss << "min=" << TimeToString(minimum()) << ", ";
ss << "max=" << TimeToString(maximum()) << ", ";
ss << "avg=" << TimeToString( mean() ) << ", ";
ss << "stddev=" << TimeToString( std_deviation() ) << ", ";
ss << "min=" << TimeToString( minimum() ) << ", ";
ss << "max=" << TimeToString( maximum() ) << ", ";
ss << "cycles=" << cycles();
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 )
set_property( TARGET SampleFrameTest PROPERTY FOLDER "ITACoreLibs/Tests/ITABase" )
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;
}