History

put m_cIdleThreads to CWelsCircleQueue rather than std::map https://rbcommons.com/s/OpenH264/r/1313/

Sijia Chen committed 11 years ago

Commit bc566f01 parent eb00d5c6 files · +183 −43Browse files

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

Unified · Split

codec/common/src/WelsThreadPool.cpp+15−25
@@ -51,6 +51,7 @@ namespace WelsCommon { · 50 unmodified lines
5151 CWelsThreadPool::CWelsThreadPool (IWelsThreadPoolSink* pSink, int32_t iMaxThreadNum) :
5252 m_pSink (pSink) {
5353 m_cWaitedTasks = new CWelsCircleQueue<IWelsTask>();
54+ m_cIdleThreads = new CWelsCircleQueue<CWelsTaskThread>();
5455 m_iMaxThreadNum = 0;
5556
5657 Init (iMaxThreadNum);
@@ -61,6 +62,7 @@ CWelsThreadPool::~CWelsThreadPool() { · 4 unmodified lines
6162 Uninit();
6263
6364 delete m_cWaitedTasks;
65+ delete m_cIdleThreads;
6466 }
6567
6668 WELS_THREAD_ERROR_CODE CWelsThreadPool::OnTaskStart (CWelsTaskThread* pThread, IWelsTask* pTask) {
@@ -71,7 +73,7 @@ WELS_THREAD_ERROR_CODE CWelsThreadPool::OnTaskStart (CWelsTaskThread* pThread, I · 4 unmodified lines
7173
7274 WELS_THREAD_ERROR_CODE CWelsThreadPool::OnTaskStop (CWelsTaskThread* pThread, IWelsTask* pTask) {
7375 RemoveThreadFromBusyMap (pThread);
74− AddThreadToIdleMap (pThread);
76+ AddThreadToIdleQueue (pThread);
7577
7678 if (m_pSink) {
7779 m_pSink->OnTaskExecuted (pTask);
@@ -121,10 +123,9 @@ WELS_THREAD_ERROR_CODE CWelsThreadPool::Uninit() { · 43 unmodified lines
121123 }
122124
123125 m_cLockIdleTasks.Lock();
124− std::map<uintptr_t, CWelsTaskThread*>::iterator iter = m_cIdleThreads.begin();
125− while (iter != m_cIdleThreads.end()) {
126− DestroyThread (iter->second);
127− ++ iter;
126+ while (m_cIdleThreads->size() > 0) {
127+ DestroyThread (m_cIdleThreads->begin());
128+ m_cIdleThreads->pop_front();
128129 }
129130 m_cLockIdleTasks.Unlock();
130131
@@ -179,7 +180,7 @@ WELS_THREAD_ERROR_CODE CWelsThreadPool::CreateIdleThread() { · 48 unmodified lines
179180 }
180181
181182 pThread->Start();
182− AddThreadToIdleMap (pThread);
183+ AddThreadToIdleQueue (pThread);
183184
184185 return WELS_THREAD_ERROR_OK;
185186 }
@@ -191,19 +192,9 @@ void CWelsThreadPool::DestroyThread (CWelsTaskThread* pThread) { · 5 unmodified lines
191192 return;
192193 }
193194
194−WELS_THREAD_ERROR_CODE CWelsThreadPool::AddThreadToIdleMap (CWelsTaskThread* pThread) {
195+WELS_THREAD_ERROR_CODE CWelsThreadPool::AddThreadToIdleQueue (CWelsTaskThread* pThread) {
195196 CWelsAutoLock cLock (m_cLockIdleTasks);
196−
197− uintptr_t id = pThread->GetID();
198−
199− std::map<uintptr_t, CWelsTaskThread*>::iterator iter = m_cIdleThreads.find (id);
200−
201− if (iter != m_cIdleThreads.end()) {
202− return WELS_THREAD_ERROR_GENERAL;
203− }
204−
205− m_cIdleThreads[id] = pThread;
206−
197+ m_cIdleThreads->push_back (pThread);
207198 return WELS_THREAD_ERROR_OK;
208199 }
209200
@@ -249,15 +240,12 @@ void CWelsThreadPool::AddTaskToWaitedList (IWelsTask* pTask) { · 39 unmodified lines
249240 CWelsTaskThread* CWelsThreadPool::GetIdleThread() {
250241 CWelsAutoLock cLock (m_cLockIdleTasks);
251242
252− if (m_cIdleThreads.size() == 0) {
243+ if (m_cIdleThreads->size() == 0) {
253244 return NULL;
254245 }
255246
256− std::map<uintptr_t, CWelsTaskThread*>::iterator it = m_cIdleThreads.begin();
257− CWelsTaskThread* pThread = it->second;
258−
259− m_cIdleThreads.erase (it);
260−
247+ CWelsTaskThread* pThread = m_cIdleThreads->begin();
248+ m_cIdleThreads->pop_front();
261249 return pThread;
262250 }
263251
@@ -266,7 +254,7 @@ int32_t CWelsThreadPool::GetBusyThreadNum() { · 2 unmodified lines
266254 }
267255
268256 int32_t CWelsThreadPool::GetIdleThreadNum() {
269− return static_cast<int32_t> (m_cIdleThreads.size());
257+ return static_cast<int32_t> (m_cIdleThreads->size());
270258 }
271259
272260 int32_t CWelsThreadPool::GetWaitedTaskNum() {
@@ -275,6 +263,7 @@ int32_t CWelsThreadPool::GetWaitedTaskNum() { · 2 unmodified lines
275263
276264 IWelsTask* CWelsThreadPool::GetWaitedTask() {
277265 CWelsAutoLock lock (m_cLockWaitedTasks);
266+
278267 if (m_cWaitedTasks->size() == 0) {
279268 return NULL;
280269 }
@@ -288,6 +277,7 @@ IWelsTask* CWelsThreadPool::GetWaitedTask() { · 7 unmodified lines
288277
289278 void CWelsThreadPool::ClearWaitedTasks() {
290279 CWelsAutoLock cLock (m_cLockWaitedTasks);
280+
291281 if (m_pSink) {
292282 while (0 != m_cWaitedTasks->size()) {
293283 m_pSink->OnTaskCancelled (m_cWaitedTasks->begin());

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