Kaydet (Commit) 7db6878a authored tarafından Julien Nabet's avatar Julien Nabet Kaydeden (comit) Noel Grandin

Replace lists by vector or deque (cppu)

+ use for range loops

Change-Id: If0fcba6e06538913031c50ec878b18db3547e06c
Reviewed-on: https://gerrit.libreoffice.org/44894Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 9d1f61a6
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#ifndef INCLUDED_CPPU_SOURCE_THREADPOOL_JOBQUEUE_HXX #ifndef INCLUDED_CPPU_SOURCE_THREADPOOL_JOBQUEUE_HXX
#define INCLUDED_CPPU_SOURCE_THREADPOOL_JOBQUEUE_HXX #define INCLUDED_CPPU_SOURCE_THREADPOOL_JOBQUEUE_HXX
#include <list>
#include <deque> #include <deque>
#include <memory> #include <memory>
#include <sal/types.h> #include <sal/types.h>
...@@ -38,8 +37,6 @@ namespace cppu_threadpool ...@@ -38,8 +37,6 @@ namespace cppu_threadpool
RequestFun * doRequest; RequestFun * doRequest;
}; };
typedef std::list < struct Job > JobList;
class DisposedCallerAdmin; class DisposedCallerAdmin;
typedef std::shared_ptr<DisposedCallerAdmin> DisposedCallerAdminHolder; typedef std::shared_ptr<DisposedCallerAdmin> DisposedCallerAdminHolder;
...@@ -62,7 +59,7 @@ namespace cppu_threadpool ...@@ -62,7 +59,7 @@ namespace cppu_threadpool
private: private:
mutable ::osl::Mutex m_mutex; mutable ::osl::Mutex m_mutex;
JobList m_lstJob; std::deque < struct Job > m_lstJob;
std::deque<sal_Int64> m_lstCallstack; std::deque<sal_Int64> m_lstCallstack;
sal_Int32 m_nToDo; sal_Int32 m_nToDo;
bool m_bSuspended; bool m_bSuspended;
......
...@@ -39,7 +39,7 @@ namespace cppu_threadpool { ...@@ -39,7 +39,7 @@ namespace cppu_threadpool {
ThreadAdmin::~ThreadAdmin() ThreadAdmin::~ThreadAdmin()
{ {
SAL_WARN_IF(m_lst.size(), "cppu.threadpool", m_lst.size() << "Threads left"); SAL_WARN_IF(m_deque.size(), "cppu.threadpool", m_deque.size() << "Threads left");
} }
bool ThreadAdmin::add( rtl::Reference< ORequestThread > const & p ) bool ThreadAdmin::add( rtl::Reference< ORequestThread > const & p )
...@@ -49,17 +49,13 @@ namespace cppu_threadpool { ...@@ -49,17 +49,13 @@ namespace cppu_threadpool {
{ {
return false; return false;
} }
m_lst.push_back( p ); m_deque.push_back( p );
return true; return true;
} }
void ThreadAdmin::remove_locked( rtl::Reference< ORequestThread > const & p ) void ThreadAdmin::remove_locked( rtl::Reference< ORequestThread > const & p )
{ {
std::list< rtl::Reference< ORequestThread > >::iterator ii = std::find( m_lst.begin(), m_lst.end(), p ); m_deque.erase(std::find( m_deque.begin(), m_deque.end(), p ), m_deque.end());
if( ii != m_lst.end() )
{
m_lst.erase( ii );
}
} }
void ThreadAdmin::remove( rtl::Reference< ORequestThread > const & p ) void ThreadAdmin::remove( rtl::Reference< ORequestThread > const & p )
...@@ -79,12 +75,12 @@ namespace cppu_threadpool { ...@@ -79,12 +75,12 @@ namespace cppu_threadpool {
rtl::Reference< ORequestThread > pCurrent; rtl::Reference< ORequestThread > pCurrent;
{ {
MutexGuard aGuard( m_mutex ); MutexGuard aGuard( m_mutex );
if( m_lst.empty() ) if( m_deque.empty() )
{ {
break; break;
} }
pCurrent = m_lst.front(); pCurrent = m_deque.front();
m_lst.pop_front(); m_deque.pop_front();
} }
if (pCurrent->getIdentifier() if (pCurrent->getIdentifier()
!= osl::Thread::getCurrentIdentifier()) != osl::Thread::getCurrentIdentifier())
......
...@@ -60,43 +60,25 @@ namespace cppu_threadpool ...@@ -60,43 +60,25 @@ namespace cppu_threadpool
DisposedCallerAdmin::~DisposedCallerAdmin() 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 ) void DisposedCallerAdmin::dispose( sal_Int64 nDisposeId )
{ {
MutexGuard guard( m_mutex ); MutexGuard guard( m_mutex );
m_lst.push_back( nDisposeId ); m_vector.push_back( nDisposeId );
} }
void DisposedCallerAdmin::destroy( sal_Int64 nDisposeId ) void DisposedCallerAdmin::destroy( sal_Int64 nDisposeId )
{ {
MutexGuard guard( m_mutex ); MutexGuard guard( m_mutex );
for( auto it = m_lst.begin() ; m_vector.erase(std::remove(m_vector.begin(), m_vector.end(), nDisposeId), m_vector.end());
it != m_lst.end() ;
++ it )
{
if( (*it) == nDisposeId )
{
m_lst.erase( it );
break;
}
}
} }
bool DisposedCallerAdmin::isDisposed( sal_Int64 nDisposeId ) bool DisposedCallerAdmin::isDisposed( sal_Int64 nDisposeId )
{ {
MutexGuard guard( m_mutex ); MutexGuard guard( m_mutex );
for( auto it = m_lst.begin() ; return (std::find(m_vector.begin(), m_vector.end(), nDisposeId) != m_vector.end());
it != m_lst.end() ;
++ it )
{
if( (*it) == nDisposeId )
{
return true;
}
}
return false;
} }
...@@ -115,17 +97,15 @@ namespace cppu_threadpool ...@@ -115,17 +97,15 @@ namespace cppu_threadpool
m_DisposedCallerAdmin->dispose( nDisposeId ); m_DisposedCallerAdmin->dispose( nDisposeId );
MutexGuard guard( m_mutex ); MutexGuard guard( m_mutex );
for( ThreadIdHashMap::iterator ii = m_mapQueue.begin() ; for (auto const& item : m_mapQueue)
ii != m_mapQueue.end();
++ii)
{ {
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 ...@@ -145,7 +125,7 @@ namespace cppu_threadpool
WaitingThread waitingThread(pThread); WaitingThread waitingThread(pThread);
{ {
MutexGuard guard( m_mutexWaitingThreadList ); MutexGuard guard( m_mutexWaitingThreadList );
m_lstThreads.push_front( &waitingThread ); m_dequeThreads.push_front( &waitingThread );
} }
// let the thread wait 2 seconds // let the thread wait 2 seconds
...@@ -156,10 +136,10 @@ namespace cppu_threadpool ...@@ -156,10 +136,10 @@ namespace cppu_threadpool
if( waitingThread.thread.is() ) if( waitingThread.thread.is() )
{ {
// thread wasn't reused, remove it from the list // thread wasn't reused, remove it from the list
WaitingThreadList::iterator ii = find( WaitingThreadDeque::iterator ii = find(
m_lstThreads.begin(), m_lstThreads.end(), &waitingThread ); m_dequeThreads.begin(), m_dequeThreads.end(), &waitingThread );
OSL_ASSERT( ii != m_lstThreads.end() ); OSL_ASSERT( ii != m_dequeThreads.end() );
m_lstThreads.erase( ii ); m_dequeThreads.erase( ii );
} }
} }
} }
...@@ -168,12 +148,10 @@ namespace cppu_threadpool ...@@ -168,12 +148,10 @@ namespace cppu_threadpool
{ {
{ {
MutexGuard guard( m_mutexWaitingThreadList ); MutexGuard guard( m_mutexWaitingThreadList );
for( WaitingThreadList::iterator ii = m_lstThreads.begin() ; for (auto const& thread : m_dequeThreads)
ii != m_lstThreads.end() ;
++ ii )
{ {
// wake the threads up // wake the threads up
(*ii)->condition.set(); thread->condition.set();
} }
} }
m_aThreadAdmin.join(); m_aThreadAdmin.join();
...@@ -186,15 +164,15 @@ namespace cppu_threadpool ...@@ -186,15 +164,15 @@ namespace cppu_threadpool
{ {
// Can a thread be reused ? // Can a thread be reused ?
MutexGuard guard( m_mutexWaitingThreadList ); MutexGuard guard( m_mutexWaitingThreadList );
if( ! m_lstThreads.empty() ) if( ! m_dequeThreads.empty() )
{ {
// inform the thread and let it go // 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->setTask( pQueue , aThreadId , bAsynchron );
pWaitingThread->thread = nullptr; pWaitingThread->thread = nullptr;
// remove from list // remove from list
m_lstThreads.pop_back(); m_dequeThreads.pop_back();
// let the thread go // let the thread go
pWaitingThread->condition.set(); pWaitingThread->condition.set();
......
...@@ -72,7 +72,7 @@ namespace cppu_threadpool { ...@@ -72,7 +72,7 @@ namespace cppu_threadpool {
rtl::Reference<ORequestThread> const & theThread); rtl::Reference<ORequestThread> const & theThread);
}; };
typedef std::list < struct ::cppu_threadpool::WaitingThread * > WaitingThreadList; typedef std::deque< struct ::cppu_threadpool::WaitingThread * > WaitingThreadDeque;
class DisposedCallerAdmin; class DisposedCallerAdmin;
typedef std::shared_ptr<DisposedCallerAdmin> DisposedCallerAdminHolder; typedef std::shared_ptr<DisposedCallerAdmin> DisposedCallerAdminHolder;
...@@ -90,7 +90,7 @@ namespace cppu_threadpool { ...@@ -90,7 +90,7 @@ namespace cppu_threadpool {
private: private:
::osl::Mutex m_mutex; ::osl::Mutex m_mutex;
std::vector< sal_Int64 > m_lst; std::vector< sal_Int64 > m_vector;
}; };
class ThreadAdmin class ThreadAdmin
...@@ -107,7 +107,7 @@ namespace cppu_threadpool { ...@@ -107,7 +107,7 @@ namespace cppu_threadpool {
::osl::Mutex m_mutex; ::osl::Mutex m_mutex;
private: private:
std::list< rtl::Reference< ORequestThread > > m_lst; std::deque< rtl::Reference< ORequestThread > > m_deque;
bool m_disposed; bool m_disposed;
}; };
...@@ -150,7 +150,7 @@ namespace cppu_threadpool { ...@@ -150,7 +150,7 @@ namespace cppu_threadpool {
::osl::Mutex m_mutex; ::osl::Mutex m_mutex;
::osl::Mutex m_mutexWaitingThreadList; ::osl::Mutex m_mutexWaitingThreadList;
WaitingThreadList m_lstThreads; WaitingThreadDeque m_dequeThreads;
DisposedCallerAdminHolder m_DisposedCallerAdmin; DisposedCallerAdminHolder m_DisposedCallerAdmin;
ThreadAdmin m_aThreadAdmin; ThreadAdmin m_aThreadAdmin;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment