diff options
author | Arnaud Versini <arnaud.versini@libreoffice.org> | 2021-03-13 18:10:46 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2021-04-06 10:22:34 +0200 |
commit | 550a47f117cc35dbffbb6caef6db52acdd0c1453 (patch) | |
tree | e3f6b89cb5f93a8c1689e95a1970473870fa4159 /cppu | |
parent | ce135ba8a693fc0d4c749b7409bf9deb8ae8e59e (diff) |
cppu : use std::mutex in threadpool
Change-Id: I559a2c533accfe95740c29d726833d0bbab210fa
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112460
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'cppu')
-rw-r--r-- | cppu/source/threadpool/thread.cxx | 15 | ||||
-rw-r--r-- | cppu/source/threadpool/threadpool.cxx | 18 | ||||
-rw-r--r-- | cppu/source/threadpool/threadpool.hxx | 9 |
3 files changed, 21 insertions, 21 deletions
diff --git a/cppu/source/threadpool/thread.cxx b/cppu/source/threadpool/thread.cxx index 794d8f35e7ec..c0c3bc9ae61d 100644 --- a/cppu/source/threadpool/thread.cxx +++ b/cppu/source/threadpool/thread.cxx @@ -42,9 +42,8 @@ namespace cppu_threadpool { SAL_WARN_IF(m_deque.size(), "cppu.threadpool", m_deque.size() << "Threads left"); } - bool ThreadAdmin::add( rtl::Reference< ORequestThread > const & p ) + bool ThreadAdmin::add_locked( rtl::Reference< ORequestThread > const & p ) { - MutexGuard aGuard( m_mutex ); if( m_disposed ) { return false; @@ -60,21 +59,21 @@ namespace cppu_threadpool { void ThreadAdmin::remove( rtl::Reference< ORequestThread > const & p ) { - MutexGuard aGuard( m_mutex ); + std::scoped_lock aGuard( m_mutex ); remove_locked( p ); } void ThreadAdmin::join() { { - MutexGuard aGuard( m_mutex ); + std::scoped_lock aGuard( m_mutex ); m_disposed = true; } for (;;) { rtl::Reference< ORequestThread > pCurrent; { - MutexGuard aGuard( m_mutex ); + std::scoped_lock aGuard( m_mutex ); if( m_deque.empty() ) { break; @@ -118,8 +117,8 @@ namespace cppu_threadpool { // return value iff it causes osl::Thread::run to start executing: acquire(); ThreadAdmin & rThreadAdmin = m_aThreadPool->getThreadAdmin(); - osl::ClearableMutexGuard g(rThreadAdmin.m_mutex); - if (!rThreadAdmin.add( this )) { + std::unique_lock g(rThreadAdmin.m_mutex); + if (!rThreadAdmin.add_locked( this )) { return false; } try { @@ -128,7 +127,7 @@ namespace cppu_threadpool { } } catch (...) { rThreadAdmin.remove_locked( this ); - g.clear(); + g.release(); release(); throw; } diff --git a/cppu/source/threadpool/threadpool.cxx b/cppu/source/threadpool/threadpool.cxx index c5783dc19989..257155027955 100644 --- a/cppu/source/threadpool/threadpool.cxx +++ b/cppu/source/threadpool/threadpool.cxx @@ -99,7 +99,7 @@ namespace cppu_threadpool { m_DisposedCallerAdmin->dispose( nDisposeId ); - MutexGuard guard( m_mutex ); + std::scoped_lock guard( m_mutex ); for (auto const& item : m_mapQueue) { if( item.second.first ) @@ -127,7 +127,7 @@ namespace cppu_threadpool { WaitingThread waitingThread(pThread); { - MutexGuard guard( m_mutexWaitingThreadList ); + std::scoped_lock guard( m_mutexWaitingThreadList ); m_dequeThreads.push_front( &waitingThread ); } @@ -135,7 +135,7 @@ namespace cppu_threadpool waitingThread.condition.wait( std::chrono::seconds(2) ); { - MutexGuard guard ( m_mutexWaitingThreadList ); + std::scoped_lock guard ( m_mutexWaitingThreadList ); if( waitingThread.thread.is() ) { // thread wasn't reused, remove it from the list @@ -150,7 +150,7 @@ namespace cppu_threadpool void ThreadPool::joinWorkers() { { - MutexGuard guard( m_mutexWaitingThreadList ); + std::scoped_lock guard( m_mutexWaitingThreadList ); for (auto const& thread : m_dequeThreads) { // wake the threads up @@ -166,7 +166,7 @@ namespace cppu_threadpool { { // Can a thread be reused ? - MutexGuard guard( m_mutexWaitingThreadList ); + std::scoped_lock guard( m_mutexWaitingThreadList ); if( ! m_dequeThreads.empty() ) { // inform the thread and let it go @@ -190,7 +190,7 @@ namespace cppu_threadpool bool ThreadPool::revokeQueue( const ByteSequence &aThreadId, bool bAsynchron ) { - MutexGuard guard( m_mutex ); + std::scoped_lock guard( m_mutex ); ThreadIdHashMap::iterator ii = m_mapQueue.find( aThreadId ); OSL_ASSERT( ii != m_mapQueue.end() ); @@ -240,7 +240,7 @@ namespace cppu_threadpool bool bCreateThread = false; JobQueue *pQueue = nullptr; { - MutexGuard guard( m_mutex ); + std::scoped_lock guard( m_mutex ); if (m_DisposedCallerAdmin->isDisposed(disposeId)) { return true; } @@ -285,7 +285,7 @@ namespace cppu_threadpool void ThreadPool::prepare( const ByteSequence &aThreadId ) { - MutexGuard guard( m_mutex ); + std::scoped_lock guard( m_mutex ); ThreadIdHashMap::iterator ii = m_mapQueue.find( aThreadId ); @@ -304,7 +304,7 @@ namespace cppu_threadpool { JobQueue *pQueue = nullptr; { - MutexGuard guard( m_mutex ); + std::scoped_lock guard( m_mutex ); ThreadIdHashMap::iterator ii = m_mapQueue.find( aThreadId ); diff --git a/cppu/source/threadpool/threadpool.hxx b/cppu/source/threadpool/threadpool.hxx index e112f05805d0..5b758703579a 100644 --- a/cppu/source/threadpool/threadpool.hxx +++ b/cppu/source/threadpool/threadpool.hxx @@ -19,6 +19,7 @@ #pragma once +#include <mutex> #include <vector> #include <unordered_map> @@ -98,12 +99,12 @@ namespace cppu_threadpool { ThreadAdmin(); ~ThreadAdmin (); - bool add( rtl::Reference< ORequestThread > const & ); void remove( rtl::Reference< ORequestThread > const & ); void join(); + bool add_locked( rtl::Reference< ORequestThread > const & ); void remove_locked( rtl::Reference< ORequestThread > const & ); - ::osl::Mutex m_mutex; + std::mutex m_mutex; private: std::deque< rtl::Reference< ORequestThread > > m_deque; @@ -147,9 +148,9 @@ namespace cppu_threadpool { ThreadIdHashMap m_mapQueue; - ::osl::Mutex m_mutex; + std::mutex m_mutex; - ::osl::Mutex m_mutexWaitingThreadList; + std::mutex m_mutexWaitingThreadList; WaitingThreadDeque m_dequeThreads; DisposedCallerAdminHolder m_DisposedCallerAdmin; |