Aufgrund einer Wartung wird GitLab am 26.10. zwischen 8:00 und 9:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 26.10. between 8:00 and 9:00 am.

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