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

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

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

◆ ~StrippedSafeSavingLocker()

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

Definition at line 583 of file KisDocument.cpp.

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

References m_imageLock, m_locked, and m_savingLock.

Member Function Documentation

◆ successfullyLocked()

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

Definition at line 590 of file KisDocument.cpp.

590 {
591 return m_locked;
592 }

References m_locked.

Member Data Documentation

◆ m_image

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

Definition at line 598 of file KisDocument.cpp.

◆ m_imageLock

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

Definition at line 600 of file KisDocument.cpp.

◆ m_locked

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

Definition at line 597 of file KisDocument.cpp.

◆ m_savingLock

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

Definition at line 599 of file KisDocument.cpp.


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