mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-06 00:31:10 +01:00
AtomicCounter fix for GH #282: Using Thread in a global can cause crash on Windows
This commit is contained in:
parent
b5ce0804a1
commit
c2704199ae
@ -18,6 +18,7 @@
|
|||||||
#include "Poco/Mutex.h"
|
#include "Poco/Mutex.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#include "Poco/ThreadLocal.h"
|
#include "Poco/ThreadLocal.h"
|
||||||
|
#include "Poco/AtomicCounter.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
|
||||||
@ -144,23 +145,10 @@ std::string Thread::makeName()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
FastMutex& getUniqueIdMutex()
|
|
||||||
{
|
|
||||||
static FastMutex uniqueIdMutex;
|
|
||||||
return uniqueIdMutex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int Thread::uniqueId()
|
int Thread::uniqueId()
|
||||||
{
|
{
|
||||||
FastMutex::ScopedLock lock(getUniqueIdMutex());
|
static Poco::AtomicCounter counter;
|
||||||
|
return ++counter;
|
||||||
static unsigned count = 0;
|
|
||||||
++count;
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user