Adding race protection fot internal members of LogDestination.

parent 89204512
......@@ -240,11 +240,14 @@ namespace Arc {
}
void LogDestination::setPrefix(const std::string& pre) {
Glib::Mutex::Lock lock(mutex);
prefix = pre;
}
std::string LogDestination::getPrefix() const {
return prefix;
Glib::Mutex::Lock lock(mutex);
std::string tmp(prefix);
return tmp;
}
LogStream::LogStream(std::ostream& destination)
......
......@@ -256,6 +256,15 @@ namespace Arc {
friend std::ostream& operator<<(std::ostream& os, const LogDestination& dest);
protected:
/// A mutex for synchronization.
/** This mutex is to be locked before a LogMessage is written and it is
not unlocked until the entire message has been written and the
stream flushed. This is done in order to prevent LogMessages to
appear mixed in the stream and prevent race on modification of
internal members. It is mutable to provide protection while reading members.
*/
mutable Glib::Mutex mutex;
/// Format to use in this LogDestination.
LogFormat format;
......@@ -318,14 +327,6 @@ namespace Arc {
*/
std::ostream& destination;
/// A mutex for synchronization.
/** This mutex is locked before a LogMessage is written and it is
not unlocked until the entire message has been written and the
stream flushed. This is done in order to prevent LogMessages to
appear mixed in the stream.
*/
Glib::Mutex mutex;
};
/// A class for logging to files.
......@@ -410,7 +411,6 @@ namespace Arc {
int maxsize;
int backups;
bool reopen;
Glib::Mutex mutex;
};
class LoggerContextRef;
......
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