Skip to content

Commit

Permalink
Protect against creating two default COs from two threads.
Browse files Browse the repository at this point in the history
  • Loading branch information
daschuer committed Aug 20, 2021
1 parent f231655 commit bb389e9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/control/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,15 @@ QSharedPointer<ControlDoublePrivate> ControlDoublePrivate::getControl(
QSharedPointer<ControlDoublePrivate> ControlDoublePrivate::getDefaultControl() {
auto defaultCO = QSharedPointer<ControlDoublePrivate>(s_defaultCO);
if (!defaultCO) {
defaultCO = QSharedPointer<ControlDoublePrivate>(new ControlDoublePrivateConst());
s_defaultCO = defaultCO;
// Try again with the mutex locked to protect against creating two
// ControlDoublePrivateConst objects. Access to s_defaultCO itself is
// thread save.
MMutexLocker locker(&s_qCOHashMutex);
defaultCO = QSharedPointer<ControlDoublePrivate>(s_defaultCO);
if (!defaultCO) {
defaultCO = QSharedPointer<ControlDoublePrivate>(new ControlDoublePrivateConst());
s_defaultCO = defaultCO;
}
}
return defaultCO;
}
Expand Down

0 comments on commit bb389e9

Please sign in to comment.