History

replacement of std::list for m_cBusyThreads https://rbcommons.com/s/OpenH264/r/1320/

Sijia Chen committed 11 years ago

Commit a3f606e1 parent bc566f07 files · +475 −33Browse files

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

Unified · Split

codec/common/src/WelsThreadPool.cpp+11−26
@@ -52,6 +52,7 @@ CWelsThreadPool::CWelsThreadPool (IWelsThreadPoolSink* pSink, int32_t iMaxThread · 51 unmodified lines
5252 m_pSink (pSink) {
5353 m_cWaitedTasks = new CWelsCircleQueue<IWelsTask>();
5454 m_cIdleThreads = new CWelsCircleQueue<CWelsTaskThread>();
55+ m_cBusyThreads = new CWelsList<CWelsTaskThread>();
5556 m_iMaxThreadNum = 0;
5657
5758 Init (iMaxThreadNum);
@@ -63,16 +64,17 @@ CWelsThreadPool::~CWelsThreadPool() { · 5 unmodified lines
6364
6465 delete m_cWaitedTasks;
6566 delete m_cIdleThreads;
67+ delete m_cBusyThreads;
6668 }
6769
6870 WELS_THREAD_ERROR_CODE CWelsThreadPool::OnTaskStart (CWelsTaskThread* pThread, IWelsTask* pTask) {
69− AddThreadToBusyMap (pThread);
71+ AddThreadToBusyList (pThread);
7072
7173 return WELS_THREAD_ERROR_OK;
7274 }
7375
7476 WELS_THREAD_ERROR_CODE CWelsThreadPool::OnTaskStop (CWelsTaskThread* pThread, IWelsTask* pTask) {
75− RemoveThreadFromBusyMap (pThread);
77+ RemoveThreadFromBusyList (pThread);
7678 AddThreadToIdleQueue (pThread);
7779
7880 if (m_pSink) {
@@ -198,36 +200,19 @@ WELS_THREAD_ERROR_CODE CWelsThreadPool::AddThreadToIdleQueue (CWelsTaskThread* p · 119 unmodified lines
198200 return WELS_THREAD_ERROR_OK;
199201 }
200202
201−WELS_THREAD_ERROR_CODE CWelsThreadPool::AddThreadToBusyMap (CWelsTaskThread* pThread) {
203+WELS_THREAD_ERROR_CODE CWelsThreadPool::AddThreadToBusyList (CWelsTaskThread* pThread) {
202204 CWelsAutoLock cLock (m_cLockBusyTasks);
203−
204− uintptr_t id = pThread->GetID();
205−
206− std::map<uintptr_t, CWelsTaskThread*>::iterator iter = m_cBusyThreads.find (id);
207−
208− if (iter != m_cBusyThreads.end()) {
209− return WELS_THREAD_ERROR_GENERAL;
210− }
211−
212− m_cBusyThreads[id] = pThread;
213−
205+ m_cBusyThreads->push_back (pThread);
214206 return WELS_THREAD_ERROR_OK;
215207 }
216208
217−WELS_THREAD_ERROR_CODE CWelsThreadPool::RemoveThreadFromBusyMap (CWelsTaskThread* pThread) {
209+WELS_THREAD_ERROR_CODE CWelsThreadPool::RemoveThreadFromBusyList (CWelsTaskThread* pThread) {
218210 CWelsAutoLock cLock (m_cLockBusyTasks);
219−
220− uintptr_t id = pThread->GetID();
221−
222− std::map<uintptr_t, CWelsTaskThread*>::iterator iter = m_cBusyThreads.find (id);
223−
224− if (iter != m_cBusyThreads.end()) {
225− m_cBusyThreads.erase (iter);
211+ if (m_cBusyThreads->erase(pThread)) {
212+ return WELS_THREAD_ERROR_OK;
226213 } else {
227− return WELS_THREAD_ERROR_GENERAL;
214+ return WELS_THREAD_ERROR_GENERAL;
228215 }
229−
230− return WELS_THREAD_ERROR_OK;
231216 }
232217
233218 void CWelsThreadPool::AddTaskToWaitedList (IWelsTask* pTask) {
@@ -250,7 +235,7 @@ CWelsTaskThread* CWelsThreadPool::GetIdleThread() { · 16 unmodified lines
250235 }
251236
252237 int32_t CWelsThreadPool::GetBusyThreadNum() {
253− return static_cast<int32_t> (m_cBusyThreads.size());
238+ return static_cast<int32_t> (m_cBusyThreads->size());
254239 }
255240
256241 int32_t CWelsThreadPool::GetIdleThreadNum() {

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