mirror of
https://github.com/opencv/opencv.git
synced 2024-11-25 11:40:44 +08:00
Merge pull request #5765 from alalek:pthread_mutex_init
This commit is contained in:
commit
a15707bc57
@ -155,22 +155,9 @@ public:
|
|||||||
|
|
||||||
static ThreadManager& instance()
|
static ThreadManager& instance()
|
||||||
{
|
{
|
||||||
if(!m_instance.ptr)
|
CV_SINGLETON_LAZY_INIT_REF(ThreadManager, new ThreadManager())
|
||||||
{
|
|
||||||
pthread_mutex_lock(&m_manager_access_mutex);
|
|
||||||
|
|
||||||
if(!m_instance.ptr)
|
|
||||||
{
|
|
||||||
m_instance.ptr = new ThreadManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&m_manager_access_mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
return *m_instance.ptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void stop()
|
static void stop()
|
||||||
{
|
{
|
||||||
ThreadManager& manager = instance();
|
ThreadManager& manager = instance();
|
||||||
@ -194,21 +181,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
struct ptr_holder
|
|
||||||
{
|
|
||||||
ThreadManager* ptr;
|
|
||||||
|
|
||||||
ptr_holder(): ptr(NULL) { }
|
|
||||||
|
|
||||||
~ptr_holder()
|
|
||||||
{
|
|
||||||
if(ptr)
|
|
||||||
{
|
|
||||||
delete ptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ThreadManager();
|
ThreadManager();
|
||||||
|
|
||||||
~ThreadManager();
|
~ThreadManager();
|
||||||
@ -231,8 +203,7 @@ private:
|
|||||||
unsigned int m_task_position;
|
unsigned int m_task_position;
|
||||||
unsigned int m_num_of_completed_tasks;
|
unsigned int m_num_of_completed_tasks;
|
||||||
|
|
||||||
static pthread_mutex_t m_manager_access_mutex;
|
pthread_mutex_t m_manager_access_mutex;
|
||||||
static ptr_holder m_instance;
|
|
||||||
|
|
||||||
static const char m_env_name[];
|
static const char m_env_name[];
|
||||||
static const unsigned int m_default_number_of_threads;
|
static const unsigned int m_default_number_of_threads;
|
||||||
@ -250,13 +221,6 @@ private:
|
|||||||
ThreadManagerPoolState m_pool_state;
|
ThreadManagerPoolState m_pool_state;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
|
|
||||||
#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP PTHREAD_RECURSIVE_MUTEX_INITIALIZER
|
|
||||||
#endif
|
|
||||||
|
|
||||||
pthread_mutex_t ThreadManager::m_manager_access_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
|
|
||||||
|
|
||||||
ThreadManager::ptr_holder ThreadManager::m_instance;
|
|
||||||
const char ThreadManager::m_env_name[] = "OPENCV_FOR_THREADS_NUM";
|
const char ThreadManager::m_env_name[] = "OPENCV_FOR_THREADS_NUM";
|
||||||
|
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
@ -383,6 +347,12 @@ ThreadManager::ThreadManager(): m_num_threads(0), m_task_complete(false), m_num_
|
|||||||
{
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
|
pthread_mutexattr_t attr;
|
||||||
|
pthread_mutexattr_init(&attr);
|
||||||
|
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||||
|
res |= pthread_mutex_init(&m_manager_access_mutex, &attr);
|
||||||
|
pthread_mutexattr_destroy(&attr);
|
||||||
|
|
||||||
res |= pthread_mutex_init(&m_manager_task_mutex, NULL);
|
res |= pthread_mutex_init(&m_manager_task_mutex, NULL);
|
||||||
|
|
||||||
res |= pthread_cond_init(&m_cond_thread_task_complete, NULL);
|
res |= pthread_cond_init(&m_cond_thread_task_complete, NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user