mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 23:33:05 +04:00
next(core): use C++11 classes for cv::Mutex/cv::AutoLock
This commit is contained in:
@@ -1101,93 +1101,6 @@ cvErrorFromIppStatus( int status )
|
||||
|
||||
namespace cv {
|
||||
bool __termination = false;
|
||||
}
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
#if defined _WIN32 || defined WINCE
|
||||
|
||||
struct Mutex::Impl
|
||||
{
|
||||
Impl()
|
||||
{
|
||||
#if (_WIN32_WINNT >= 0x0600)
|
||||
::InitializeCriticalSectionEx(&cs, 1000, 0);
|
||||
#else
|
||||
::InitializeCriticalSection(&cs);
|
||||
#endif
|
||||
refcount = 1;
|
||||
}
|
||||
~Impl() { DeleteCriticalSection(&cs); }
|
||||
|
||||
void lock() { EnterCriticalSection(&cs); }
|
||||
bool trylock() { return TryEnterCriticalSection(&cs) != 0; }
|
||||
void unlock() { LeaveCriticalSection(&cs); }
|
||||
|
||||
CRITICAL_SECTION cs;
|
||||
int refcount;
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
struct Mutex::Impl
|
||||
{
|
||||
Impl()
|
||||
{
|
||||
pthread_mutexattr_t attr;
|
||||
pthread_mutexattr_init(&attr);
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
pthread_mutex_init(&mt, &attr);
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
|
||||
refcount = 1;
|
||||
}
|
||||
~Impl() { pthread_mutex_destroy(&mt); }
|
||||
|
||||
void lock() { pthread_mutex_lock(&mt); }
|
||||
bool trylock() { return pthread_mutex_trylock(&mt) == 0; }
|
||||
void unlock() { pthread_mutex_unlock(&mt); }
|
||||
|
||||
pthread_mutex_t mt;
|
||||
int refcount;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Mutex::Mutex()
|
||||
{
|
||||
impl = new Mutex::Impl;
|
||||
}
|
||||
|
||||
Mutex::~Mutex()
|
||||
{
|
||||
if( CV_XADD(&impl->refcount, -1) == 1 )
|
||||
delete impl;
|
||||
impl = 0;
|
||||
}
|
||||
|
||||
Mutex::Mutex(const Mutex& m)
|
||||
{
|
||||
impl = m.impl;
|
||||
CV_XADD(&impl->refcount, 1);
|
||||
}
|
||||
|
||||
Mutex& Mutex::operator = (const Mutex& m)
|
||||
{
|
||||
if (this != &m)
|
||||
{
|
||||
CV_XADD(&m.impl->refcount, 1);
|
||||
if( CV_XADD(&impl->refcount, -1) == 1 )
|
||||
delete impl;
|
||||
impl = m.impl;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Mutex::lock() { impl->lock(); }
|
||||
void Mutex::unlock() { impl->unlock(); }
|
||||
bool Mutex::trylock() { return impl->trylock(); }
|
||||
|
||||
|
||||
//////////////////////////////// thread-local storage ////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user