Showing the changes to codec/common/src/WelsThreadPool.cpp (1 of 2 files). Show all
Unified · Split
| @@ -43,8 +43,16 @@ · 42 unmodified lines | |||
| 43 | 43 | ||
| 44 | namespace WelsCommon { | 44 | namespace WelsCommon { |
| 45 | 45 | ||
| 46 | namespace { | ||
| 47 | |||
| 48 | CWelsLock& GetInitLock() { | ||
| 49 | static CWelsLock initLock; | ||
| 50 | return initLock; | ||
| 51 | } | ||
| 52 | |||
| 53 | } | ||
| 54 | |||
| 46 | int32_t CWelsThreadPool::m_iRefCount = 0; | 55 | int32_t CWelsThreadPool::m_iRefCount = 0; |
| 47 | CWelsLock CWelsThreadPool::m_cInitLock; | ||
| 48 | int32_t CWelsThreadPool::m_iMaxThreadNum = DEFAULT_THREAD_NUM; | 56 | int32_t CWelsThreadPool::m_iMaxThreadNum = DEFAULT_THREAD_NUM; |
| 49 | CWelsThreadPool* CWelsThreadPool::m_pThreadPoolSelf = NULL; | 57 | CWelsThreadPool* CWelsThreadPool::m_pThreadPoolSelf = NULL; |
| 50 | 58 | ||
| @@ -62,7 +70,7 @@ CWelsThreadPool::~CWelsThreadPool() { · 11 unmodified lines | |||
| 62 | } | 70 | } |
| 63 | 71 | ||
| 64 | WELS_THREAD_ERROR_CODE CWelsThreadPool::SetThreadNum (int32_t iMaxThreadNum) { | 72 | WELS_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 | ||
| 79 | CWelsThreadPool* CWelsThreadPool::AddReference() { | 87 | CWelsThreadPool* 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 | ||
| 104 | void CWelsThreadPool::RemoveInstance() { | 112 | void 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 | ||
| 120 | bool CWelsThreadPool::IsReferenced() { | 128 | bool 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 | |||