Use the sander std::condition_variable semantics in ExtensionCmdQueue::Thread
This avoids the need for the tricky osl::Condition::reset call. Change-Id: Id441fe6be42409fa43624bc0c1cbc8a62462d3e9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133240 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
@@ -46,9 +46,7 @@
|
|||||||
#include <com/sun/star/uno/Sequence.hxx>
|
#include <com/sun/star/uno/Sequence.hxx>
|
||||||
#include <com/sun/star/uno/TypeClass.hpp>
|
#include <com/sun/star/uno/TypeClass.hpp>
|
||||||
#include <o3tl/any.hxx>
|
#include <o3tl/any.hxx>
|
||||||
#include <osl/conditn.hxx>
|
|
||||||
#include <osl/diagnose.h>
|
#include <osl/diagnose.h>
|
||||||
#include <osl/mutex.hxx>
|
|
||||||
#include <rtl/ref.hxx>
|
#include <rtl/ref.hxx>
|
||||||
#include <rtl/ustring.hxx>
|
#include <rtl/ustring.hxx>
|
||||||
#include <sal/types.h>
|
#include <sal/types.h>
|
||||||
@@ -73,8 +71,10 @@
|
|||||||
#include <dp_identifier.hxx>
|
#include <dp_identifier.hxx>
|
||||||
#include <dp_version.hxx>
|
#include <dp_version.hxx>
|
||||||
|
|
||||||
|
#include <condition_variable>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <o3tl/safeCoInitUninit.hxx>
|
#include <o3tl/safeCoInitUninit.hxx>
|
||||||
@@ -248,8 +248,8 @@ private:
|
|||||||
const OUString m_sRemovingPackages;
|
const OUString m_sRemovingPackages;
|
||||||
const OUString m_sDefaultCmd;
|
const OUString m_sDefaultCmd;
|
||||||
const OUString m_sAcceptLicense;
|
const OUString m_sAcceptLicense;
|
||||||
osl::Condition m_wakeup;
|
std::condition_variable m_wakeup;
|
||||||
osl::Mutex m_mutex;
|
std::mutex m_mutex;
|
||||||
Input m_eInput;
|
Input m_eInput;
|
||||||
bool m_bStopped;
|
bool m_bStopped;
|
||||||
bool m_bWorking;
|
bool m_bWorking;
|
||||||
@@ -655,16 +655,16 @@ void ExtensionCmdQueue::Thread::checkForUpdates(
|
|||||||
//Stopping this thread will not abort the installation of extensions.
|
//Stopping this thread will not abort the installation of extensions.
|
||||||
void ExtensionCmdQueue::Thread::stop()
|
void ExtensionCmdQueue::Thread::stop()
|
||||||
{
|
{
|
||||||
osl::MutexGuard aGuard( m_mutex );
|
std::scoped_lock aGuard( m_mutex );
|
||||||
m_bStopped = true;
|
m_bStopped = true;
|
||||||
m_eInput = STOP;
|
m_eInput = STOP;
|
||||||
m_wakeup.set();
|
m_wakeup.notify_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ExtensionCmdQueue::Thread::isBusy()
|
bool ExtensionCmdQueue::Thread::isBusy()
|
||||||
{
|
{
|
||||||
osl::MutexGuard aGuard( m_mutex );
|
std::scoped_lock aGuard( m_mutex );
|
||||||
return m_bWorking;
|
return m_bWorking;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -682,17 +682,13 @@ void ExtensionCmdQueue::Thread::execute()
|
|||||||
#endif
|
#endif
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
if ( m_wakeup.wait() != osl::Condition::result_ok )
|
|
||||||
{
|
|
||||||
dp_misc::TRACE( "dp_gui::ExtensionCmdQueue::Thread::run: ignored "
|
|
||||||
"osl::Condition::wait failure\n" );
|
|
||||||
}
|
|
||||||
m_wakeup.reset();
|
|
||||||
|
|
||||||
int nSize;
|
int nSize;
|
||||||
Input eInput;
|
Input eInput;
|
||||||
{
|
{
|
||||||
osl::MutexGuard aGuard( m_mutex );
|
std::unique_lock aGuard( m_mutex );
|
||||||
|
while (m_eInput == NONE) {
|
||||||
|
m_wakeup.wait(aGuard);
|
||||||
|
}
|
||||||
eInput = m_eInput;
|
eInput = m_eInput;
|
||||||
m_eInput = NONE;
|
m_eInput = NONE;
|
||||||
nSize = m_queue.size();
|
nSize = m_queue.size();
|
||||||
@@ -702,13 +698,11 @@ void ExtensionCmdQueue::Thread::execute()
|
|||||||
if ( eInput == STOP )
|
if ( eInput == STOP )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// If this thread has been woken up by anything else except start, stop
|
|
||||||
// then input is NONE and we wait again.
|
|
||||||
// We only install the extension which are currently in the queue.
|
// We only install the extension which are currently in the queue.
|
||||||
// The progressbar will be set to show the progress of the current number
|
// The progressbar will be set to show the progress of the current number
|
||||||
// of extensions. If we allowed to add extensions now then the progressbar may
|
// of extensions. If we allowed to add extensions now then the progressbar may
|
||||||
// have reached the end while we still install newly added extensions.
|
// have reached the end while we still install newly added extensions.
|
||||||
if ( ( eInput == NONE ) || ( nSize == 0 ) )
|
if ( nSize == 0 )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
::rtl::Reference< ProgressCmdEnv > currentCmdEnv( new ProgressCmdEnv( m_xContext, m_pDialogHelper, m_sDefaultCmd ) );
|
::rtl::Reference< ProgressCmdEnv > currentCmdEnv( new ProgressCmdEnv( m_xContext, m_pDialogHelper, m_sDefaultCmd ) );
|
||||||
@@ -721,7 +715,7 @@ void ExtensionCmdQueue::Thread::execute()
|
|||||||
while ( --nSize >= 0 )
|
while ( --nSize >= 0 )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
osl::MutexGuard aGuard( m_mutex );
|
std::scoped_lock aGuard( m_mutex );
|
||||||
m_bWorking = true;
|
m_bWorking = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -729,7 +723,7 @@ void ExtensionCmdQueue::Thread::execute()
|
|||||||
{
|
{
|
||||||
TExtensionCmd pEntry;
|
TExtensionCmd pEntry;
|
||||||
{
|
{
|
||||||
::osl::MutexGuard queueGuard( m_mutex );
|
std::scoped_lock queueGuard( m_mutex );
|
||||||
pEntry = m_queue.front();
|
pEntry = m_queue.front();
|
||||||
m_queue.pop();
|
m_queue.pop();
|
||||||
}
|
}
|
||||||
@@ -767,7 +761,7 @@ void ExtensionCmdQueue::Thread::execute()
|
|||||||
//Then we cancel the installation of all extensions and remove them from
|
//Then we cancel the installation of all extensions and remove them from
|
||||||
//the queue.
|
//the queue.
|
||||||
{
|
{
|
||||||
::osl::MutexGuard queueGuard2(m_mutex);
|
std::scoped_lock queueGuard2(m_mutex);
|
||||||
while ( --nSize >= 0 )
|
while ( --nSize >= 0 )
|
||||||
m_queue.pop();
|
m_queue.pop();
|
||||||
}
|
}
|
||||||
@@ -814,14 +808,14 @@ void ExtensionCmdQueue::Thread::execute()
|
|||||||
//Continue with installation of the remaining extensions
|
//Continue with installation of the remaining extensions
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
osl::MutexGuard aGuard( m_mutex );
|
std::scoped_lock aGuard( m_mutex );
|
||||||
m_bWorking = false;
|
m_bWorking = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
// when leaving the while loop with break, we should set working to false, too
|
// when leaving the while loop with break, we should set working to false, too
|
||||||
osl::MutexGuard aGuard( m_mutex );
|
std::scoped_lock aGuard( m_mutex );
|
||||||
m_bWorking = false;
|
m_bWorking = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1044,7 +1038,7 @@ void ExtensionCmdQueue::Thread::_acceptLicense( ::rtl::Reference< ProgressCmdEnv
|
|||||||
|
|
||||||
void ExtensionCmdQueue::Thread::_insert(const TExtensionCmd& rExtCmd)
|
void ExtensionCmdQueue::Thread::_insert(const TExtensionCmd& rExtCmd)
|
||||||
{
|
{
|
||||||
::osl::MutexGuard aGuard( m_mutex );
|
std::scoped_lock aGuard( m_mutex );
|
||||||
|
|
||||||
// If someone called stop then we do not process the command -> game over!
|
// If someone called stop then we do not process the command -> game over!
|
||||||
if ( m_bStopped )
|
if ( m_bStopped )
|
||||||
@@ -1052,7 +1046,7 @@ void ExtensionCmdQueue::Thread::_insert(const TExtensionCmd& rExtCmd)
|
|||||||
|
|
||||||
m_queue.push( rExtCmd );
|
m_queue.push( rExtCmd );
|
||||||
m_eInput = START;
|
m_eInput = START;
|
||||||
m_wakeup.set();
|
m_wakeup.notify_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user