23 OrganizeWriteAccess();
31 m_Image->m_ReadWriteLock.Lock();
34 auto it = std::find(m_Image->m_Writers.begin(), m_Image->m_Writers.end(),
this);
35 m_Image->m_Writers.erase(it);
38 if (m_WaitLock->m_WaiterCount <= 0)
40 m_WaitLock->m_Mutex.Unlock();
45 m_WaitLock->m_Mutex.Unlock();
48 m_Image->m_ReadWriteLock.Unlock();
53 return m_Image.GetPointer();
56 void mitk::ImageWriteAccessor::OrganizeWriteAccess()
58 m_Image->m_ReadWriteLock.Lock();
60 bool readOverlap =
false;
61 bool writeOverlap =
false;
66 if (m_Image->m_Readers.size() > 0)
70 auto it = m_Image->m_Readers.begin();
72 for (; it != m_Image->m_Readers.end(); ++it)
76 if ((r->
m_Options & IgnoreLock) == 0 && Overlap(r))
80 PreventRecursiveMutexLock(r);
90 if (m_Image->m_Writers.size() > 0)
94 auto it = m_Image->m_Writers.begin();
96 for (; it != m_Image->m_Writers.end(); ++it)
98 ImageAccessorBase *w = *it;
104 PreventRecursiveMutexLock(w);
108 overlapLock = w->m_WaitLock;
115 if (readOverlap || writeOverlap)
119 if (!(m_Options & ExceptionIfLocked))
123 m_Image->m_ReadWriteLock.Unlock();
127 OrganizeWriteAccess();
133 m_Image->m_ReadWriteLock.Unlock();
135 <<
"The image part being ordered by the ImageAccessor is already in use and locked";
143 m_WaitLock->m_Mutex.Lock();
146 m_Image->m_Writers.push_back(
this);
150 m_Image->m_ReadWriteLock.Unlock();
void WaitForReleaseOf(ImageAccessorWaitLock *wL)
Uses the WaitLock to wait for another ImageAccessor.
ImageWriteAccessor(ImagePointer image, const ImageDataItem *iDI=nullptr, int OptionFlags=ImageAccessorBase::DefaultBehavior)
Orders write access for a slice, volume or 4D-Image.
unsigned int m_WaiterCount
Holds the number of ImageAccessors, which are waiting until the represented ImageAccessor is released...
virtual ~ImageWriteAccessor()
informs Image to unlock the represented image part
ImageAccessorWaitLock * m_WaitLock
Pointer to a WaitLock struct, that allows other ImageAccessors to wait for this ImageAccessor.
Image class for storing images.
#define mitkThrowException(classname)
int m_Options
Stores all extended properties of an ImageAccessor. The different flags in mitk::ImageAccessorBase::O...
This struct allows to make ImageAccessors wait for this particular ImageAccessor object.
Internal class for managing references on sub-images.
virtual const Image * GetImage() const override