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 556 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 558 of file KisDocument.cpp.

559 : m_locked(false)
560 , m_image(image)
561 , m_savingLock(savingMutex)
562 , m_imageLock(image, std::defer_lock)
563
564 {
574 m_locked = std::try_lock(m_imageLock, *m_savingLock) < 0;
575
576 if (!m_locked) {
578 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
579
580 // one more try...
581 m_locked = std::try_lock(m_imageLock, *m_savingLock) < 0;
582 }
583 }
void requestStrokeEnd()

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

◆ ~StrippedSafeSavingLocker()

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

Definition at line 585 of file KisDocument.cpp.

585 {
586 if (m_locked) {
587 m_imageLock.unlock();
588 m_savingLock->unlock();
589 }
590 }

References m_imageLock, m_locked, and m_savingLock.

Member Function Documentation

◆ successfullyLocked()

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

Definition at line 592 of file KisDocument.cpp.

592 {
593 return m_locked;
594 }

References m_locked.

Member Data Documentation

◆ m_image

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

Definition at line 600 of file KisDocument.cpp.

◆ m_imageLock

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

Definition at line 602 of file KisDocument.cpp.

◆ m_locked

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

Definition at line 599 of file KisDocument.cpp.

◆ m_savingLock

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

Definition at line 601 of file KisDocument.cpp.


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