diff --git a/dali/base/dadfs.cpp b/dali/base/dadfs.cpp index 1526640ca49..dbd1738589c 100644 --- a/dali/base/dadfs.cpp +++ b/dali/base/dadfs.cpp @@ -8239,20 +8239,19 @@ class CNamedGroupStore: implements INamedGroupStore, public CInterface }; -static CNamedGroupStore *groupStore = NULL; -static CriticalSection groupsect; +static std::atomic groupStore{nullptr}; bool CNamedGroupIterator::match() { if (conn.get()) { if (matchgroup.get()) { - if (!groupStore) + if (!groupStore.load()) return false; const char *name = pe->query().queryProp("@name"); if (!name||!*name) return false; GroupType dummy; - Owned lgrp = groupStore->dolookup(name, conn, NULL, dummy); + Owned lgrp = groupStore.load()->dolookup(name, conn, NULL, dummy); if (lgrp) { if (exactmatch) return lgrp->equals(matchgroup); @@ -8266,14 +8265,11 @@ bool CNamedGroupIterator::match() return false; } -INamedGroupStore &queryNamedGroupStore() +INamedGroupStore &queryNamedGroupStore() { - if (!groupStore) { - CriticalBlock block(groupsect); - if (!groupStore) - groupStore = new CNamedGroupStore(); - } - return *groupStore; + if (!groupStore.load()) + groupStore.store(new CNamedGroupStore()); + return *(groupStore.load()); } // -------------------------------------------------------- @@ -9204,8 +9200,7 @@ GetFileClusterNamesType CDistributedFileDirectory::getFileClusterNames(const cha // -------------------------------------------------------- -static CDistributedFileDirectory *DFdir = NULL; -static CriticalSection dfdirCrit; +static std::atomic DFdir{nullptr}; /** * Public method to control DistributedFileDirectory access @@ -9214,12 +9209,9 @@ static CriticalSection dfdirCrit; */ IDistributedFileDirectory &queryDistributedFileDirectory() { - if (!DFdir) { - CriticalBlock block(dfdirCrit); - if (!DFdir) - DFdir = new CDistributedFileDirectory(); - } - return *DFdir; + if (!DFdir.load()) + DFdir.store(new CDistributedFileDirectory()); + return *DFdir.load(); } /** @@ -9227,25 +9219,29 @@ IDistributedFileDirectory &queryDistributedFileDirectory() */ void closedownDFS() // called by dacoven { - CriticalBlock block(dfdirCrit); - try { - delete DFdir; - } - catch (IMP_Exception *e) { - if (e->errorCode()!=MPERR_link_closed) - throw; - PrintExceptionLog(e,"closedownDFS"); - e->Release(); + if (DFdir.load()) + { + try { + delete DFdir.load(); + } + catch (IMP_Exception *e) { + if (e->errorCode()!=MPERR_link_closed) + throw; + PrintExceptionLog(e,"closedownDFS"); + e->Release(); + } + catch (IDaliClient_Exception *e) { + if (e->errorCode()!=DCERR_server_closed) + throw; + e->Release(); + } + DFdir.store(nullptr); } - catch (IDaliClient_Exception *e) { - if (e->errorCode()!=DCERR_server_closed) - throw; - e->Release(); + if (groupStore.load()) + { + ::Release(groupStore.load()); + groupStore.store(nullptr); } - DFdir = NULL; - CriticalBlock block2(groupsect); - ::Release(groupStore); - groupStore = NULL; } class CDFPartFilter : implements IDFPartFilter, public CInterface