Commit 62b85a41 authored by Alexander Smorkalov's avatar Alexander Smorkalov

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

parent 6257df1c
...@@ -16,10 +16,23 @@ namespace cv ...@@ -16,10 +16,23 @@ namespace cv
list.clear(); list.clear();
std::string path_f = path + "/" + exten; std::string path_f = path + "/" + exten;
#ifdef WIN32 #ifdef WIN32
#if HAVE_WINRT
WIN32_FIND_DATAW FindFileData;
#else
WIN32_FIND_DATA FindFileData; WIN32_FIND_DATA FindFileData;
HANDLE hFind; #endif
HANDLE hFind;
hFind = FindFirstFile((LPCSTR)path_f.c_str(), &FindFileData);
#ifdef HAVE_WINRT
size_t size = mbstowcs(NULL, path_f.c_str(), path_f.size());
wchar_t* wpath = (wchar_t*)malloc((size+1)*sizeof(wchar_t));
wpath[size] = 0;
mbstowcs(wpath, path_f.c_str(), path_f.size());
hFind = FindFirstFileW(wpath, &FindFileData);
free(wpath);
#else
hFind = FindFirstFileA((LPCSTR)path_f.c_str(), &FindFileData);
#endif
if (hFind == INVALID_HANDLE_VALUE) if (hFind == INVALID_HANDLE_VALUE)
{ {
return list; return list;
...@@ -34,13 +47,29 @@ namespace cv ...@@ -34,13 +47,29 @@ namespace cv
FindFileData.dwFileAttributes == FILE_ATTRIBUTE_SYSTEM || FindFileData.dwFileAttributes == FILE_ATTRIBUTE_SYSTEM ||
FindFileData.dwFileAttributes == FILE_ATTRIBUTE_READONLY) FindFileData.dwFileAttributes == FILE_ATTRIBUTE_READONLY)
{ {
char* fname;
#ifdef HAVE_WINRT
size_t asize = wcstombs(NULL, FindFileData.cFileName, 0);
char* fname = (char*)malloc((asize+1)*sizeof(char));
fname[asize] = 0;
wcstombs(fname, FindFileData.cFileName, asize);
#else
fname = FindFileData.cFileName;
#endif
if (addPath) if (addPath)
list.push_back(path + "/" + FindFileData.cFileName); list.push_back(path + "/" + fname);
else else
list.push_back(FindFileData.cFileName); list.push_back(fname);
#ifdef HAVE_WINRT
free(fname);
#endif
} }
} }
while(FindNextFile(hFind, &FindFileData)); #ifdef HAVE_WINRT
while(FindNextFileW(hFind, &FindFileData));
#else
while(FindNextFileA(hFind, &FindFileData));
#endif
FindClose(hFind); FindClose(hFind);
} }
#else #else
...@@ -75,10 +104,23 @@ namespace cv ...@@ -75,10 +104,23 @@ namespace cv
std::string path_f = path + "/" + exten; std::string path_f = path + "/" + exten;
list.clear(); list.clear();
#ifdef WIN32 #ifdef WIN32
#if HAVE_WINRT
WIN32_FIND_DATAW FindFileData;
#else
WIN32_FIND_DATA FindFileData; WIN32_FIND_DATA FindFileData;
#endif
HANDLE hFind; HANDLE hFind;
hFind = FindFirstFile((LPCSTR)path_f.c_str(), &FindFileData); #ifdef HAVE_WINRT
size_t size = mbstowcs(NULL, path_f.c_str(), path_f.size());
wchar_t* wpath = (wchar_t*)malloc((size+1)*sizeof(wchar_t));
wpath[size] = 0;
mbstowcs(wpath, path_f.c_str(), path_f.size());
hFind = FindFirstFileW(wpath, &FindFileData);
free(wpath);
#else
hFind = FindFirstFileA((LPCSTR)path_f.c_str(), &FindFileData);
#endif
if (hFind == INVALID_HANDLE_VALUE) if (hFind == INVALID_HANDLE_VALUE)
{ {
return list; return list;
...@@ -91,13 +133,27 @@ namespace cv ...@@ -91,13 +133,27 @@ namespace cv
strcmp(FindFileData.cFileName, ".") != 0 && strcmp(FindFileData.cFileName, ".") != 0 &&
strcmp(FindFileData.cFileName, "..") != 0) strcmp(FindFileData.cFileName, "..") != 0)
{ {
char* fname;
#ifdef HAVE_WINRT
size_t asize = wcstombs(NULL, FindFileData.cFileName, 0);
char* fname = (char*)malloc((asize+1)*sizeof(char));
fname[asize] = 0;
wcstombs(fname, FindFileData.cFileName, asize);
#else
fname = FindFileData.cFileName;
#endif
if (addPath) if (addPath)
list.push_back(path + "/" + FindFileData.cFileName); list.push_back(path + "/" + fname);
else else
list.push_back(FindFileData.cFileName); list.push_back(fname);
} }
} }
while(FindNextFile(hFind, &FindFileData)); #ifdef HAVE_WINRT
while(FindNextFileW(hFind, &FindFileData));
#else
while(FindNextFileA(hFind, &FindFileData));
#endif
FindClose(hFind); FindClose(hFind);
} }
......
...@@ -42,10 +42,6 @@ ...@@ -42,10 +42,6 @@
#include "precomp.hpp" #include "precomp.hpp"
#if (_WIN32_WINNT >= 0x0602)
#include <synchapi.h>
#endif
#define CV_USE_SYSTEM_MALLOC 1 #define CV_USE_SYSTEM_MALLOC 1
namespace cv namespace cv
...@@ -98,6 +94,10 @@ void fastFree(void* ptr) ...@@ -98,6 +94,10 @@ void fastFree(void* ptr)
#define STAT(stmt) #define STAT(stmt)
#ifdef WIN32 #ifdef WIN32
#if (_WIN32_WINNT >= 0x0602)
#include <synchapi.h>
#endif
struct CriticalSection struct CriticalSection
{ {
CriticalSection() CriticalSection()
......
...@@ -726,33 +726,54 @@ void RNG::fill( InputOutputArray _mat, int disttype, ...@@ -726,33 +726,54 @@ void RNG::fill( InputOutputArray _mat, int disttype,
} }
#ifdef WIN32 #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 #ifdef WINCE
# define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF) # define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)
#endif #endif
static DWORD tlsRNGKey = TLS_OUT_OF_INDEXES; static DWORD tlsRNGKey = TLS_OUT_OF_INDEXES;
void deleteThreadRNGData() void deleteThreadRNGData()
{ {
if( tlsRNGKey != TLS_OUT_OF_INDEXES ) if( tlsRNGKey != TLS_OUT_OF_INDEXES )
delete (RNG*)TlsGetValue( tlsRNGKey ); delete (RNG*)TlsGetValue( tlsRNGKey );
} }
RNG& theRNG() RNG& theRNG()
{ {
if( tlsRNGKey == TLS_OUT_OF_INDEXES ) if( tlsRNGKey == TLS_OUT_OF_INDEXES )
{ {
tlsRNGKey = TlsAlloc(); tlsRNGKey = TlsAlloc();
CV_Assert(tlsRNGKey != TLS_OUT_OF_INDEXES); CV_Assert(tlsRNGKey != TLS_OUT_OF_INDEXES);
} }
RNG* rng = (RNG*)TlsGetValue( tlsRNGKey ); RNG* rng = (RNG*)TlsGetValue( tlsRNGKey );
if( !rng ) if( !rng )
{ {
rng = new RNG; rng = new RNG;
TlsSetValue( tlsRNGKey, rng ); TlsSetValue( tlsRNGKey, rng );
} }
return *rng; return *rng;
} }
#endif //HAVE_WINRT
#else #else
static pthread_key_t tlsRNGKey = 0; static pthread_key_t tlsRNGKey = 0;
......
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
#endif #endif
#include <windows.h> #include <windows.h>
#if (_WIN32_WINNT >= 0x0602) #if (_WIN32_WINNT >= 0x0602)
#include <synchapi.h> #include <synchapi.h>
#endif #endif
#undef small #undef small
#undef min #undef min
...@@ -80,8 +80,8 @@ ...@@ -80,8 +80,8 @@
#endif #endif
#ifdef HAVE_WINRT #ifdef HAVE_WINRT
#pragma comment(lib, "MinCore_Downlevel")
#include <wrl/client.h> #include <wrl/client.h>
#pragma comment(lib, "MinCore_Downlevel")
std::wstring GetTempPathWinRT() std::wstring GetTempPathWinRT()
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment