delegate: add assert to check calling thread and improve requeuing.
This commit is contained in:
@@ -503,6 +503,7 @@ void Addon::openRepo()
|
|||||||
|
|
||||||
void Addon::delegate(QString taskname, auto work, auto callback)
|
void Addon::delegate(QString taskname, auto work, auto callback)
|
||||||
{
|
{
|
||||||
|
Q_ASSERT_X(QThread::currentThread() == thread(), "delegate", "Attempt to delegate from another thread.");
|
||||||
if (status() != Status::Ready) {
|
if (status() != Status::Ready) {
|
||||||
qInfo() << name() << "Enqueueing" << taskname;
|
qInfo() << name() << "Enqueueing" << taskname;
|
||||||
m_tasks.enqueue({taskname, [this, taskname, work, callback](){delegate(taskname, work,callback);}});
|
m_tasks.enqueue({taskname, [this, taskname, work, callback](){delegate(taskname, work,callback);}});
|
||||||
@@ -525,8 +526,7 @@ void Addon::delegate(QString taskname, auto work, auto callback)
|
|||||||
else
|
else
|
||||||
callback(fw->result());
|
callback(fw->result());
|
||||||
|
|
||||||
while(!old.isEmpty())
|
m_tasks.append(old);
|
||||||
m_tasks.enqueue(old.dequeue());
|
|
||||||
|
|
||||||
if (!m_tasks.isEmpty() && status() != Status::Busy)
|
if (!m_tasks.isEmpty() && status() != Status::Busy)
|
||||||
m_tasks.dequeue().second();
|
m_tasks.dequeue().second();
|
||||||
|
|||||||
+2
-2
@@ -39,6 +39,7 @@ Control::Control(QObject *parent) : QObject(parent), m_progress(0), m_total(0),
|
|||||||
|
|
||||||
void Control::delegate(QString taskname, auto work, auto callback)
|
void Control::delegate(QString taskname, auto work, auto callback)
|
||||||
{
|
{
|
||||||
|
Q_ASSERT_X(QThread::currentThread() == thread(), "delegate", "Attempt to delegate from another thread.");
|
||||||
if (status() != Status::Ready) {
|
if (status() != Status::Ready) {
|
||||||
qInfo() << "Enqueueing" << taskname;
|
qInfo() << "Enqueueing" << taskname;
|
||||||
m_tasks.enqueue({taskname, [this, taskname, work, callback](){delegate(taskname, work,callback);}});
|
m_tasks.enqueue({taskname, [this, taskname, work, callback](){delegate(taskname, work,callback);}});
|
||||||
@@ -62,8 +63,7 @@ void Control::delegate(QString taskname, auto work, auto callback)
|
|||||||
else
|
else
|
||||||
callback(fw->result());
|
callback(fw->result());
|
||||||
|
|
||||||
while(!old.isEmpty())
|
m_tasks.append(old);
|
||||||
m_tasks.enqueue(old.dequeue());
|
|
||||||
|
|
||||||
if (!m_tasks.isEmpty() && status() != Status::Busy)
|
if (!m_tasks.isEmpty() && status() != Status::Busy)
|
||||||
m_tasks.dequeue().second();
|
m_tasks.dequeue().second();
|
||||||
|
|||||||
Reference in New Issue
Block a user