Commit 65ac3688 authored by Thomas Zander's avatar Thomas Zander

Ok, I think this is how Qt lets me do a thread-save a wait().

A bit complex; and probably good to have in the API docs.

svn path=/trunk/koffice/; revision=689810
parent 62799911
......@@ -57,8 +57,10 @@ void ActionJob::run() {
m_action->doActionUi(m_params);
else {
// do it in the main thread.
m_mutex.lock();
QCoreApplication::postEvent(this, new ActionJobEvent());
m_semaphore.acquire();
m_waiter.wait(&m_mutex);
m_mutex.unlock();
}
}
......@@ -66,7 +68,9 @@ bool ActionJob::event(QEvent *e) {
ActionJobEvent *event = dynamic_cast<ActionJobEvent*> (e);
if(event) {
m_action->doActionUi(m_params);
m_semaphore.release();
m_mutex.lock(); // wait for the above to start waiting on us.
m_waiter.wakeAll();
m_mutex.unlock();
return true;
}
return QObject::event(e);
......
......@@ -21,7 +21,8 @@
#define TW_ACTIONJOB_H
#include <threadweaver/Job.h>
#include <QSemaphore>
#include <QWaitCondition>
#include <QMutex>
#include <QVariant>
class QEvent;
......@@ -52,7 +53,8 @@ private:
Enable m_enable;
bool m_started;
QVariant m_params;
QSemaphore m_semaphore;
QWaitCondition m_waiter;
QMutex m_mutex;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment