Browse Source

More std::atomic and friends

Michael Hansen 11 years ago
parent
commit
34b2eb1836
  1. 15
      Sources/Plasma/CoreLib/HeadSpin.h
  2. 8
      Sources/Plasma/FeatureLib/pfGameMgr/pfGameMgr.cpp
  3. 18
      Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNt.cpp
  4. 8
      Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtInt.h
  5. 15
      Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp
  6. 9
      Sources/Plasma/NucleusLib/pnAsyncCoreExe/pnAceCore.cpp
  7. 6
      Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp
  8. 2
      Sources/Plasma/PubUtilLib/plNetGameLib/Intern.h
  9. 6
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp
  10. 6
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCore.cpp
  11. 6
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.cpp
  12. 6
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.cpp
  13. 6
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.cpp
  14. 10
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglTrans.cpp
  15. 28
      Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp

15
Sources/Plasma/CoreLib/HeadSpin.h

@ -489,19 +489,4 @@ void DebugMsg(const char* fmt, ...);
#define DEFAULT_FATAL(var) default: FATAL("No valid case for switch variable '" #var "'"); break; #define DEFAULT_FATAL(var) default: FATAL("No valid case for switch variable '" #var "'"); break;
#endif #endif
/*****************************************************************************
*
* Atomic Operations
* FIXME: Replace with std::atomic when VS2012 supports WinXP
*
***/
#ifdef _MSC_VER
# define AtomicAdd(value, increment) InterlockedExchangeAdd(value, increment)
# define AtomicSet(value, set) InterlockedExchange(value, set)
#elif __GNUC__
# define AtomicAdd(value, increment) __sync_fetch_and_add(value, increment)
# define AtomicSet(value, set) __sync_lock_test_and_set(value, set)
#endif
#endif #endif

8
Sources/Plasma/FeatureLib/pfGameMgr/pfGameMgr.cpp

