deadlock issues, part 1

metadata
Wenzel Jakob 2011-10-20 15:22:29 -04:00
parent 7ec713347f
commit 04c0351d8a
2 changed files with 31 additions and 5 deletions

View File

@ -163,8 +163,8 @@ MainWindow::MainWindow(QWidget *parent) :
connect(m_renderListener, SIGNAL(jobFinished(const RenderJob *, bool)),
this, SLOT(onJobFinished(const RenderJob *, bool)), Qt::QueuedConnection);
connect(m_renderListener, SIGNAL(refresh(const RenderJob *, const Bitmap *)),
this, SLOT(onRefresh(const RenderJob *, const Bitmap *)), Qt::BlockingQueuedConnection);
connect(m_renderListener, SIGNAL(refresh(const RenderJob *)),
this, SLOT(onRefresh(const RenderJob *)), Qt::QueuedConnection);
connect(m_renderListener, SIGNAL(workEnd(const RenderJob *, const ImageBlock *)),
this, SLOT(onWorkEnd(const RenderJob *, const ImageBlock *)), Qt::DirectConnection);
connect(m_renderListener, SIGNAL(workBegin(const RenderJob *, const RectangularWorkUnit *, int)),
@ -1673,10 +1673,11 @@ void MainWindow::onWorkEnd(const RenderJob *job, const ImageBlock *block) {
emit updateView();
}
void MainWindow::onRefresh(const RenderJob *job, const Bitmap *_bitmap) {
void MainWindow::onRefresh(const RenderJob *job) {
SceneContext *context = getContext(job, false);
if (context == NULL)
return;
Film *film = context->scene->getFilm();
Point2i co = film->getCropOffset();
Bitmap *bitmap = context->framebuffer;

View File

@ -41,6 +41,11 @@ class PreviewSettingsDlg;
class QRenderListener : public QObject, public RenderListener {
Q_OBJECT
public:
QRenderListener() {
m_mutex = new Mutex();
m_cond = new ConditionVariable(m_mutex);
}
/// Called when work has begun in a rectangular image region
inline void workBeginEvent(const RenderJob *job, const RectangularWorkUnit *wu, int worker) {
emit workBegin(job, wu, worker);
@ -53,7 +58,12 @@ public:
/// Called when the whole target image has been altered in some way
inline void refreshEvent(const RenderJob *job, const Bitmap *bitmap) {
emit refresh(job, bitmap);
m_mutex->lock();
m_bitmap = bitmap;
emit refresh(job);
m_cond->wait(500);
m_bitmap = NULL;
m_mutex->unlock();
}
/// Called when a render job has completed successfully or unsuccessfully
@ -61,14 +71,29 @@ public:
emit jobFinished(job, cancelled);
}
/// Lock the mutex
inline void lock() { m_mutex->lock(); }
/// Access the image associated with the last refresh event
inline const Bitmap *getBitmap() const { return m_bitmap.get(); }
/// Unlock the mutex
inline void unlock() { m_mutex->unlock(); }
MTS_DECLARE_CLASS()
signals:
void workBegin(const RenderJob *job, const RectangularWorkUnit *wu, int worker);
void workEnd(const RenderJob *job, const ImageBlock *wr);
void refresh(const RenderJob *job, const Bitmap *bitmap);
void refresh(const RenderJob *job);
void jobFinished(const RenderJob *job, bool cancelled);
protected:
virtual ~QRenderListener() { }
private:
ref<Mutex> m_mutex;
ref<ConditionVariable> m_cond;
ref<Bitmap> m_bitmap;
};
class PreviewSettingsDialog;