ref: dd44eea215f18d5f0cda1f6922cee77b540aeb72
parent: b722f3ea47ce546a2320dd825df7d279b1d1f7d2
author: Tom Anderson <thomasanderson@chromium.org>
date: Fri Oct 12 06:34:55 EDT 2018
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;
+ 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 @@
}
}
-
-