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
43 43
44namespace WelsCommon {44namespace WelsCommon {
45 45
46namespace {
47
48CWelsLock& GetInitLock() {
49 static CWelsLock initLock;
50 return initLock;
51}
52
53}
54
46int32_t CWelsThreadPool::m_iRefCount = 0;55int32_t CWelsThreadPool::m_iRefCount = 0;
47CWelsLock CWelsThreadPool::m_cInitLock;
48int32_t CWelsThreadPool::m_iMaxThreadNum = DEFAULT_THREAD_NUM;56int32_t CWelsThreadPool::m_iMaxThreadNum = DEFAULT_THREAD_NUM;
49CWelsThreadPool* CWelsThreadPool::m_pThreadPoolSelf = NULL;57CWelsThreadPool* CWelsThreadPool::m_pThreadPoolSelf = NULL;
50 58
@@ -62,7 +70,7 @@ CWelsThreadPool::~CWelsThreadPool() { · 11 unmodified lines
62}70}
63 71
64WELS_THREAD_ERROR_CODE CWelsThreadPool::SetThreadNum (int32_t iMaxThreadNum) {72WELS_THREAD_ERROR_CODE CWelsThreadPool::SetThreadNum (int32_t iMaxThreadNum) {
65 CWelsAutoLock cLock (m_cInitLock);73 CWelsAutoLock cLock (GetInitLock());
66 74
67 if (m_iRefCount != 0) {75 if (m_iRefCount != 0) {
68 return WELS_THREAD_ERROR_GENERAL;76 return WELS_THREAD_ERROR_GENERAL;
@@ -77,7 +85,7 @@ WELS_THREAD_ERROR_CODE CWelsThreadPool::SetThreadNum (int32_t iMaxThreadNum) { · 8 unmodified lines
77 85
78 86
79CWelsThreadPool* CWelsThreadPool::AddReference() {87CWelsThreadPool* CWelsThreadPool::AddReference() {
80 CWelsAutoLock cLock (m_cInitLock);88 CWelsAutoLock cLock (GetInitLock());
81 if (m_pThreadPoolSelf == NULL) {89 if (m_pThreadPoolSelf == NULL) {
82 m_pThreadPoolSelf = new CWelsThreadPool();90 m_pThreadPoolSelf = new CWelsThreadPool();
83 if (!m_pThreadPoolSelf) {91 if (!m_pThreadPoolSelf) {
@@ -102,7 +110,7 @@ CWelsThreadPool* CWelsThreadPool::AddReference() { · 18 unmodified lines
102}110}
103 111
104void CWelsThreadPool::RemoveInstance() {112void CWelsThreadPool::RemoveInstance() {
105 CWelsAutoLock cLock (m_cInitLock);113 CWelsAutoLock cLock (GetInitLock());
106 //fprintf(stdout, "m_iRefCount=%d\n", m_iRefCount);114 //fprintf(stdout, "m_iRefCount=%d\n", m_iRefCount);
107 -- m_iRefCount;115 -- m_iRefCount;
108 if (0 == m_iRefCount) {116 if (0 == m_iRefCount) {
@@ -118,7 +126,7 @@ void CWelsThreadPool::RemoveInstance() { · 9 unmodified lines
118 126
119 127
120bool CWelsThreadPool::IsReferenced() {128bool CWelsThreadPool::IsReferenced() {
121 CWelsAutoLock cLock (m_cInitLock);129 CWelsAutoLock cLock (GetInitLock());
122 return (m_iRefCount > 0);130 return (m_iRefCount > 0);
123}131}
124 132
@@ -370,5 +378,3 @@ void CWelsThreadPool::ClearWaitedTasks() { · 245 unmodified lines
370}378}
371 379
372}380}
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