Skip to content

Commit 53ebcce

Browse files
committed
HPCC-33586 Fix double-checked locking pattern in Dali
Change DFdir to be an atomic pointer for thread safety. Signed-off-by: Dave Streeter <[email protected]>
1 parent 0928a7a commit 53ebcce

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

dali/base/dadfs.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -9205,7 +9205,7 @@ GetFileClusterNamesType CDistributedFileDirectory::getFileClusterNames(const cha
92059205
// --------------------------------------------------------
92069206

92079207

9208-
static CDistributedFileDirectory *DFdir = NULL;
9208+
static std::atomic<CDistributedFileDirectory *> DFdir{nullptr};
92099209
static CriticalSection dfdirCrit;
92109210

92119211
/**
@@ -9215,12 +9215,10 @@ static CriticalSection dfdirCrit;
92159215
*/
92169216
IDistributedFileDirectory &queryDistributedFileDirectory()
92179217
{
9218-
if (!DFdir) {
9219-
CriticalBlock block(dfdirCrit);
9220-
if (!DFdir)
9221-
DFdir = new CDistributedFileDirectory();
9222-
}
9223-
return *DFdir;
9218+
CriticalBlock block(dfdirCrit);
9219+
if (!DFdir.load())
9220+
DFdir.store(new CDistributedFileDirectory());
9221+
return *DFdir.load();
92249222
}
92259223

92269224
/**
@@ -9230,7 +9228,7 @@ void closedownDFS() // called by dacoven
92309228
{
92319229
CriticalBlock block(dfdirCrit);
92329230
try {
9233-
delete DFdir;
9231+
delete DFdir.load();
92349232
}
92359233
catch (IMP_Exception *e) {
92369234
if (e->errorCode()!=MPERR_link_closed)
@@ -9243,7 +9241,7 @@ void closedownDFS() // called by dacoven
92439241
throw;
92449242
e->Release();
92459243
}
9246-
DFdir = NULL;
9244+
DFdir.store(nullptr);
92479245
CriticalBlock block2(groupsect);
92489246
::Release(groupStore.load());
92499247
groupStore.store(nullptr);

0 commit comments

Comments
 (0)