[libcalamares] Reimplement JobQueue::queueChanged
- switch to QStringList as parameter, since consumers (that is, the debug dialog, which is what this is for) are interested just in the **names** of the jobs. - to allow mutex locking in const methods, mark them mutable.
This commit is contained in:
parent
9afe7a3711
commit
b37a675657
@ -102,14 +102,8 @@ DebugWindow::DebugWindow()
|
|||||||
|
|
||||||
// JobQueue page
|
// JobQueue page
|
||||||
m_ui->jobQueueText->setReadOnly( true );
|
m_ui->jobQueueText->setReadOnly( true );
|
||||||
connect( JobQueue::instance(), &JobQueue::queueChanged, this, [this]( const JobList& jobs ) {
|
connect( JobQueue::instance(), &JobQueue::queueChanged, this, [this]( const QStringList& jobs ) {
|
||||||
QStringList text;
|
m_ui->jobQueueText->setText( jobs.join( '\n' ) );
|
||||||
for ( const auto& job : jobs )
|
|
||||||
{
|
|
||||||
text.append( job->prettyName() );
|
|
||||||
}
|
|
||||||
|
|
||||||
m_ui->jobQueueText->setText( text.join( '\n' ) );
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// Modules page
|
// Modules page
|
||||||
@ -193,7 +187,8 @@ DebugWindow::DebugWindow()
|
|||||||
#endif
|
#endif
|
||||||
] {
|
] {
|
||||||
QString moduleName = m_ui->modulesListView->currentIndex().data().toString();
|
QString moduleName = m_ui->modulesListView->currentIndex().data().toString();
|
||||||
Module* module = ModuleManager::instance()->moduleInstance( ModuleSystem::InstanceKey::fromString( moduleName ) );
|
Module* module
|
||||||
|
= ModuleManager::instance()->moduleInstance( ModuleSystem::InstanceKey::fromString( moduleName ) );
|
||||||
if ( module )
|
if ( module )
|
||||||
{
|
{
|
||||||
m_module = module->configurationMap();
|
m_module = module->configurationMap();
|
||||||
|
@ -151,6 +151,24 @@ public:
|
|||||||
QMetaObject::invokeMethod( m_queue, "finish", Qt::QueuedConnection );
|
QMetaObject::invokeMethod( m_queue, "finish", Qt::QueuedConnection );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @brief The names of the queued (not running!) jobs.
|
||||||
|
*/
|
||||||
|
QStringList queuedJobs() const
|
||||||
|
{
|
||||||
|
QMutexLocker qlock( &m_enqueMutex );
|
||||||
|
QStringList l;
|
||||||
|
l.reserve( m_queuedJobs->count() );
|
||||||
|
for ( const auto& j : *m_queuedJobs )
|
||||||
|
{
|
||||||
|
l << j.job->prettyName();
|
||||||
|
}
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
/* This is called **only** from run(), while m_runMutex is
|
||||||
|
* already locked, so we can use the m_runningJobs member safely.
|
||||||
|
*/
|
||||||
void emitProgress( qreal percentage ) const
|
void emitProgress( qreal percentage ) const
|
||||||
{
|
{
|
||||||
percentage = qBound( 0.0, percentage, 1.0 );
|
percentage = qBound( 0.0, percentage, 1.0 );
|
||||||
@ -172,10 +190,8 @@ public:
|
|||||||
m_queue, "progress", Qt::QueuedConnection, Q_ARG( qreal, progress ), Q_ARG( QString, message ) );
|
m_queue, "progress", Qt::QueuedConnection, Q_ARG( qreal, progress ), Q_ARG( QString, message ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mutable QMutex m_runMutex;
|
||||||
private:
|
mutable QMutex m_enqueMutex;
|
||||||
QMutex m_runMutex;
|
|
||||||
QMutex m_enqueMutex;
|
|
||||||
|
|
||||||
std::unique_ptr< WeightedJobList > m_runningJobs = std::make_unique< WeightedJobList >();
|
std::unique_ptr< WeightedJobList > m_runningJobs = std::make_unique< WeightedJobList >();
|
||||||
std::unique_ptr< WeightedJobList > m_queuedJobs = std::make_unique< WeightedJobList >();
|
std::unique_ptr< WeightedJobList > m_queuedJobs = std::make_unique< WeightedJobList >();
|
||||||
@ -242,6 +258,7 @@ JobQueue::enqueue( int moduleWeight, const JobList& jobs )
|
|||||||
{
|
{
|
||||||
Q_ASSERT( !m_thread->isRunning() );
|
Q_ASSERT( !m_thread->isRunning() );
|
||||||
m_thread->enqueue( moduleWeight, jobs );
|
m_thread->enqueue( moduleWeight, jobs );
|
||||||
|
emit queueChanged( m_thread->queuedJobs() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -249,6 +266,7 @@ JobQueue::finish()
|
|||||||
{
|
{
|
||||||
m_finished = true;
|
m_finished = true;
|
||||||
emit finished();
|
emit finished();
|
||||||
|
emit queueChanged( m_thread->queuedJobs() );
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalStorage*
|
GlobalStorage*
|
||||||
|
@ -82,6 +82,14 @@ signals:
|
|||||||
*/
|
*/
|
||||||
void failed( const QString& message, const QString& details );
|
void failed( const QString& message, const QString& details );
|
||||||
|
|
||||||
|
/** @brief Reports the names of jobs in the queue.
|
||||||
|
*
|
||||||
|
* When jobs are added via enqueue(), or when the queue otherwise
|
||||||
|
* changes, the **names** of the jobs are reported. This is
|
||||||
|
* primarily for debugging purposes.
|
||||||
|
*/
|
||||||
|
void queueChanged( const QStringList& jobNames );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void finish();
|
void finish();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user