File tree Expand file tree Collapse file tree 2 files changed +17
-6
lines changed
Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -31,13 +31,18 @@ namespace zim
3131namespace
3232{
3333
34+ std::mutex mutex_;
3435size_t threadCounter_ = 0 ;
3536std::vector<const NamedThread*> namedThreads_;
3637std::map<std::thread::id, std::string> threadId2NameMap_;
3738
3839} // unnamed namespace
3940
40- std::mutex NamedThread::mutex_;
41+
42+ std::mutex& NamedThread::getMutex ()
43+ {
44+ return mutex_;
45+ }
4146
4247NamedThread::NamedThread (const std::string& name)
4348 : name_(name)
Original file line number Diff line number Diff line change @@ -43,9 +43,10 @@ class LIBZIM_PRIVATE_API NamedThread
4343 // the thread_ data member has completed (so that any possible
4444 // calls to NamedThread::getCurrentThreadName() from inside f()
4545 // read the correct value of thread id).
46- std::lock_guard<std::mutex> lock (mutex_);
46+ std::mutex& mutex = getMutex ();
47+ std::lock_guard<std::mutex> lock (mutex);
4748
48- thread_ = std::thread ([f]() { mutex_ .lock (); mutex_ .unlock (); f (); });
49+ thread_ = std::thread ([f, &mutex ]() { mutex .lock (); mutex .unlock (); f (); });
4950 }
5051
5152 ~NamedThread ();
@@ -57,11 +58,16 @@ class LIBZIM_PRIVATE_API NamedThread
5758
5859 static std::string getCurrentThreadName ();
5960
60- private:
61+ private: // functions
62+
63+ // This is a workaround for a bug in our build system that prevents
64+ // LIBZIM_PRIVATE_API and/or LIBZIM_API classes from having static data
65+ // members
66+ static std::mutex& getMutex ();
67+
68+ private: // data
6169 const std::string name_;
6270 std::thread thread_;
63-
64- static std::mutex mutex_;
6571};
6672
6773} // namespace zim
You can’t perform that action at this time.
0 commit comments