mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-18 11:19:10 +00:00
More std::atomic and friends
This commit is contained in:
@ -815,10 +815,10 @@ void NetCommActivatePostInitErrorHandler () {
|
||||
//============================================================================
|
||||
void NetCommUpdate () {
|
||||
// plClient likes to recursively call us on occasion; debounce that crap.
|
||||
static long s_updating;
|
||||
if (0 == AtomicSet(&s_updating, 1)) {
|
||||
static std::atomic_flag s_updating = ATOMIC_FLAG_INIT;
|
||||
if (!s_updating.test_and_set()) {
|
||||
NetClientUpdate();
|
||||
AtomicSet(&s_updating, 0);
|
||||
s_updating.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -273,7 +273,7 @@ static const char * s_transTypes[] = {
|
||||
};
|
||||
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; }
|
||||
|
@ -1208,7 +1208,7 @@ static ShaDigest s_accountNamePassHash;
|
||||
static wchar_t s_authToken[kMaxPublisherAuthKeyLength];
|
||||
static wchar_t s_os[kMaxGTOSIdLength];
|
||||
|
||||
static long s_perf[kNumPerf];
|
||||
static std::atomic<long> s_perf[kNumPerf];
|
||||
|
||||
static uint32_t s_encryptionKey[4];
|
||||
|
||||
@ -1596,14 +1596,14 @@ CliAuConn::CliAuConn ()
|
||||
{
|
||||
memset(name, 0, sizeof(name));
|
||||
|
||||
AtomicAdd(&s_perf[kPerfConnCount], 1);
|
||||
++s_perf[kPerfConnCount];
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
CliAuConn::~CliAuConn () {
|
||||
if (cli)
|
||||
NetCliDelete(cli, true);
|
||||
AtomicAdd(&s_perf[kPerfConnCount], -1);
|
||||
--s_perf[kPerfConnCount];
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
@ -77,7 +77,7 @@ struct ReportNetErrorTrans : NetNotifyTrans {
|
||||
***/
|
||||
|
||||
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 () {
|
||||
|
||||
if (0 == AtomicAdd(&s_initCount, 1)) {
|
||||
if (0 == s_initCount.fetch_add(1)) {
|
||||
NetTransInitialize();
|
||||
AuthInitialize();
|
||||
GameInitialize();
|
||||
@ -160,7 +160,7 @@ void NetClientCancelAllTrans () {
|
||||
//============================================================================
|
||||
void NetClientDestroy (bool wait) {
|
||||
|
||||
if (1 == AtomicAdd(&s_initCount, -1)) {
|
||||
if (1 == s_initCount.fetch_sub(1)) {
|
||||
s_errorProc = nil;
|
||||
|
||||
GateKeeperDestroy(false);
|
||||
|
@ -225,7 +225,7 @@ static bool s_running;
|
||||
static CCritSect s_critsect;
|
||||
static LISTDECL(CliFileConn, link) s_conns;
|
||||
static CliFileConn * s_active;
|
||||
static long s_perf[kNumPerf];
|
||||
static std::atomic<long> s_perf[kNumPerf];
|
||||
static unsigned s_connectBuildId;
|
||||
static unsigned s_serverType;
|
||||
|
||||
@ -588,7 +588,7 @@ CliFileConn::CliFileConn ()
|
||||
, pingTimer(nil), pingSendTimeMs(0), lastHeardTimeMs(0)
|
||||
{
|
||||
memset(name, 0, sizeof(name));
|
||||
AtomicAdd(&s_perf[kPerfConnCount], 1);
|
||||
++s_perf[kPerfConnCount];
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
@ -596,7 +596,7 @@ CliFileConn::~CliFileConn () {
|
||||
ASSERT(!cancelId);
|
||||
ASSERT(!reconnectTimer);
|
||||
Destroy();
|
||||
AtomicAdd(&s_perf[kPerfConnCount], -1);
|
||||
--s_perf[kPerfConnCount];
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
@ -156,7 +156,7 @@ static LISTDECL(CliGmConn, link) s_conns;
|
||||
static CliGmConn * s_active;
|
||||
static FNetCliGameRecvBufferHandler s_bufHandler;
|
||||
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)
|
||||
, pingTimer(nil), pingSendTimeMs(0), lastHeardTimeMs(0)
|
||||
{
|
||||
AtomicAdd(&s_perf[kPerfConnCount], 1);
|
||||
++s_perf[kPerfConnCount];
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
CliGmConn::~CliGmConn () {
|
||||
if (cli)
|
||||
NetCliDelete(cli, true);
|
||||
AtomicAdd(&s_perf[kPerfConnCount], -1);
|
||||
--s_perf[kPerfConnCount];
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
|
@ -188,7 +188,7 @@ static CCritSect s_critsect;
|
||||
static LISTDECL(CliGkConn, link) s_conns;
|
||||
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));
|
||||
|
||||
AtomicAdd(&s_perf[kPerfConnCount], 1);
|
||||
++s_perf[kPerfConnCount];
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
CliGkConn::~CliGkConn () {
|
||||
if (cli)
|
||||
NetCliDelete(cli, true);
|
||||
AtomicAdd(&s_perf[kPerfConnCount], -1);
|
||||
--s_perf[kPerfConnCount];
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
@ -66,7 +66,7 @@ static const unsigned kDefaultTimeoutMs = 5 * 60 * 1000;
|
||||
static bool s_running;
|
||||
static CCritSect s_critsect;
|
||||
static LISTDECL(NetTrans, m_link) s_transactions;
|
||||
static long s_perf[kNumPerf];
|
||||
static std::atomic<long> s_perf[kNumPerf];
|
||||
static unsigned s_timeoutMs = kDefaultTimeoutMs;
|
||||
|
||||
|
||||
@ -127,16 +127,16 @@ NetTrans::NetTrans (ENetProtocol protocol, ETransType transType)
|
||||
, m_timeoutAtMs(0)
|
||||
, m_transType(transType)
|
||||
{
|
||||
AtomicAdd(&s_perf[kPerfCurrTransactions], 1);
|
||||
AtomicAdd(&s_perfTransCount[m_transType], 1);
|
||||
++s_perf[kPerfCurrTransactions];
|
||||
++s_perfTransCount[m_transType];
|
||||
// DebugMsg("%s@%p created", s_transTypes[m_transType], this);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
NetTrans::~NetTrans () {
|
||||
ASSERT(!m_link.IsLinked());
|
||||
AtomicAdd(&s_perfTransCount[m_transType], -1);
|
||||
AtomicAdd(&s_perf[kPerfCurrTransactions], -1);
|
||||
--s_perfTransCount[m_transType];
|
||||
--s_perf[kPerfCurrTransactions];
|
||||
// DebugMsg("%s@%p destroyed", s_transTypes[m_transType], this);
|
||||
}
|
||||
|
||||
|
@ -250,7 +250,7 @@ struct AddChildNodeFetchTrans {
|
||||
FVaultAddChildNodeCallback callback;
|
||||
void * cbParam;
|
||||
ENetError result;
|
||||
long opCount;
|
||||
std::atomic<long> opCount;
|
||||
|
||||
AddChildNodeFetchTrans()
|
||||
: callback(nil), cbParam(nil), result(kNetSuccess), opCount(0) { }
|
||||
@ -1019,12 +1019,11 @@ void AddChildNodeFetchTrans::VaultNodeRefsFetched (
|
||||
param,
|
||||
&incFetchCount
|
||||
);
|
||||
AtomicAdd(&trans->opCount, incFetchCount);
|
||||
trans->opCount += incFetchCount;
|
||||
}
|
||||
|
||||
// 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)
|
||||
trans->callback(
|
||||
trans->result,
|
||||
@ -1046,9 +1045,8 @@ void AddChildNodeFetchTrans::VaultNodeFetched (
|
||||
|
||||
if (IS_NET_ERROR(result))
|
||||
trans->result = result;
|
||||
|
||||
AtomicAdd(&trans->opCount, -1);
|
||||
if (!trans->opCount) {
|
||||
|
||||
if (!(--trans->opCount)) {
|
||||
if (trans->callback)
|
||||
trans->callback(
|
||||
trans->result,
|
||||
@ -1793,13 +1791,13 @@ void VaultAddChildNode (
|
||||
// One or more nodes need to be fetched before the callback is made
|
||||
AddChildNodeFetchTrans * trans = new AddChildNodeFetchTrans(callback, param);
|
||||
if (!childLink->node->GetNodeType()) {
|
||||
AtomicAdd(&trans->opCount, 1);
|
||||
++trans->opCount;
|
||||
NetCliAuthVaultNodeFetch(
|
||||
childId,
|
||||
AddChildNodeFetchTrans::VaultNodeFetched,
|
||||
trans
|
||||
);
|
||||
AtomicAdd(&trans->opCount, 1);
|
||||
++trans->opCount;
|
||||
NetCliAuthVaultFetchNodeRefs(
|
||||
childId,
|
||||
AddChildNodeFetchTrans::VaultNodeRefsFetched,
|
||||
@ -1807,13 +1805,13 @@ void VaultAddChildNode (
|
||||
);
|
||||
}
|
||||
if (!parentLink->node->GetNodeType()) {
|
||||
AtomicAdd(&trans->opCount, 1);
|
||||
++trans->opCount;
|
||||
NetCliAuthVaultNodeFetch(
|
||||
parentId,
|
||||
AddChildNodeFetchTrans::VaultNodeFetched,
|
||||
trans
|
||||
);
|
||||
AtomicAdd(&trans->opCount, 1);
|
||||
++trans->opCount;
|
||||
NetCliAuthVaultFetchNodeRefs(
|
||||
parentId,
|
||||
AddChildNodeFetchTrans::VaultNodeRefsFetched,
|
||||
@ -2218,8 +2216,7 @@ namespace _VaultFetchNodesAndWait {
|
||||
) {
|
||||
::VaultNodeFetched(result, nil, node);
|
||||
|
||||
long * nodeCount = (long *)param;
|
||||
AtomicAdd(nodeCount, -1);
|
||||
--(*reinterpret_cast<std::atomic<unsigned>*>(param));
|
||||
}
|
||||
|
||||
} // namespace _VaultFetchNodesAndWait
|
||||
@ -2231,20 +2228,21 @@ void VaultFetchNodesAndWait (
|
||||
) {
|
||||
using namespace _VaultFetchNodesAndWait;
|
||||
|
||||
long nodeCount = (long)count;
|
||||
std::atomic<unsigned> nodeCount(count);
|
||||
|
||||
for (unsigned i = 0; i < count; ++i) {
|
||||
|
||||
if (!force) {
|
||||
// See if we already have this node
|
||||
if (RelVaultNodeLink * link = s_nodes.Find(nodeIds[i])) {
|
||||
AtomicAdd(&nodeCount, -1);
|
||||
--nodeCount;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Start fetching the node
|
||||
NetCliAuthVaultNodeFetch(nodeIds[i], _VaultNodeFetched, (void *)&nodeCount);
|
||||
// Start fetching the node
|
||||
NetCliAuthVaultNodeFetch(nodeIds[i], _VaultNodeFetched,
|
||||
reinterpret_cast<void *>(&nodeCount));
|
||||
}
|
||||
|
||||
while (nodeCount) {
|
||||
|
Reference in New Issue
Block a user