diff options
Diffstat (limited to 'cppu/source/threadpool/threadpool.cxx')
-rw-r--r-- | cppu/source/threadpool/threadpool.cxx | 60 |
1 files changed, 19 insertions, 41 deletions
diff --git a/cppu/source/threadpool/threadpool.cxx b/cppu/source/threadpool/threadpool.cxx index b54036d2cfd2..a3a3eab51d01 100644 --- a/cppu/source/threadpool/threadpool.cxx +++ b/cppu/source/threadpool/threadpool.cxx @@ -60,43 +60,25 @@ namespace cppu_threadpool DisposedCallerAdmin::~DisposedCallerAdmin() { - SAL_WARN_IF( !m_lst.empty(), "cppu.threadpool", "DisposedCallerList : " << m_lst.size() << " left"); + SAL_WARN_IF( !m_vector.empty(), "cppu.threadpool", "DisposedCallerList : " << m_vector.size() << " left"); } void DisposedCallerAdmin::dispose( sal_Int64 nDisposeId ) { MutexGuard guard( m_mutex ); - m_lst.push_back( nDisposeId ); + m_vector.push_back( nDisposeId ); } void DisposedCallerAdmin::destroy( sal_Int64 nDisposeId ) { MutexGuard guard( m_mutex ); - for( auto it = m_lst.begin() ; - it != m_lst.end() ; - ++ it ) - { - if( (*it) == nDisposeId ) - { - m_lst.erase( it ); - break; - } - } + m_vector.erase(std::remove(m_vector.begin(), m_vector.end(), nDisposeId), m_vector.end()); } bool DisposedCallerAdmin::isDisposed( sal_Int64 nDisposeId ) { MutexGuard guard( m_mutex ); - for( auto it = m_lst.begin() ; - it != m_lst.end() ; - ++ it ) - { - if( (*it) == nDisposeId ) - { - return true; - } - } - return false; + return (std::find(m_vector.begin(), m_vector.end(), nDisposeId) != m_vector.end()); } @@ -115,17 +97,15 @@ namespace cppu_threadpool m_DisposedCallerAdmin->dispose( nDisposeId ); MutexGuard guard( m_mutex ); - for( ThreadIdHashMap::iterator ii = m_mapQueue.begin() ; - ii != m_mapQueue.end(); - ++ii) + for (auto const& item : m_mapQueue) { - if( (*ii).second.first ) + if( item.second.first ) { - (*ii).second.first->dispose( nDisposeId ); + item.second.first->dispose( nDisposeId ); } - if( (*ii).second.second ) + if( item.second.second ) { - (*ii).second.second->dispose( nDisposeId ); + item.second.second->dispose( nDisposeId ); } } } @@ -145,7 +125,7 @@ namespace cppu_threadpool WaitingThread waitingThread(pThread); { MutexGuard guard( m_mutexWaitingThreadList ); - m_lstThreads.push_front( &waitingThread ); + m_dequeThreads.push_front( &waitingThread ); } // let the thread wait 2 seconds @@ -156,10 +136,10 @@ namespace cppu_threadpool if( waitingThread.thread.is() ) { // thread wasn't reused, remove it from the list - WaitingThreadList::iterator ii = find( - m_lstThreads.begin(), m_lstThreads.end(), &waitingThread ); - OSL_ASSERT( ii != m_lstThreads.end() ); - m_lstThreads.erase( ii ); + WaitingThreadDeque::iterator ii = find( + m_dequeThreads.begin(), m_dequeThreads.end(), &waitingThread ); + OSL_ASSERT( ii != m_dequeThreads.end() ); + m_dequeThreads.erase( ii ); } } } @@ -168,12 +148,10 @@ namespace cppu_threadpool { { MutexGuard guard( m_mutexWaitingThreadList ); - for( WaitingThreadList::iterator ii = m_lstThreads.begin() ; - ii != m_lstThreads.end() ; - ++ ii ) + for (auto const& thread : m_dequeThreads) { // wake the threads up - (*ii)->condition.set(); + thread->condition.set(); } } m_aThreadAdmin.join(); @@ -186,15 +164,15 @@ namespace cppu_threadpool { // Can a thread be reused ? MutexGuard guard( m_mutexWaitingThreadList ); - if( ! m_lstThreads.empty() ) + if( ! m_dequeThreads.empty() ) { // inform the thread and let it go - struct WaitingThread *pWaitingThread = m_lstThreads.back(); + struct WaitingThread *pWaitingThread = m_dequeThreads.back(); pWaitingThread->thread->setTask( pQueue , aThreadId , bAsynchron ); pWaitingThread->thread = nullptr; // remove from list - m_lstThreads.pop_back(); + m_dequeThreads.pop_back(); // let the thread go pWaitingThread->condition.set(); |