Krita Source Code Documentation
Loading...
Searching...
No Matches
KisDocument::Private::StrippedSafeSavingLocker Class Reference

Public Member Functions

 StrippedSafeSavingLocker (QMutex *savingMutex, KisImageSP image)
 
bool successfullyLocked () const
 
 ~StrippedSafeSavingLocker ()
 

Private Attributes

KisImageSP m_image
 
KisImageReadOnlyBarrierLock m_imageLock
 
bool m_locked
 
QMutex * m_savingLock
 

Detailed Description

Definition at line 553 of file KisDocument.cpp.

Constructor & Destructor Documentation

◆ StrippedSafeSavingLocker()

KisDocument::Private::StrippedSafeSavingLocker::StrippedSafeSavingLocker ( QMutex * savingMutex,
KisImageSP image )
inline

Initial try to lock both objects. Locking the image guards us from any image composition threads running in the background, while savingMutex guards us from entering the saving code twice by autosave and main threads.

Since we are trying to lock multiple objects, so we should do it in a safe manner.

Definition at line 555 of file KisDocument.cpp.

556 : m_locked(false)
557 , m_image(image)
558 , m_savingLock(savingMutex)
559 , m_imageLock(image, std::defer_lock)
560
561 {
571 m_locked = std::try_lock(m_imageLock, *m_savingLock) < 0;
572
573 if (!m_locked) {
575 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
576
577 // one more try...
578 m_locked = std::try_lock(m_imageLock, *m_savingLock) < 0;
579 }
580 }
void requestStrokeEnd()

References m_image, m_imageLock, m_locked, m_savingLock, and KisImage::requestStrokeEnd().

◆ ~StrippedSafeSavingLocker()

KisDocument::Private::StrippedSafeSavingLocker::~StrippedSafeSavingLocker ( )
inline

Definition at line 582 of file KisDocument.cpp.

582 {
583 if (m_locked) {
584 m_imageLock.unlock();
585 m_savingLock->unlock();
586 }
587 }

References m_imageLock, m_locked, and m_savingLock.

Member Function Documentation

◆ successfullyLocked()

bool KisDocument::Private::StrippedSafeSavingLocker::successfullyLocked ( ) const
inline

Definition at line 589 of file KisDocument.cpp.

589 {
590 return m_locked;
591 }

References m_locked.

Member Data Documentation

◆ m_image

KisImageSP KisDocument::Private::StrippedSafeSavingLocker::m_image
private

Definition at line 597 of file KisDocument.cpp.

◆ m_imageLock

KisImageReadOnlyBarrierLock KisDocument::Private::StrippedSafeSavingLocker::m_imageLock
private

Definition at line 599 of file KisDocument.cpp.

◆ m_locked

bool KisDocument::Private::StrippedSafeSavingLocker::m_locked
private

Definition at line 596 of file KisDocument.cpp.

◆ m_savingLock

QMutex* KisDocument::Private::StrippedSafeSavingLocker::m_savingLock
private

Definition at line 598 of file KisDocument.cpp.


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