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
4747 CWelsLock CWelsThreadPool::m_cInitLock;
4848 int32_t CWelsThreadPool::m_iMaxThreadNum = DEFAULT_THREAD_NUM;
4949
50−CWelsThreadPool::CWelsThreadPool (IWelsThreadPoolSink* pSink) :
51− m_cWaitedTasks (NULL), m_cIdleThreads (NULL), m_cBusyThreads (NULL), m_pSink (pSink) {
50+CWelsThreadPool::CWelsThreadPool() :
51+ m_cWaitedTasks (NULL), m_cIdleThreads (NULL), m_cBusyThreads (NULL) {
5252 }
5353
5454
@@ -74,15 +74,15 @@ WELS_THREAD_ERROR_CODE CWelsThreadPool::SetThreadNum (int32_t iMaxThreadNum) { · 19 unmodified lines
7474 return WELS_THREAD_ERROR_OK;
7575 }
7676
77−CWelsThreadPool& CWelsThreadPool::AddReference (IWelsThreadPoolSink* pSink) {
77+
78+CWelsThreadPool& CWelsThreadPool::AddReference () {
7879 CWelsAutoLock cLock (m_cInitLock);
79− static CWelsThreadPool m_cThreadPoolSelf (pSink);
80+ static CWelsThreadPool m_cThreadPoolSelf;
8081 if (m_iRefCount == 0) {
8182 //TODO: will remove this afterwards
82− if (WELS_THREAD_ERROR_OK != m_cThreadPoolSelf.Init(pSink)) {
83+ if (WELS_THREAD_ERROR_OK != m_cThreadPoolSelf.Init()) {
8384 m_cThreadPoolSelf.Uninit();
8485 }
85− m_cThreadPoolSelf.UpdateSink (pSink);
8686 }
8787
8888 //fprintf(stdout, "m_iRefCount=%d, pSink=%x, iMaxThreadNum=%d\n", m_iRefCount, pSink, iMaxThreadNum);
@@ -98,23 +98,17 @@ void CWelsThreadPool::RemoveInstance() { · 9 unmodified lines
9898 -- m_iRefCount;
9999 if (0 == m_iRefCount) {
100100 StopAllRunning();
101− m_pSink = NULL;
102101 Uninit();
103102 //fprintf(stdout, "m_iRefCount=%d, IdleThreadNum=%d, BusyThreadNum=%d, WaitedTask=%d\n", m_iRefCount, GetIdleThreadNum(), GetBusyThreadNum(), GetWaitedTaskNum());
104103 }
105104 }
106105
106+
107107 bool CWelsThreadPool::IsReferenced() {
108108 CWelsAutoLock cLock (m_cInitLock);
109109 return (m_iRefCount>0);
110110 }
111111
112−void 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−
118112
119113 WELS_THREAD_ERROR_CODE CWelsThreadPool::OnTaskStart (CWelsTaskThread* pThread, IWelsTask* pTask) {
120114 AddThreadToBusyList (pThread);
@@ -143,7 +137,7 @@ WELS_THREAD_ERROR_CODE CWelsThreadPool::OnTaskStop (CWelsTaskThread* pThread, IW · 22 unmodified lines
143137 return WELS_THREAD_ERROR_OK;
144138 }
145139
146−WELS_THREAD_ERROR_CODE CWelsThreadPool::Init (IWelsThreadPoolSink* pSink) {
140+WELS_THREAD_ERROR_CODE CWelsThreadPool::Init () {
147141 //fprintf(stdout, "Enter WelsThreadPool Init\n");
148142
149143 CWelsAutoLock cLock (m_cLockPool);
@@ -341,12 +335,13 @@ IWelsTask* CWelsThreadPool::GetWaitedTask() { · 191 unmodified lines
341335
342336 void CWelsThreadPool::ClearWaitedTasks() {
343337 CWelsAutoLock cLock (m_cLockWaitedTasks);
344−
345− if (m_pSink) {
346− while (0 != m_cWaitedTasks->size()) {
347− m_pSink->OnTaskCancelled (m_cWaitedTasks->begin());
348− m_cWaitedTasks->pop_front();
338+ IWelsTask* pTask = NULL;
339+ while (0 != m_cWaitedTasks->size()) {
340+ pTask = m_cWaitedTasks->begin();
341+ if (pTask->GetSink()) {
342+ pTask->GetSink()->OnTaskCancelled();
349343 }
344+ m_cWaitedTasks->pop_front();
350345 }
351346 }
352347

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