History

remove sink in WelsThreadPool and hide the construtor to finish the singleTon

sijchen committed 10 years ago

Commit 4db9c321 parent d4f09d97 files · +28 −54Browse files

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

Unified · Split

codec/common/src/WelsThreadPool.cpp+14−19
@@ -47,8 +47,8 @@ int32_t CWelsThreadPool::m_iRefCount = 0; · 46 unmodified lines
47CWelsLock CWelsThreadPool::m_cInitLock;47CWelsLock CWelsThreadPool::m_cInitLock;
48int32_t CWelsThreadPool::m_iMaxThreadNum = DEFAULT_THREAD_NUM;48int32_t CWelsThreadPool::m_iMaxThreadNum = DEFAULT_THREAD_NUM;
49 49
50CWelsThreadPool::CWelsThreadPool (IWelsThreadPoolSink* pSink) :50CWelsThreadPool::CWelsThreadPool() :
51 m_cWaitedTasks (NULL), m_cIdleThreads (NULL), m_cBusyThreads (NULL), m_pSink (pSink) {51 m_cWaitedTasks (NULL), m_cIdleThreads (NULL), m_cBusyThreads (NULL) {
52}52}
53 53
54 54
@@ -74,15 +74,15 @@ WELS_THREAD_ERROR_CODE CWelsThreadPool::SetThreadNum (int32_t iMaxThreadNum) { · 19 unmodified lines
74 return WELS_THREAD_ERROR_OK;74 return WELS_THREAD_ERROR_OK;
75}75}
76 76
77CWelsThreadPool& CWelsThreadPool::AddReference (IWelsThreadPoolSink* pSink) {77
78CWelsThreadPool& CWelsThreadPool::AddReference () {
78 CWelsAutoLock cLock (m_cInitLock);79 CWelsAutoLock cLock (m_cInitLock);
79 static CWelsThreadPool m_cThreadPoolSelf (pSink);80 static CWelsThreadPool m_cThreadPoolSelf;
80 if (m_iRefCount == 0) {81 if (m_iRefCount == 0) {
81 //TODO: will remove this afterwards82 //TODO: will remove this afterwards
82 if (WELS_THREAD_ERROR_OK != m_cThreadPoolSelf.Init(pSink)) {83 if (WELS_THREAD_ERROR_OK != m_cThreadPoolSelf.Init()) {
83 m_cThreadPoolSelf.Uninit();84 m_cThreadPoolSelf.Uninit();
84 }85 }
85 m_cThreadPoolSelf.UpdateSink (pSink);
86 }86 }
87 87
88 //fprintf(stdout, "m_iRefCount=%d, pSink=%x, iMaxThreadNum=%d\n", m_iRefCount, pSink, iMaxThreadNum);88 //fprintf(stdout, "m_iRefCount=%d, pSink=%x, iMaxThreadNum=%d\n", m_iRefCount, pSink, iMaxThreadNum);
@@ -98,23 +98,17 @@ void CWelsThreadPool::RemoveInstance() { · 9 unmodified lines
98 -- m_iRefCount;98 -- m_iRefCount;
99 if (0 == m_iRefCount) {99 if (0 == m_iRefCount) {
100 StopAllRunning();100 StopAllRunning();
101 m_pSink = NULL;
102 Uninit();101 Uninit();
103 //fprintf(stdout, "m_iRefCount=%d, IdleThreadNum=%d, BusyThreadNum=%d, WaitedTask=%d\n", m_iRefCount, GetIdleThreadNum(), GetBusyThreadNum(), GetWaitedTaskNum());102 //fprintf(stdout, "m_iRefCount=%d, IdleThreadNum=%d, BusyThreadNum=%d, WaitedTask=%d\n", m_iRefCount, GetIdleThreadNum(), GetBusyThreadNum(), GetWaitedTaskNum());
104 }103 }
105}104}
106 105
106
107bool CWelsThreadPool::IsReferenced() {107bool CWelsThreadPool::IsReferenced() {
108 CWelsAutoLock cLock (m_cInitLock);108 CWelsAutoLock cLock (m_cInitLock);
109 return (m_iRefCount>0);109 return (m_iRefCount>0);
110}110}
111 111
112void CWelsThreadPool::UpdateSink (IWelsThreadPoolSink* pSink) {
113 m_pSink = pSink;
114 //fprintf(stdout, "UpdateSink: m_pSink=%x\n", m_pSink);
115 //fprintf(stdout, "m_iRefCount=%d, IdleThreadNum=%d, BusyThreadNum=%d, WaitedTask=%d\n", m_iRefCount, GetIdleThreadNum(), GetBusyThreadNum(), GetWaitedTaskNum());
116}
117
118 112
119WELS_THREAD_ERROR_CODE CWelsThreadPool::OnTaskStart (CWelsTaskThread* pThread, IWelsTask* pTask) {113WELS_THREAD_ERROR_CODE CWelsThreadPool::OnTaskStart (CWelsTaskThread* pThread, IWelsTask* pTask) {
120 AddThreadToBusyList (pThread);114 AddThreadToBusyList (pThread);
@@ -143,7 +137,7 @@ WELS_THREAD_ERROR_CODE CWelsThreadPool::OnTaskStop (CWelsTaskThread* pThread, IW · 22 unmodified lines
143 return WELS_THREAD_ERROR_OK;137 return WELS_THREAD_ERROR_OK;
144}138}
145 139
146WELS_THREAD_ERROR_CODE CWelsThreadPool::Init (IWelsThreadPoolSink* pSink) {140WELS_THREAD_ERROR_CODE CWelsThreadPool::Init () {
147 //fprintf(stdout, "Enter WelsThreadPool Init\n");141 //fprintf(stdout, "Enter WelsThreadPool Init\n");
148 142
149 CWelsAutoLock cLock (m_cLockPool);143 CWelsAutoLock cLock (m_cLockPool);
@@ -341,12 +335,13 @@ IWelsTask* CWelsThreadPool::GetWaitedTask() { · 191 unmodified lines
341 335
342void CWelsThreadPool::ClearWaitedTasks() {336void CWelsThreadPool::ClearWaitedTasks() {
343 CWelsAutoLock cLock (m_cLockWaitedTasks);337 CWelsAutoLock cLock (m_cLockWaitedTasks);
344 338 IWelsTask* pTask = NULL;
345 if (m_pSink) {339 while (0 != m_cWaitedTasks->size()) {
346 while (0 != m_cWaitedTasks->size()) {340 pTask = m_cWaitedTasks->begin();
347 m_pSink->OnTaskCancelled (m_cWaitedTasks->begin());341 if (pTask->GetSink()) {
348 m_cWaitedTasks->pop_front();342 pTask->GetSink()->OnTaskCancelled();
349 }343 }
344 m_cWaitedTasks->pop_front();
350 }345 }
351}346}
352 347

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