Commit 49d71dde authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen
Browse files

Fixing problem with real-time logger thread dtor

parent 786e7ef2
#include "VALog.h"
/* /*
* -------------------------------------------------------------------------------------------- * --------------------------------------------------------------------------------------------
* *
...@@ -12,9 +10,9 @@ ...@@ -12,9 +10,9 @@
* *
* -------------------------------------------------------------------------------------------- * --------------------------------------------------------------------------------------------
*/ */
#include "VALog.h"
#include <algorithm>
#include <VistaInterProcComm/Concurrency/VistaPriority.h> #include <VistaInterProcComm/Concurrency/VistaPriority.h>
#include <algorithm>
std::ostream* VA_STDOUT = &std::cout; std::ostream* VA_STDOUT = &std::cout;
...@@ -68,9 +66,19 @@ CVARealtimeLogger::CVARealtimeLogger() ...@@ -68,9 +66,19 @@ CVARealtimeLogger::CVARealtimeLogger()
//int iPriority = VistaPriority::VISTA_MIN_PRIORITY; //int iPriority = VistaPriority::VISTA_MIN_PRIORITY;
//SetPriority(iPriority); // TODO stienen/wefers: klren wie man eine low priority setzen kann //SetPriority(iPriority); // TODO stienen/wefers: klren wie man eine low priority setzen kann
// @todo: sort out how to properly use vista threads.
Run(); Run();
} }
CVARealtimeLogger::~CVARealtimeLogger()
{
m_bStop = true;
m_evTrigger.SignalEvent();
m_evTrigger.WaitForEvent( true );
StopGently( false );
}
static CVARealtimeLogger g_oInstance; static CVARealtimeLogger g_oInstance;
CVARealtimeLogger* CVARealtimeLogger::GetInstance() CVARealtimeLogger* CVARealtimeLogger::GetInstance()
{ {
...@@ -95,15 +103,6 @@ void CVARealtimeLogger::Unregister( CVARealtimeLogStream* pStream ) ...@@ -95,15 +103,6 @@ void CVARealtimeLogger::Unregister( CVARealtimeLogStream* pStream )
Trigger(); Trigger();
} }
CVARealtimeLogger::~CVARealtimeLogger()
{
m_bStop = true;
m_evTrigger.SignalEvent();
// TODO: Problematisch mit Matlab
// StopGently(false);
StopGently( false );
}
void CVARealtimeLogger::Trigger() void CVARealtimeLogger::Trigger()
{ {
++m_iTriggerCnt; ++m_iTriggerCnt;
...@@ -112,15 +111,21 @@ void CVARealtimeLogger::Trigger() ...@@ -112,15 +111,21 @@ void CVARealtimeLogger::Trigger()
bool CVARealtimeLogger::LoopBody() bool CVARealtimeLogger::LoopBody()
{ {
if( ( m_iTriggerCnt == 0 ) && !m_bStop )
if( ( m_iTriggerCnt == 0 ) && !m_bStop ) { {
// Blockierend warten // Blockierend warten
m_evTrigger.WaitForEvent( true ); m_evTrigger.WaitForEvent( true );
if( m_bStop == true )
{
m_evTrigger.SignalEvent();
return false;
}
// Daten greifen // Daten greifen
std::vector<CVALogItem> vLogItems; std::vector<CVALogItem> vLogItems;
m_mxRegistration.Lock(); m_mxRegistration.Lock();
std::list<CVARealtimeLogStream*>::const_iterator it; std::list< CVARealtimeLogStream* >::const_iterator it;
for( it = m_lpStreams.begin(); it != m_lpStreams.end(); ++it ) for( it = m_lpStreams.begin(); it != m_lpStreams.end(); ++it )
{ {
CVARealtimeLogStream* pStream = *it; CVARealtimeLogStream* pStream = *it;
...@@ -141,7 +146,8 @@ bool CVARealtimeLogger::LoopBody() ...@@ -141,7 +146,8 @@ bool CVARealtimeLogger::LoopBody()
} }
// Stop-Flag berprfen, ggf. selbst beenden // Stop-Flag berprfen, ggf. selbst beenden
if( m_bStop ) { if( m_bStop )
{
IndicateLoopEnd(); IndicateLoopEnd();
return false; return false;
} }
......
...@@ -100,14 +100,14 @@ public: ...@@ -100,14 +100,14 @@ public:
//! Ausgabe //! Ausgabe
bool LoopBody(); bool LoopBody();
void PreLoop() {}; inline void PreLoop() {};
void PostLoop() {}; inline void PostLoop() {};
private: private:
VistaThreadEvent m_evTrigger; VistaThreadEvent m_evTrigger;
ITAAtomicInt m_iTriggerCnt; ITAAtomicInt m_iTriggerCnt;
ITAAtomicBool m_bStop; ITAAtomicBool m_bStop;
std::list<CVARealtimeLogStream*> m_lpStreams; std::list< CVARealtimeLogStream* > m_lpStreams;
VistaMutex m_mxRegistration; VistaMutex m_mxRegistration;
}; };
...@@ -117,29 +117,35 @@ private: ...@@ -117,29 +117,35 @@ private:
* niederpriorisiertem Thread auf die Konsole oder Visual Studio Ausgabe * niederpriorisiertem Thread auf die Konsole oder Visual Studio Ausgabe
* auszugeben. * auszugeben.
*/ */
class CVARealtimeLogStream { class CVARealtimeLogStream
{
public: public:
CVARealtimeLogStream( ITAClock* pClock = ITAClock::getDefaultClock() ) inline CVARealtimeLogStream( ITAClock* pClock = ITAClock::getDefaultClock() )
: m_pClock( pClock ) { : m_pClock( pClock )
{
// Bei Ausgabe-Thread registrieren (Singleton) // Bei Ausgabe-Thread registrieren (Singleton)
CVARealtimeLogger::GetInstance()->Register( this ); CVARealtimeLogger::GetInstance()->Register( this );
} }
virtual ~CVARealtimeLogStream() { virtual ~CVARealtimeLogStream()
{
// Bei Thread deregistieren // Bei Thread deregistieren
CVARealtimeLogger::GetInstance()->Unregister( this ); CVARealtimeLogger::GetInstance()->Unregister( this );
} }
std::string GetName() const { std::string GetName() const
{
return m_sName; return m_sName;
} }
void SetName( const std::string& sName ) { void SetName( const std::string& sName )
{
m_sName = sName; m_sName = sName;
} }
// Ausgabe // Ausgabe
void Printf( const char * format, ... ) { void Printf( const char * format, ... )
{
char buf[ 16384 ]; char buf[ 16384 ];
va_list args; va_list args;
va_start( args, format ); va_start( args, format );
......
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