mirror of
https://github.com/opencv/opencv.git
synced 2025-06-07 17:44:04 +08:00
core: avoid process cleanup deadlock if TlsStorage is not used
This commit is contained in:
parent
76860933f0
commit
222af8e7e4
@ -388,6 +388,8 @@ cv::Mutex& getInitializationMutex();
|
|||||||
#define CV_SINGLETON_LAZY_INIT(TYPE, INITIALIZER) CV_SINGLETON_LAZY_INIT_(TYPE, INITIALIZER, instance)
|
#define CV_SINGLETON_LAZY_INIT(TYPE, INITIALIZER) CV_SINGLETON_LAZY_INIT_(TYPE, INITIALIZER, instance)
|
||||||
#define CV_SINGLETON_LAZY_INIT_REF(TYPE, INITIALIZER) CV_SINGLETON_LAZY_INIT_(TYPE, INITIALIZER, *instance)
|
#define CV_SINGLETON_LAZY_INIT_REF(TYPE, INITIALIZER) CV_SINGLETON_LAZY_INIT_(TYPE, INITIALIZER, *instance)
|
||||||
|
|
||||||
|
CV_EXPORTS void releaseTlsStorageThread();
|
||||||
|
|
||||||
int cv_snprintf(char* buf, int len, const char* fmt, ...);
|
int cv_snprintf(char* buf, int len, const char* fmt, ...);
|
||||||
int cv_vsnprintf(char* buf, int len, const char* fmt, va_list args);
|
int cv_vsnprintf(char* buf, int len, const char* fmt, va_list args);
|
||||||
}
|
}
|
||||||
|
@ -1583,6 +1583,9 @@ struct ThreadData
|
|||||||
size_t idx; // Thread index in TLS storage. This is not OS thread ID!
|
size_t idx; // Thread index in TLS storage. This is not OS thread ID!
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static bool g_isTlsStorageInitialized = false;
|
||||||
|
|
||||||
// Main TLS storage class
|
// Main TLS storage class
|
||||||
class TlsStorage
|
class TlsStorage
|
||||||
{
|
{
|
||||||
@ -1592,6 +1595,7 @@ public:
|
|||||||
{
|
{
|
||||||
tlsSlots.reserve(32);
|
tlsSlots.reserve(32);
|
||||||
threads.reserve(32);
|
threads.reserve(32);
|
||||||
|
g_isTlsStorageInitialized = true;
|
||||||
}
|
}
|
||||||
~TlsStorage()
|
~TlsStorage()
|
||||||
{
|
{
|
||||||
@ -1810,6 +1814,13 @@ static void WINAPI opencv_fls_destructor(void* pData)
|
|||||||
} // namespace details
|
} // namespace details
|
||||||
using namespace details;
|
using namespace details;
|
||||||
|
|
||||||
|
void releaseTlsStorageThread()
|
||||||
|
{
|
||||||
|
if (!g_isTlsStorageInitialized)
|
||||||
|
return; // nothing to release, so prefer to avoid creation of new global structures
|
||||||
|
getTlsStorage().releaseThread();
|
||||||
|
}
|
||||||
|
|
||||||
TLSDataContainer::TLSDataContainer()
|
TLSDataContainer::TLSDataContainer()
|
||||||
{
|
{
|
||||||
key_ = (int)getTlsStorage().reserveSlot(this); // Reserve key from TLS storage
|
key_ = (int)getTlsStorage().reserveSlot(this); // Reserve key from TLS storage
|
||||||
@ -1893,7 +1904,7 @@ BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID lpReserved)
|
|||||||
{
|
{
|
||||||
// Not allowed to free resources if lpReserved is non-null
|
// Not allowed to free resources if lpReserved is non-null
|
||||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms682583.aspx
|
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms682583.aspx
|
||||||
cv::getTlsStorage().releaseThread();
|
releaseTlsStorageThread();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
Loading…
Reference in New Issue
Block a user