History

Remove static initializer in WelsThreadPool

Tom Anderson committed 8 years ago

Commit dd44eea1 parent b722f3e2 files · +13 −8Browse files

Showing the changes to codec/common/src/WelsThreadPool.cpp (1 of 2 files). Show all

Unified · Split

codec/common/src/WelsThreadPool.cpp+13−7
@@ -43,8 +43,16 @@ · 42 unmodified lines
4343
4444 namespace WelsCommon {
4545
46+namespace {
47+
48+CWelsLock& GetInitLock() {
49+ static CWelsLock initLock;
50+ return initLock;
51+}
52+
53+}
54+
4655 int32_t CWelsThreadPool::m_iRefCount = 0;
47−CWelsLock CWelsThreadPool::m_cInitLock;
4856 int32_t CWelsThreadPool::m_iMaxThreadNum = DEFAULT_THREAD_NUM;
4957 CWelsThreadPool* CWelsThreadPool::m_pThreadPoolSelf = NULL;
5058
@@ -62,7 +70,7 @@ CWelsThreadPool::~CWelsThreadPool() { · 11 unmodified lines
6270 }
6371
6472 WELS_THREAD_ERROR_CODE CWelsThreadPool::SetThreadNum (int32_t iMaxThreadNum) {
65− CWelsAutoLock cLock (m_cInitLock);
73+ CWelsAutoLock cLock (GetInitLock());
6674
6775 if (m_iRefCount != 0) {
6876 return WELS_THREAD_ERROR_GENERAL;
@@ -77,7 +85,7 @@ WELS_THREAD_ERROR_CODE CWelsThreadPool::SetThreadNum (int32_t iMaxThreadNum) { · 8 unmodified lines
7785
7886
7987 CWelsThreadPool* CWelsThreadPool::AddReference() {
80− CWelsAutoLock cLock (m_cInitLock);
88+ CWelsAutoLock cLock (GetInitLock());
8189 if (m_pThreadPoolSelf == NULL) {
8290 m_pThreadPoolSelf = new CWelsThreadPool();
8391 if (!m_pThreadPoolSelf) {
@@ -102,7 +110,7 @@ CWelsThreadPool* CWelsThreadPool::AddReference() { · 18 unmodified lines
102110 }
103111
104112 void CWelsThreadPool::RemoveInstance() {
105− CWelsAutoLock cLock (m_cInitLock);
113+ CWelsAutoLock cLock (GetInitLock());
106114 //fprintf(stdout, "m_iRefCount=%d\n", m_iRefCount);
107115 -- m_iRefCount;
108116 if (0 == m_iRefCount) {
@@ -118,7 +126,7 @@ void CWelsThreadPool::RemoveInstance() { · 9 unmodified lines
118126
119127
120128 bool CWelsThreadPool::IsReferenced() {
121− CWelsAutoLock cLock (m_cInitLock);
129+ CWelsAutoLock cLock (GetInitLock());
122130 return (m_iRefCount > 0);
123131 }
124132
@@ -370,5 +378,3 @@ void CWelsThreadPool::ClearWaitedTasks() { · 245 unmodified lines
370378 }
371379
372380 }
373−
374−

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t