TLS calls on WinRT replaced on variables with C++11 "thread" attribute.

This commit is contained in:
Alexander Smorkalov
2013-07-23 06:44:57 -07:00
parent 6257df1c4b
commit 62b85a41da
4 changed files with 101 additions and 24 deletions

View File

@@ -42,10 +42,6 @@
#include "precomp.hpp"
#if (_WIN32_WINNT >= 0x0602)
#include <synchapi.h>
#endif
#define CV_USE_SYSTEM_MALLOC 1
namespace cv
@@ -98,6 +94,10 @@ void fastFree(void* ptr)
#define STAT(stmt)
#ifdef WIN32
#if (_WIN32_WINNT >= 0x0602)
#include <synchapi.h>
#endif
struct CriticalSection
{
CriticalSection()

View File

@@ -726,33 +726,54 @@ void RNG::fill( InputOutputArray _mat, int disttype,
}
#ifdef WIN32
#ifdef HAVE_WINRT
// using C++11 thread attribute for local thread data
__declspec( thread ) RNG* rng = NULL;
void deleteThreadRNGData()
{
if (rng)
delete rng;
}
RNG& theRNG()
{
if (!rng)
{
rng = new RNG;
}
return *rng;
}
#else
#ifdef WINCE
# define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)
#endif
static DWORD tlsRNGKey = TLS_OUT_OF_INDEXES;
void deleteThreadRNGData()
{
if( tlsRNGKey != TLS_OUT_OF_INDEXES )
delete (RNG*)TlsGetValue( tlsRNGKey );
void deleteThreadRNGData()
{
if( tlsRNGKey != TLS_OUT_OF_INDEXES )
delete (RNG*)TlsGetValue( tlsRNGKey );
}
RNG& theRNG()
{
if( tlsRNGKey == TLS_OUT_OF_INDEXES )
{
tlsRNGKey = TlsAlloc();
CV_Assert(tlsRNGKey != TLS_OUT_OF_INDEXES);
tlsRNGKey = TlsAlloc();
CV_Assert(tlsRNGKey != TLS_OUT_OF_INDEXES);
}
RNG* rng = (RNG*)TlsGetValue( tlsRNGKey );
if( !rng )
{
rng = new RNG;
TlsSetValue( tlsRNGKey, rng );
rng = new RNG;
TlsSetValue( tlsRNGKey, rng );
}
return *rng;
}
#endif //HAVE_WINRT
#else
static pthread_key_t tlsRNGKey = 0;

View File

@@ -48,7 +48,7 @@
#endif
#include <windows.h>
#if (_WIN32_WINNT >= 0x0602)
#include <synchapi.h>
#include <synchapi.h>
#endif
#undef small
#undef min
@@ -80,8 +80,8 @@
#endif
#ifdef HAVE_WINRT
#pragma comment(lib, "MinCore_Downlevel")
#include <wrl/client.h>
#pragma comment(lib, "MinCore_Downlevel")
std::wstring GetTempPathWinRT()
{