ref: 9a81539c5b758d745ddb9960ef714013cfaeb56f
parent: 3b21a962d4d432cbec3008256d347fb30d87ec69
parent: 628b08182aec5613ab1a8b362766023496cd5763
author: huili2 <[email protected]>
date: Thu Nov 29 04:16:39 EST 2018
Merge pull request #3029 from tanderson-google/remove-si Remove static initializer in WelsThreadPool
--- a/codec/common/inc/WelsThreadPool.h
+++ b/codec/common/inc/WelsThreadPool.h
@@ -100,7 +100,6 @@
WELS_THREAD_ERROR_CODE StopAllRunning();
static int32_t m_iRefCount;
- static CWelsLock m_cInitLock;
static int32_t m_iMaxThreadNum;
static CWelsThreadPool* m_pThreadPoolSelf;
--- a/codec/common/src/WelsThreadPool.cpp
+++ b/codec/common/src/WelsThreadPool.cpp
@@ -43,8 +43,16 @@
namespace WelsCommon {
+namespace {
+
+CWelsLock& GetInitLock() {
+ static CWelsLock *initLock = new CWelsLock;
+ return *initLock;
+}
+
+}
+
int32_t CWelsThreadPool::m_iRefCount = 0;
-CWelsLock CWelsThreadPool::m_cInitLock;
int32_t CWelsThreadPool::m_iMaxThreadNum = DEFAULT_THREAD_NUM;
CWelsThreadPool* CWelsThreadPool::m_pThreadPoolSelf = NULL;
@@ -62,7 +70,7 @@
}
WELS_THREAD_ERROR_CODE CWelsThreadPool::SetThreadNum (int32_t iMaxThreadNum) {
- CWelsAutoLock cLock (m_cInitLock);
+ CWelsAutoLock cLock (GetInitLock());
if (m_iRefCount != 0) {
return WELS_THREAD_ERROR_GENERAL;
@@ -77,7 +85,7 @@
CWelsThreadPool* CWelsThreadPool::AddReference() {
- CWelsAutoLock cLock (m_cInitLock);
+ CWelsAutoLock cLock (GetInitLock());
if (m_pThreadPoolSelf == NULL) {
m_pThreadPoolSelf = new CWelsThreadPool();
if (!m_pThreadPoolSelf) {
@@ -102,7 +110,7 @@
}
void CWelsThreadPool::RemoveInstance() {
- CWelsAutoLock cLock (m_cInitLock);
+ CWelsAutoLock cLock (GetInitLock());
//fprintf(stdout, "m_iRefCount=%d\n", m_iRefCount);
-- m_iRefCount;
if (0 == m_iRefCount) {
@@ -118,7 +126,7 @@
bool CWelsThreadPool::IsReferenced() {
- CWelsAutoLock cLock (m_cInitLock);
+ CWelsAutoLock cLock (GetInitLock());
return (m_iRefCount > 0);
}
@@ -370,5 +378,3 @@
}
}
-
-