Skip to content

Commit bce9a15

Browse files
Workaround for the CI failure under Windows
1 parent 3ef0774 commit bce9a15

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/namedthread.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,18 @@ namespace zim
3131
namespace
3232
{
3333

34+
std::mutex mutex_;
3435
size_t threadCounter_ = 0;
3536
std::vector<const NamedThread*> namedThreads_;
3637
std::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

4247
NamedThread::NamedThread(const std::string& name)
4348
: name_(name)

src/namedthread.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)