Skip to content

Commit

Permalink
HPCC-33586 Fix double-checked locking pattern for CNamedGroupStore in…
Browse files Browse the repository at this point in the history
… Dali

Change groupStore to be an atomic pointer for thread safety.

Signed-off-by: Dave Streeter <[email protected]>
  • Loading branch information
streeterd committed Mar 5, 2025
1 parent b58cb35 commit 192c358
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions dali/base/dadfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8239,20 +8239,22 @@ class CNamedGroupStore: implements INamedGroupStore, public CInterface

};

static CNamedGroupStore *groupStore = NULL;
static std::atomic<CNamedGroupStore *> groupStore{nullptr};
static CriticalSection groupsect;

bool CNamedGroupIterator::match()
{
if (conn.get()) {
if (matchgroup.get()) {
if (!groupStore)
CLeavableCriticalBlock block3(groupsect);
if (!groupStore.load())
return false;
const char *name = pe->query().queryProp("@name");
if (!name||!*name)
return false;
GroupType dummy;
Owned<IGroup> lgrp = groupStore->dolookup(name, conn, NULL, dummy);
Owned<IGroup> lgrp = groupStore.load()->dolookup(name, conn, NULL, dummy);
block3.leave();
if (lgrp) {
if (exactmatch)
return lgrp->equals(matchgroup);
Expand All @@ -8266,14 +8268,13 @@ bool CNamedGroupIterator::match()
return false;
}

INamedGroupStore &queryNamedGroupStore()
INamedGroupStore &queryNamedGroupStore()
{
if (!groupStore) {
CriticalBlock block(groupsect);
if (!groupStore)
groupStore = new CNamedGroupStore();
CriticalBlock block(groupsect);
if (!groupStore.load()) {
groupStore.store(new CNamedGroupStore());
}
return *groupStore;
return *(groupStore.load());
}

// --------------------------------------------------------
Expand Down Expand Up @@ -9244,8 +9245,8 @@ void closedownDFS() // called by dacoven
}
DFdir = NULL;
CriticalBlock block2(groupsect);
::Release(groupStore);
groupStore = NULL;
::Release(groupStore.load());
groupStore.store(nullptr);
}

class CDFPartFilter : implements IDFPartFilter, public CInterface
Expand Down

0 comments on commit 192c358

Please sign in to comment.