[Libreoffice-commits] core.git: cppu/source

Julien Nabet serval2412 at yahoo.fr
Sat Nov 18 06:50:44 UTC 2017


 cppu/source/threadpool/jobqueue.hxx   |    5 --
 cppu/source/threadpool/thread.cxx     |   16 +++------
 cppu/source/threadpool/threadpool.cxx |   60 ++++++++++------------------------
 cppu/source/threadpool/threadpool.hxx |    8 ++--
 4 files changed, 30 insertions(+), 59 deletions(-)

New commits:
commit 7db6878a9d3e534583f9c22709f0eee96eff849f
Author: Julien Nabet <serval2412 at yahoo.fr>
Date:   Fri Nov 17 20:19:56 2017 +0100

    Replace lists by vector or deque (cppu)
    
    + use for range loops
    
    Change-Id: If0fcba6e06538913031c50ec878b18db3547e06c
    Reviewed-on: https://gerrit.libreoffice.org/44894
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/cppu/source/threadpool/jobqueue.hxx b/cppu/source/threadpool/jobqueue.hxx
index d4a26c7709cc..9dc20f3cd75e 100644
--- a/cppu/source/threadpool/jobqueue.hxx
+++ b/cppu/source/threadpool/jobqueue.hxx
@@ -20,7 +20,6 @@
 #ifndef INCLUDED_CPPU_SOURCE_THREADPOOL_JOBQUEUE_HXX
 #define INCLUDED_CPPU_SOURCE_THREADPOOL_JOBQUEUE_HXX
 
-#include <list>
 #include <deque>
 #include <memory>
 #include <sal/types.h>
@@ -38,8 +37,6 @@ namespace cppu_threadpool
         RequestFun * doRequest;
     };
 
-    typedef std::list < struct Job > JobList;
-
     class DisposedCallerAdmin;
     typedef std::shared_ptr<DisposedCallerAdmin> DisposedCallerAdminHolder;
 
@@ -62,7 +59,7 @@ namespace cppu_threadpool
 
     private:
         mutable ::osl::Mutex m_mutex;
-        JobList      m_lstJob;
+        std::deque < struct Job > m_lstJob;
         std::deque<sal_Int64>  m_lstCallstack;
         sal_Int32 m_nToDo;
         bool m_bSuspended;
diff --git a/cppu/source/threadpool/thread.cxx b/cppu/source/threadpool/thread.cxx
index 8dfa93bd443f..ad37fa3072a8 100644
--- a/cppu/source/threadpool/thread.cxx
+++ b/cppu/source/threadpool/thread.cxx
@@ -39,7 +39,7 @@ namespace cppu_threadpool {
 
     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 )
@@ -49,17 +49,13 @@ namespace cppu_threadpool {
         {
             return false;
         }
-        m_lst.push_back( p );
+        m_deque.push_back( p );
         return true;
     }
 
     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 );
-        if( ii != m_lst.end() )
-        {
-            m_lst.erase( ii );
-        }
+        m_deque.erase(std::find( m_deque.begin(), m_deque.end(), p ), m_deque.end());
     }
 
     void ThreadAdmin::remove( rtl::Reference< ORequestThread > const & p )
@@ -79,12 +75,12 @@ namespace cppu_threadpool {
             rtl::Reference< ORequestThread > pCurrent;
             {
                 MutexGuard aGuard( m_mutex );
-                if( m_lst.empty() )
+                if( m_deque.empty() )
                 {
                     break;
                 }
-                pCurrent = m_lst.front();
-                m_lst.pop_front();
+                pCurrent = m_deque.front();
+                m_deque.pop_front();
             }
             if (pCurrent->getIdentifier()
                 != osl::Thread::getCurrentIdentifier())
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();
diff --git a/cppu/source/threadpool/threadpool.hxx b/cppu/source/threadpool/threadpool.hxx
index 037f14a5d581..9b4d8cf661d3 100644
--- a/cppu/source/threadpool/threadpool.hxx
+++ b/cppu/source/threadpool/threadpool.hxx
@@ -72,7 +72,7 @@ namespace cppu_threadpool {
             rtl::Reference<ORequestThread> const & theThread);
     };
 
-    typedef std::list < struct ::cppu_threadpool::WaitingThread * > WaitingThreadList;
+    typedef std::deque< struct ::cppu_threadpool::WaitingThread * > WaitingThreadDeque;
 
     class DisposedCallerAdmin;
     typedef std::shared_ptr<DisposedCallerAdmin> DisposedCallerAdminHolder;
@@ -90,7 +90,7 @@ namespace cppu_threadpool {
 
     private:
         ::osl::Mutex m_mutex;
-        std::vector< sal_Int64 > m_lst;
+        std::vector< sal_Int64 > m_vector;
     };
 
     class ThreadAdmin
@@ -107,7 +107,7 @@ namespace cppu_threadpool {
         ::osl::Mutex m_mutex;
 
     private:
-        std::list< rtl::Reference< ORequestThread > > m_lst;
+        std::deque< rtl::Reference< ORequestThread > > m_deque;
         bool m_disposed;
     };
 
@@ -150,7 +150,7 @@ namespace cppu_threadpool {
         ::osl::Mutex m_mutex;
 
         ::osl::Mutex m_mutexWaitingThreadList;
-        WaitingThreadList m_lstThreads;
+        WaitingThreadDeque m_dequeThreads;
 
         DisposedCallerAdminHolder m_DisposedCallerAdmin;
         ThreadAdmin m_aThreadAdmin;


More information about the Libreoffice-commits mailing list