From de0cdbc01cc39e4f89a9d012661031a66ba3294f Mon Sep 17 00:00:00 2001 From: sapier Date: Sat, 30 Nov 2013 21:22:15 +0100 Subject: Fix log threadname lookup handling not beeing threadsafe --- src/log.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/log.cpp') diff --git a/src/log.cpp b/src/log.cpp index 366d83b64..527f54480 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -29,6 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc., std::list log_outputs[LMT_NUM_VALUES]; std::map log_threadnames; +JMutex log_threadnamemutex; void log_add_output(ILogOutput *out, enum LogMessageLevel lev) { @@ -60,13 +61,17 @@ void log_remove_output(ILogOutput *out) void log_register_thread(const std::string &name) { threadid_t id = get_current_thread_id(); + log_threadnamemutex.Lock(); log_threadnames[id] = name; + log_threadnamemutex.Unlock(); } void log_deregister_thread() { threadid_t id = get_current_thread_id(); + log_threadnamemutex.Lock(); log_threadnames.erase(id); + log_threadnamemutex.Unlock(); } static std::string get_lev_string(enum LogMessageLevel lev) @@ -144,7 +149,7 @@ public: } m_buf += c; } - + private: enum LogMessageLevel m_lev; std::string m_buf; -- cgit v1.2.3