Skip to content

Commit 51dfb69

Browse files
committed
add initial valid check before mutex
1 parent 1f87c90 commit 51dfb69

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Framework/API/src/MatrixWorkspace.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,9 +1114,15 @@ bool MatrixWorkspace::isHistogramDataByIndex(const std::size_t index) const {
11141114
}
11151115

11161116
bool MatrixWorkspace::setCommonBinsFlag(const bool value) const {
1117+
// check valid flag before acquiring lock
11171118
if (m_isCommonBinsFlagValid.load(std::memory_order_acquire))
11181119
return m_isCommonBinsFlag.load(std::memory_order_relaxed);
11191120
std::lock_guard<std::mutex> lock{m_isCommonBinsMutex};
1121+
1122+
// after acquiring lock, check valid flag again
1123+
if (m_isCommonBinsFlagValid.load(std::memory_order_acquire))
1124+
return m_isCommonBinsFlag.load(std::memory_order_relaxed);
1125+
11201126
m_isCommonBinsFlag.store(value, std::memory_order_relaxed);
11211127
m_isCommonBinsFlagValid.store(true, std::memory_order_release);
11221128
return value;

0 commit comments

Comments
 (0)