From 1d16151e84e9fc7f53c9ee5d7c5e56034d741df0 Mon Sep 17 00:00:00 2001 From: austriancoder Date: Sat, 9 Oct 2004 16:50:10 +0000 Subject: logger now thread safe --- HISTORY | 5 +++-- dxr3log.c | 3 +++ dxr3log.h | 16 +++++++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/HISTORY b/HISTORY index a34866b..8197c4a 100644 --- a/HISTORY +++ b/HISTORY @@ -230,7 +230,7 @@ NOTE: I havent found time to include all of the languages, will be done in pre2 - fixed dxr3osd_subpicutre.c - thanks to Paavo Hartikainen -2004-0?-??: Version 0.2.3-pre3 +2004-??-??: Version 0.2.3-pre3 - fixed output of anamorphic video, if tv aspect is configured to 16:9 in DVB setup menu thanks Seppo Ingalsuo @@ -254,4 +254,5 @@ NOTE: I havent found time to include all of the languages, will be done in pre2 because the pre2 seems to put this dxr3plugin.log random in some folders - reporded by Martin Dauskardt - extended cDxr3MemcpyBench::Rdtsc(uint32_t config_flags) support for non x86 arch - support for cpu's, which dont support rdtsc timing \ No newline at end of file + support for cpu's, which dont support rdtsc timing +- logger now thread safe \ No newline at end of file diff --git a/dxr3log.c b/dxr3log.c index 680dd6b..0095c57 100644 --- a/dxr3log.c +++ b/dxr3log.c @@ -21,6 +21,9 @@ #include "dxr3log.h" +// ================================== +cMutex* cLog::m_pMutex = new cMutex; + // ================================== //! constructor cLog::cLog() diff --git a/dxr3log.h b/dxr3log.h index bfabfe6..fdb6bbd 100644 --- a/dxr3log.h +++ b/dxr3log.h @@ -25,6 +25,7 @@ #include #include #include "dxr3singleton.h" +#include "dxr3vdrincludes.h" // ================================== //! A log class. @@ -32,6 +33,7 @@ With this nice util dxr3plugin generates and mange a log file. In this file the developer/enduser can find informations and can find errors, problems and ohter stuff. + The logging class is now thread-safe! */ class cLog : public Singleton { @@ -41,31 +43,36 @@ public: ~cLog() { Close(); } - void SetForceFlush(const bool v) { m_ForeFlush = v; } + void SetForceFlush(const bool v) { Lock(); m_ForeFlush = v; Unlock(); } bool GetForceFlush() const { return m_ForeFlush; } // write type data to log file. template inline cLog& operator << ( Type item ) { + Lock(); if (m_LogOpen) { m_LogStream << item; if (m_ForeFlush) m_LogStream.flush(); } + Unlock(); return *this; } inline cLog& operator << ( size_t item ) { + Lock(); if (m_LogOpen) { m_LogStream << (unsigned int)item; if (m_ForeFlush) m_LogStream.flush(); } + Unlock(); return *this; } inline cLog& operator << ( bool item ) { + Lock(); if (m_LogOpen) { if (item == true) @@ -78,6 +85,7 @@ public: } if (m_ForeFlush) m_LogStream.flush(); } + Unlock(); return *this; } @@ -88,6 +96,12 @@ private: void Open(std::string Filename); // with this function we open our logfile void Close(); // with this function we close our logfile + +protected: + static cMutex* m_pMutex; ///< mutex + + static void Lock() { cLog::m_pMutex->Lock(); } + static void Unlock() { cLog::m_pMutex->Unlock(); } }; -- cgit v1.2.3