Krita Source Code Documentation
Loading...
Searching...
No Matches
KisBusyWaitBroker Class Reference

a simple singleton class for tracking busy-waits on the image and breaking deadlock ties when needed. More...

#include <KisBusyWaitBroker.h>

Classes

struct  Private
 

Public Member Functions

bool guiThreadIsWaitingForBetterWeather () const
 
 KisBusyWaitBroker ()
 
void notifyGeneralWaitEnded ()
 
void notifyGeneralWaitStarted ()
 
void notifyWaitOnImageEnded (KisImage *image)
 
void notifyWaitOnImageStarted (KisImage *image)
 
void setFeedbackCallback (std::function< void(KisImageSP)> callback)
 
 ~KisBusyWaitBroker ()
 

Static Public Member Functions

static KisBusyWaitBrokerinstance ()
 

Private Member Functions

 Q_DISABLE_COPY (KisBusyWaitBroker)
 

Private Attributes

QScopedPointer< Privatem_d
 

Detailed Description

a simple singleton class for tracking busy-waits on the image and breaking deadlock ties when needed.

When KisImage::barrierLock()/waitForDone() goes into sleep, waiting for the worker threads to finish, it notifies KisBusyWaitBroker about that. Therefore worker threads know that GUI thread is inactive now and can resolve the ties.

Definition at line 20 of file KisBusyWaitBroker.h.

Constructor & Destructor Documentation

◆ KisBusyWaitBroker()

KisBusyWaitBroker::KisBusyWaitBroker ( )

Definition at line 31 of file KisBusyWaitBroker.cpp.

32 : m_d(new Private)
33{
34}
QScopedPointer< Private > m_d

◆ ~KisBusyWaitBroker()

KisBusyWaitBroker::~KisBusyWaitBroker ( )

Definition at line 36 of file KisBusyWaitBroker.cpp.

37{
38}

Member Function Documentation

◆ guiThreadIsWaitingForBetterWeather()

bool KisBusyWaitBroker::guiThreadIsWaitingForBetterWeather ( ) const
Returns
true if GUI thread is currently sleeping on an image lock. When a worker thread is sure that GUI thread is sleeping, it has a bit more freedom in manipulating the image (and especially vector shapes)

Definition at line 103 of file KisBusyWaitBroker.cpp.

104{
105 return m_d->guiThreadLockCount;
106}

References m_d.

◆ instance()

KisBusyWaitBroker * KisBusyWaitBroker::instance ( )
static

Definition at line 40 of file KisBusyWaitBroker.cpp.

41{
42 return s_instance;
43}

◆ notifyGeneralWaitEnded()

void KisBusyWaitBroker::notifyGeneralWaitEnded ( )

Definition at line 90 of file KisBusyWaitBroker.cpp.

91{
92 if (QThread::currentThread() != qApp->thread()) return;
93
94 QMutexLocker l(&m_d->lock);
95 m_d->guiThreadLockCount--;
96}

References m_d.

◆ notifyGeneralWaitStarted()

void KisBusyWaitBroker::notifyGeneralWaitStarted ( )

Definition at line 82 of file KisBusyWaitBroker.cpp.

83{
84 if (QThread::currentThread() != qApp->thread()) return;
85
86 QMutexLocker l(&m_d->lock);
87 m_d->guiThreadLockCount++;
88}

References m_d.

◆ notifyWaitOnImageEnded()

void KisBusyWaitBroker::notifyWaitOnImageEnded ( KisImage * image)

Definition at line 65 of file KisBusyWaitBroker.cpp.

66{
67 if (QThread::currentThread() != qApp->thread()) return;
68
69 {
70 QMutexLocker l(&m_d->lock);
71 m_d->guiThreadLockCount--;
72
73 m_d->waitingOnImages[image]--;
74 KIS_SAFE_ASSERT_RECOVER_NOOP(m_d->waitingOnImages[image] >= 0);
75
76 if (m_d->waitingOnImages[image] == 0) {
77 m_d->waitingOnImages.remove(image);
78 }
79 }
80}
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130

References KIS_SAFE_ASSERT_RECOVER_NOOP, and m_d.

◆ notifyWaitOnImageStarted()

void KisBusyWaitBroker::notifyWaitOnImageStarted ( KisImage * image)

Definition at line 45 of file KisBusyWaitBroker.cpp.

46{
47 if (QThread::currentThread() != qApp->thread()) return;
48
49 bool needsStartCallback = false;
50
51 {
52 QMutexLocker l(&m_d->lock);
53
54 m_d->guiThreadLockCount++;
55 m_d->waitingOnImages[image]++;
56
57 needsStartCallback = m_d->waitingOnImages[image] == 1;
58 }
59
60 if (m_d->feedbackCallback && needsStartCallback && image->refCount()) {
61 m_d->feedbackCallback(image);
62 }
63}
int refCount()
Definition kis_shared.h:22

References m_d, and KisShared::refCount().

◆ Q_DISABLE_COPY()

KisBusyWaitBroker::Q_DISABLE_COPY ( KisBusyWaitBroker )
private

◆ setFeedbackCallback()

void KisBusyWaitBroker::setFeedbackCallback ( std::function< void(KisImageSP)> callback)

Set a callback that is called before image goes into sleep. This callback may show the user some feedback window with a progress bar.

This callback is expected to be initialized during the construction of KisPart.

Definition at line 98 of file KisBusyWaitBroker.cpp.

99{
100 m_d->feedbackCallback = callback;
101}

References m_d.

Member Data Documentation

◆ m_d

QScopedPointer<Private> KisBusyWaitBroker::m_d
private

Definition at line 56 of file KisBusyWaitBroker.h.


The documentation for this class was generated from the following files: