Skip to content

Commit

Permalink
Re #5552. A safer way of locking the mutex.
Browse files Browse the repository at this point in the history
In particular, trying to unlock it after the return statement is
not going to work out well.
This might also get this compiling with gcc 4.7.
  • Loading branch information
RussellTaylor committed Aug 8, 2012
1 parent 37bc273 commit fb50c37
Showing 1 changed file with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ namespace MDEvents
public:
void addBoxToSplit(const T &theBox)
{
m_boxesToSplitMutex.lock();
Kernel::Mutex::ScopedLock _lock(m_boxesToSplitMutex);
m_boxesToSplit.push_back(theBox);
m_boxesToSplitMutex.unlock();
}

//-----------------------------------------------------------------------------------
Expand All @@ -72,18 +71,17 @@ namespace MDEvents
template<class MDBoxToChange >
std::vector< MDBoxToChange > getBoxesToSplit()const
{
m_boxesToSplitMutex.lock();
Kernel::Mutex::ScopedLock _lock(m_boxesToSplitMutex);
return m_boxesToSplit;
m_boxesToSplitMutex.unlock();
}
//-----------------------------------------------------------------------------------
/** Clears the list of boxes that are big enough to split */
void clearBoxesToSplit()
{
m_boxesToSplitMutex.lock();
Kernel::Mutex::ScopedLock _lock(m_boxesToSplitMutex);
m_boxesToSplit.clear();
m_boxesToSplitMutex.unlock();
}

/**Copy constructor from a box controller pointer */
BoxCtrlChangesList(const API::BoxController & theController):
BoxController(theController)
Expand All @@ -103,7 +101,7 @@ namespace MDEvents
BoxCtrlChangesList(size_t nd):BoxController(nd){};

private:
//

/// Mutex for modifying the m_boxesToSplit member
Mantid::Kernel::Mutex m_boxesToSplitMutex;

Expand All @@ -113,4 +111,4 @@ namespace MDEvents

}
}
#endif
#endif

0 comments on commit fb50c37

Please sign in to comment.