@ -133,7 +133,7 @@ static HASHTABLEDECL(TransState, THashKeyVal<unsigned>, link) s_trans;
static HASHTABLEDECL(IGameCli, THashKeyVal<unsigned>, link) s_games; static HASHTABLEDECL(IGameCli, THashKeyVal<unsigned>, link) s_games;
static std::map<plUUID, Factory*> s_factories; static std::map<plUUID, Factory*> s_factories;
static long s_transId; static std::atomic<unsigned> s_transId;
static ARRAYOBJ(plKey) s_receivers; static ARRAYOBJ(plKey) s_receivers;
@ -163,11 +163,7 @@ AUTO_INIT_FUNC (SetGameMgrMsgHandler) {
//============================================================================ //============================================================================
static inline unsigned INextTransId () { static inline unsigned INextTransId () {
return ++s_transId;
unsigned transId = AtomicAdd(&s_transId, 1);
while (!transId)
transId = AtomicAdd(&s_transId, 1);
return transId;
} }

18
Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNt.cpp

@ -80,7 +80,6 @@ static unsigned s_pageSizeMask;
//=========================================================================== //===========================================================================
CNtWaitHandle::CNtWaitHandle () { CNtWaitHandle::CNtWaitHandle () {
m_refCount = 1;
m_event = CreateEvent( m_event = CreateEvent(
(LPSECURITY_ATTRIBUTES) nil, (LPSECURITY_ATTRIBUTES) nil,
true, // manual reset true, // manual reset
@ -94,17 +93,6 @@ CNtWaitHandle::~CNtWaitHandle () {
CloseHandle(m_event); CloseHandle(m_event);
} }
//===========================================================================
void CNtWaitHandle::IncRef () {
InterlockedIncrement(&m_refCount);
}
//===========================================================================
void CNtWaitHandle::DecRef () {
if (!InterlockedDecrement(&m_refCount))
delete this;
}
//=========================================================================== //===========================================================================
bool CNtWaitHandle::WaitForObject (unsigned timeMs) const { bool CNtWaitHandle::WaitForObject (unsigned timeMs) const {
return WAIT_TIMEOUT != WaitForSingleObject(m_event, timeMs); return WAIT_TIMEOUT != WaitForSingleObject(m_event, timeMs);
@ -189,7 +177,7 @@ static void INtOpDispatch (
// set event *after* operation is complete // set event *after* operation is complete
if (signalComplete) { if (signalComplete) {
signalComplete->SignalObject(); signalComplete->SignalObject();
signalComplete->DecRef(); signalComplete->UnRef();
} }
// if we just deleted the last operation then stop dispatching // if we just deleted the last operation then stop dispatching
@ -203,7 +191,7 @@ static void INtOpDispatch (
if (op->pending) if (op->pending)
break; break;
InterlockedDecrement(&ntObj->ioCount); --ntObj->ioCount;
} }
ntObj->critsect.Leave(); ntObj->critsect.Leave();
@ -300,7 +288,7 @@ bool INtConnInitialize (NtObject * ntObj) {
//=========================================================================== //===========================================================================
void INtConnCompleteOperation (NtObject * ntObj) { void INtConnCompleteOperation (NtObject * ntObj) {
// are we completing the last operation for this object? // are we completing the last operation for this object?
if (InterlockedDecrement(&ntObj->ioCount)) if (--ntObj->ioCount)
return; return;
DWORD err = GetLastError(); DWORD err = GetLastError();

8
Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtInt.h

@ -50,6 +50,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#endif #endif
#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNASYNCCOREEXE_PRIVATE_NT_PNACENTINT_H #define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNASYNCCOREEXE_PRIVATE_NT_PNACENTINT_H
#include "hsRefCnt.h"
namespace Nt { namespace Nt {
@ -87,15 +88,12 @@ public:
BOOL TryEnter () { return TryEnterCriticalSection(&m_handle); } BOOL TryEnter () { return TryEnterCriticalSection(&m_handle); }
}; };
class CNtWaitHandle { class CNtWaitHandle : public hsAtomicRefCnt {
long m_refCount;
HANDLE m_event; HANDLE m_event;
public: public:
CNtWaitHandle (); CNtWaitHandle ();
~CNtWaitHandle (); ~CNtWaitHandle ();
void IncRef ();
void DecRef ();
bool WaitForObject (unsigned timeMs) const; bool WaitForObject (unsigned timeMs) const;
void SignalObject () const; void SignalObject () const;
}; };
@ -131,7 +129,7 @@ struct NtObject {
LISTDECL(Operation, link) opList; LISTDECL(Operation, link) opList;
long nextCompleteSequence; long nextCompleteSequence;
long nextStartSequence; long nextStartSequence;
long ioCount; std::atomic<long> ioCount;
bool closed; bool closed;
NtObject() NtObject()

15
Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp

@ -49,6 +49,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#pragma hdrstop #pragma hdrstop
#include "pnAceNtInt.h" #include "pnAceNtInt.h"
#include <mutex>
namespace Nt { namespace Nt {
@ -222,7 +223,7 @@ static void SocketStartAsyncRead (NtSock * sock) {
bool readResult; bool readResult;
sock->critsect.Enter(); sock->critsect.Enter();
if (sock->handle != INVALID_HANDLE_VALUE) { if (sock->handle != INVALID_HANDLE_VALUE) {
InterlockedIncrement(&sock->ioCount); ++sock->ioCount;
readResult = ReadFile( readResult = ReadFile(
sock->handle, sock->handle,
sock->buffer + sock->bytesLeft, sock->buffer + sock->bytesLeft,
@ -238,7 +239,7 @@ static void SocketStartAsyncRead (NtSock * sock) {
DWORD err = GetLastError(); DWORD err = GetLastError();
if (!readResult && (err != ERROR_IO_PENDING)) if (!readResult && (err != ERROR_IO_PENDING))
InterlockedDecrement(&sock->ioCount); --sock->ioCount;
} }
//=========================================================================== //===========================================================================
@ -378,7 +379,7 @@ static NtOpSocketWrite * SocketQueueAsyncWrite (
op->write.bytesProcessed = bytes; op->write.bytesProcessed = bytes;
memcpy(op->write.buffer, data, bytes); memcpy(op->write.buffer, data, bytes);
InterlockedIncrement(&sock->ioCount); ++sock->ioCount;
PerfAddCounter(kAsyncPerfSocketBytesWaitQueued, bytes); PerfAddCounter(kAsyncPerfSocketBytesWaitQueued, bytes);
return op; return op;
@ -1022,8 +1023,8 @@ void INtSocketOpCompleteSocketRead (
|| ((sock->opRead.read.bytesProcessed + sock->bytesLeft) > sizeof(sock->buffer)) || ((sock->opRead.read.bytesProcessed + sock->bytesLeft) > sizeof(sock->buffer))
) { ) {
#ifdef HS_DEBUGGING #ifdef HS_DEBUGGING
static long s_once; static std::once_flag s_once;
if (!AtomicAdd(&s_once, 1)) { std::call_once(s_once, [sock]() {
DumpInvalidData( DumpInvalidData(
"NtSockErr.log", "NtSockErr.log",
sizeof(sock->buffer), sizeof(sock->buffer),
@ -1034,7 +1035,7 @@ void INtSocketOpCompleteSocketRead (
sock->opRead.read.bytes, sock->opRead.read.bytes,
sock->opRead.read.bytesProcessed sock->opRead.read.bytesProcessed
); );
} });
#endif // ifdef HS_DEBUGGING #endif // ifdef HS_DEBUGGING
LogMsg( LogMsg(
@ -1419,7 +1420,7 @@ bool NtSocketWrite (
op->write.bytesProcessed = bytes; op->write.bytesProcessed = bytes;
PerfAddCounter(kAsyncPerfSocketBytesWaitQueued, bytes); PerfAddCounter(kAsyncPerfSocketBytesWaitQueued, bytes);
InterlockedIncrement(&sock->ioCount); ++sock->ioCount;
if (op == sock->opList.Head()) if (op == sock->opList.Head())
result = INtSocketOpCompleteQueuedSocketWrite((NtSock *) sock, op); result = INtSocketOpCompleteQueuedSocketWrite((NtSock *) sock, op);

9
Sources/Plasma/NucleusLib/pnAsyncCoreExe/pnAceCore.cpp

@ -48,6 +48,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "Pch.h" #include "Pch.h"
#pragma hdrstop #pragma hdrstop
#include <atomic>
/***************************************************************************** /*****************************************************************************
* *
@ -55,7 +56,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
* *
***/ ***/
static long s_perf[kNumAsyncPerfCounters]; static std::atomic<long> s_perf[kNumAsyncPerfCounters];
/**************************************************************************** /****************************************************************************
@ -124,19 +125,19 @@ static void IAsyncInitForServer () {
//============================================================================ //============================================================================
long PerfAddCounter (unsigned id, unsigned n) { long PerfAddCounter (unsigned id, unsigned n) {
ASSERT(id < kNumAsyncPerfCounters); ASSERT(id < kNumAsyncPerfCounters);
return AtomicAdd(&s_perf[id], n); return s_perf[id].fetch_add(n);
} }
//============================================================================ //============================================================================
long PerfSubCounter (unsigned id, unsigned n) { long PerfSubCounter (unsigned id, unsigned n) {
ASSERT(id < kNumAsyncPerfCounters); ASSERT(id < kNumAsyncPerfCounters);
return AtomicAdd(&s_perf[id], -(signed)n); return s_perf[id].fetch_sub(n);
} }
//============================================================================ //============================================================================
long PerfSetCounter (unsigned id, unsigned n) { long PerfSetCounter (unsigned id, unsigned n) {
ASSERT(id < kNumAsyncPerfCounters); ASSERT(id < kNumAsyncPerfCounters);
return AtomicSet(&s_perf[id], n); return s_perf[id].exchange(n);
} }

6
Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp

@ -815,10 +815,10 @@ void NetCommActivatePostInitErrorHandler () {
//============================================================================ //============================================================================
void NetCommUpdate () { void NetCommUpdate () {
// plClient likes to recursively call us on occasion; debounce that crap. // plClient likes to recursively call us on occasion; debounce that crap.
static long s_updating; static std::atomic_flag s_updating = ATOMIC_FLAG_INIT;
if (0 == AtomicSet(&s_updating, 1)) { if (!s_updating.test_and_set()) {
NetClientUpdate(); NetClientUpdate();
AtomicSet(&s_updating, 0); s_updating.clear();
} }
} }

2
Sources/Plasma/PubUtilLib/plNetGameLib/Intern.h

@ -273,7 +273,7 @@ static const char * s_transTypes[] = {
}; };
static_assert(arrsize(s_transTypes) == kNumTransTypes, "Ngl Trans array and enum differ in size"); static_assert(arrsize(s_transTypes) == kNumTransTypes, "Ngl Trans array and enum differ in size");
static long s_perfTransCount[kNumTransTypes]; static std::atomic<long> s_perfTransCount[kNumTransTypes];
namespace Auth { struct CliAuConn; } namespace Auth { struct CliAuConn; }

6
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp

@ -1208,7 +1208,7 @@ static ShaDigest s_accountNamePassHash;
static wchar_t s_authToken[kMaxPublisherAuthKeyLength]; static wchar_t s_authToken[kMaxPublisherAuthKeyLength];
static wchar_t s_os[kMaxGTOSIdLength]; static wchar_t s_os[kMaxGTOSIdLength];
static long s_perf[kNumPerf]; static std::atomic<long> s_perf[kNumPerf];
static uint32_t s_encryptionKey[4]; static uint32_t s_encryptionKey[4];
@ -1596,14 +1596,14 @@ CliAuConn::CliAuConn ()
{ {
memset(name, 0, sizeof(name)); memset(name, 0, sizeof(name));
AtomicAdd(&s_perf[kPerfConnCount], 1); ++s_perf[kPerfConnCount];
} }
//============================================================================ //============================================================================
CliAuConn::~CliAuConn () { CliAuConn::~CliAuConn () {
if (cli) if (cli)
NetCliDelete(cli, true); NetCliDelete(cli, true);
AtomicAdd(&s_perf[kPerfConnCount], -1); --s_perf[kPerfConnCount];
} }
//=========================================================================== //===========================================================================

6
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCore.cpp

@ -77,7 +77,7 @@ struct ReportNetErrorTrans : NetNotifyTrans {
***/ ***/
static FNetClientErrorProc s_errorProc; static FNetClientErrorProc s_errorProc;
static long s_initCount; static std::atomic<long> s_initCount;
/***************************************************************************** /*****************************************************************************
@ -143,7 +143,7 @@ void ReportNetError (ENetProtocol protocol, ENetError error) {
//============================================================================ //============================================================================
void NetClientInitialize () { void NetClientInitialize () {
if (0 == AtomicAdd(&s_initCount, 1)) { if (0 == s_initCount.fetch_add(1)) {
NetTransInitialize(); NetTransInitialize();
AuthInitialize(); AuthInitialize();
GameInitialize(); GameInitialize();
@ -160,7 +160,7 @@ void NetClientCancelAllTrans () {
//============================================================================ //============================================================================
void NetClientDestroy (bool wait) { void NetClientDestroy (bool wait) {
if (1 == AtomicAdd(&s_initCount, -1)) { if (1 == s_initCount.fetch_sub(1)) {
s_errorProc = nil; s_errorProc = nil;
GateKeeperDestroy(false); GateKeeperDestroy(false);

6
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.cpp

@ -225,7 +225,7 @@ static bool s_running;
static CCritSect s_critsect; static CCritSect s_critsect;
static LISTDECL(CliFileConn, link) s_conns; static LISTDECL(CliFileConn, link) s_conns;
static CliFileConn * s_active; static CliFileConn * s_active;
static long s_perf[kNumPerf]; static std::atomic<long> s_perf[kNumPerf];
static unsigned s_connectBuildId; static unsigned s_connectBuildId;
static unsigned s_serverType; static unsigned s_serverType;
@ -588,7 +588,7 @@ CliFileConn::CliFileConn ()
, pingTimer(nil), pingSendTimeMs(0), lastHeardTimeMs(0) , pingTimer(nil), pingSendTimeMs(0), lastHeardTimeMs(0)
{ {
memset(name, 0, sizeof(name)); memset(name, 0, sizeof(name));
AtomicAdd(&s_perf[kPerfConnCount], 1); ++s_perf[kPerfConnCount];
} }
//============================================================================ //============================================================================
@ -596,7 +596,7 @@ CliFileConn::~CliFileConn () {
ASSERT(!cancelId); ASSERT(!cancelId);
ASSERT(!reconnectTimer); ASSERT(!reconnectTimer);
Destroy(); Destroy();
AtomicAdd(&s_perf[kPerfConnCount], -1); --s_perf[kPerfConnCount];
} }
//=========================================================================== //===========================================================================

6
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.cpp

@ -156,7 +156,7 @@ static LISTDECL(CliGmConn, link) s_conns;
static CliGmConn * s_active; static CliGmConn * s_active;
static FNetCliGameRecvBufferHandler s_bufHandler; static FNetCliGameRecvBufferHandler s_bufHandler;
static FNetCliGameRecvGameMgrMsgHandler s_gameMgrMsgHandler; static FNetCliGameRecvGameMgrMsgHandler s_gameMgrMsgHandler;
static long s_perf[kNumPerf]; static std::atomic<long> s_perf[kNumPerf];
/***************************************************************************** /*****************************************************************************
@ -419,14 +419,14 @@ CliGmConn::CliGmConn ()
, seq(0), abandoned(false) , seq(0), abandoned(false)
, pingTimer(nil), pingSendTimeMs(0), lastHeardTimeMs(0) , pingTimer(nil), pingSendTimeMs(0), lastHeardTimeMs(0)
{ {
AtomicAdd(&s_perf[kPerfConnCount], 1); ++s_perf[kPerfConnCount];
} }
//============================================================================ //============================================================================
CliGmConn::~CliGmConn () { CliGmConn::~CliGmConn () {
if (cli) if (cli)
NetCliDelete(cli, true); NetCliDelete(cli, true);
AtomicAdd(&s_perf[kPerfConnCount], -1); --s_perf[kPerfConnCount];
} }
//============================================================================ //============================================================================

6
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.cpp

@ -188,7 +188,7 @@ static CCritSect s_critsect;
static LISTDECL(CliGkConn, link) s_conns; static LISTDECL(CliGkConn, link) s_conns;
static CliGkConn * s_active; static CliGkConn * s_active;
static long s_perf[kNumPerf]; static std::atomic<long> s_perf[kNumPerf];
@ -532,14 +532,14 @@ CliGkConn::CliGkConn ()
{ {
memset(name, 0, sizeof(name)); memset(name, 0, sizeof(name));
AtomicAdd(&s_perf[kPerfConnCount], 1); ++s_perf[kPerfConnCount];
} }
//============================================================================ //============================================================================
CliGkConn::~CliGkConn () { CliGkConn::~CliGkConn () {
if (cli) if (cli)
NetCliDelete(cli, true); NetCliDelete(cli, true);
AtomicAdd(&s_perf[kPerfConnCount], -1); --s_perf[kPerfConnCount];
} }
//=========================================================================== //===========================================================================

10
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglTrans.cpp

@ -66,7 +66,7 @@ static const unsigned kDefaultTimeoutMs = 5 * 60 * 1000;
static bool s_running; static bool s_running;
static CCritSect s_critsect; static CCritSect s_critsect;
static LISTDECL(NetTrans, m_link) s_transactions; static LISTDECL(NetTrans, m_link) s_transactions;
static long s_perf[kNumPerf]; static std::atomic<long> s_perf[kNumPerf];
static unsigned s_timeoutMs = kDefaultTimeoutMs; static unsigned s_timeoutMs = kDefaultTimeoutMs;
@ -127,16 +127,16 @@ NetTrans::NetTrans (ENetProtocol protocol, ETransType transType)
, m_timeoutAtMs(0) , m_timeoutAtMs(0)
, m_transType(transType) , m_transType(transType)
{ {
AtomicAdd(&s_perf[kPerfCurrTransactions], 1); ++s_perf[kPerfCurrTransactions];
AtomicAdd(&s_perfTransCount[m_transType], 1); ++s_perfTransCount[m_transType];
// DebugMsg("%s@%p created", s_transTypes[m_transType], this); // DebugMsg("%s@%p created", s_transTypes[m_transType], this);
} }
//============================================================================ //============================================================================
NetTrans::~NetTrans () { NetTrans::~NetTrans () {
ASSERT(!m_link.IsLinked()); ASSERT(!m_link.IsLinked());
AtomicAdd(&s_perfTransCount[m_transType], -1); --s_perfTransCount[m_transType];
AtomicAdd(&s_perf[kPerfCurrTransactions], -1); --s_perf[kPerfCurrTransactions];
// DebugMsg("%s@%p destroyed", s_transTypes[m_transType], this); // DebugMsg("%s@%p destroyed", s_transTypes[m_transType], this);
} }

28
Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp

@ -250,7 +250,7 @@ struct AddChildNodeFetchTrans {
FVaultAddChildNodeCallback callback; FVaultAddChildNodeCallback callback;
void * cbParam; void * cbParam;
ENetError result; ENetError result;
long opCount; std::atomic<long> opCount;
AddChildNodeFetchTrans() AddChildNodeFetchTrans()
: callback(nil), cbParam(nil), result(kNetSuccess), opCount(0) { } : callback(nil), cbParam(nil), result(kNetSuccess), opCount(0) { }
@ -1019,12 +1019,11 @@ void AddChildNodeFetchTrans::VaultNodeRefsFetched (
param, param,
&incFetchCount &incFetchCount
); );
AtomicAdd(&trans->opCount, incFetchCount); trans->opCount += incFetchCount;
} }
// Make the callback now if there are no nodes to fetch, or if error // Make the callback now if there are no nodes to fetch, or if error
AtomicAdd(&trans->opCount, -1); if (!(--trans->opCount)) {
if (!trans->opCount) {
if (trans->callback) if (trans->callback)
trans->callback( trans->callback(
trans->result, trans->result,
@ -1047,8 +1046,7 @@ void AddChildNodeFetchTrans::VaultNodeFetched (
if (IS_NET_ERROR(result)) if (IS_NET_ERROR(result))
trans->result = result; trans->result = result;
AtomicAdd(&trans->opCount, -1); if (!(--trans->opCount)) {
if (!trans->opCount) {
if (trans->callback) if (trans->callback)
trans->callback( trans->callback(
trans->result, trans->result,
@ -1793,13 +1791,13 @@ void VaultAddChildNode (
// One or more nodes need to be fetched before the callback is made // One or more nodes need to be fetched before the callback is made
AddChildNodeFetchTrans * trans = new AddChildNodeFetchTrans(callback, param); AddChildNodeFetchTrans * trans = new AddChildNodeFetchTrans(callback, param);
if (!childLink->node->GetNodeType()) { if (!childLink->node->GetNodeType()) {
AtomicAdd(&trans->opCount, 1); ++trans->opCount;
NetCliAuthVaultNodeFetch( NetCliAuthVaultNodeFetch(
childId, childId,
AddChildNodeFetchTrans::VaultNodeFetched, AddChildNodeFetchTrans::VaultNodeFetched,
trans trans
); );
AtomicAdd(&trans->opCount, 1); ++trans->opCount;
NetCliAuthVaultFetchNodeRefs( NetCliAuthVaultFetchNodeRefs(
childId, childId,
AddChildNodeFetchTrans::VaultNodeRefsFetched, AddChildNodeFetchTrans::VaultNodeRefsFetched,
@ -1807,13 +1805,13 @@ void VaultAddChildNode (
); );
} }
if (!parentLink->node->GetNodeType()) { if (!parentLink->node->GetNodeType()) {
AtomicAdd(&trans->opCount, 1); ++trans->opCount;
NetCliAuthVaultNodeFetch( NetCliAuthVaultNodeFetch(
parentId, parentId,
AddChildNodeFetchTrans::VaultNodeFetched, AddChildNodeFetchTrans::VaultNodeFetched,
trans trans
); );
AtomicAdd(&trans->opCount, 1); ++trans->opCount;
NetCliAuthVaultFetchNodeRefs( NetCliAuthVaultFetchNodeRefs(
parentId, parentId,
AddChildNodeFetchTrans::VaultNodeRefsFetched, AddChildNodeFetchTrans::VaultNodeRefsFetched,
@ -2218,8 +2216,7 @@ namespace _VaultFetchNodesAndWait {
) { ) {
::VaultNodeFetched(result, nil, node); ::VaultNodeFetched(result, nil, node);
long * nodeCount = (long *)param; --(*reinterpret_cast<std::atomic<unsigned>*>(param));
AtomicAdd(nodeCount, -1);
} }
} // namespace _VaultFetchNodesAndWait } // namespace _VaultFetchNodesAndWait
@ -2231,20 +2228,21 @@ void VaultFetchNodesAndWait (
) { ) {
using namespace _VaultFetchNodesAndWait; using namespace _VaultFetchNodesAndWait;
long nodeCount = (long)count; std::atomic<unsigned> nodeCount(count);
for (unsigned i = 0; i < count; ++i) { for (unsigned i = 0; i < count; ++i) {
if (!force) { if (!force) {
// See if we already have this node // See if we already have this node
if (RelVaultNodeLink * link = s_nodes.Find(nodeIds[i])) { if (RelVaultNodeLink * link = s_nodes.Find(nodeIds[i])) {
AtomicAdd(&nodeCount, -1); --nodeCount;
continue; continue;
} }
} }
// Start fetching the node // Start fetching the node
NetCliAuthVaultNodeFetch(nodeIds[i], _VaultNodeFetched, (void *)&nodeCount); NetCliAuthVaultNodeFetch(nodeIds[i], _VaultNodeFetched,
reinterpret_cast<void *>(&nodeCount));
} }
while (nodeCount) { while (nodeCount) {

Loading…
Cancel
Save