Browse Source

Merge pull request #422 from zrax/atomics_n_refs

Use C++11 Atomics and merge duplicate RefCount implementations
Adam Johnson 11 years ago
parent
commit
a332c9839d
  1. 2
      Sources/Plasma/CoreLib/CMakeLists.txt
  2. 15
      Sources/Plasma/CoreLib/HeadSpin.h
  3. 55
      Sources/Plasma/CoreLib/hsRefCnt.cpp
  4. 31
      Sources/Plasma/CoreLib/hsRefCnt.h
  5. 44
      Sources/Plasma/CoreLib/hsSafeRefCnt.cpp
  6. 65
      Sources/Plasma/CoreLib/hsSafeRefCnt.h
  7. 10
      Sources/Plasma/FeatureLib/pfGameMgr/pfGameMgr.cpp
  8. 4
      Sources/Plasma/FeatureLib/pfPython/cyAvatar.cpp
  9. 4
      Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp
  10. 2
      Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp
  11. 32
      Sources/Plasma/FeatureLib/pfPython/pyAgeVault.cpp
  12. 6
      Sources/Plasma/FeatureLib/pfPython/pyDniInfoSource.cpp
  13. 8
      Sources/Plasma/FeatureLib/pfPython/pyGameScore.cpp
  14. 70
      Sources/Plasma/FeatureLib/pfPython/pyVault.cpp
  15. 4
      Sources/Plasma/FeatureLib/pfPython/pyVaultAgeInfoListNodeGlue.cpp
  16. 8
      Sources/Plasma/FeatureLib/pfPython/pyVaultAgeInfoNode.cpp
  17. 4
      Sources/Plasma/FeatureLib/pfPython/pyVaultAgeInfoNodeGlue.cpp
  18. 2
      Sources/Plasma/FeatureLib/pfPython/pyVaultAgeLinkNode.cpp
  19. 4
      Sources/Plasma/FeatureLib/pfPython/pyVaultAgeLinkNodeGlue.cpp
  20. 4
      Sources/Plasma/FeatureLib/pfPython/pyVaultChronicleNodeGlue.cpp
  21. 4
      Sources/Plasma/FeatureLib/pfPython/pyVaultFolderNodeGlue.cpp
  22. 4
      Sources/Plasma/FeatureLib/pfPython/pyVaultImageNodeGlue.cpp
  23. 4
      Sources/Plasma/FeatureLib/pfPython/pyVaultMarkerGameNodeGlue.cpp
  24. 42
      Sources/Plasma/FeatureLib/pfPython/pyVaultNode.cpp
  25. 4
      Sources/Plasma/FeatureLib/pfPython/pyVaultNodeGlue.cpp
  26. 18
      Sources/Plasma/FeatureLib/pfPython/pyVaultNodeRef.cpp
  27. 8
      Sources/Plasma/FeatureLib/pfPython/pyVaultNodeRefGlue.cpp
  28. 24
      Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerInfoListNode.cpp
  29. 4
      Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerInfoListNodeGlue.cpp
  30. 4
      Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerInfoNodeGlue.cpp
  31. 10
      Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerNode.cpp
  32. 4
      Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerNodeGlue.cpp
  33. 4
      Sources/Plasma/FeatureLib/pfPython/pyVaultSDLNodeGlue.cpp
  34. 4
      Sources/Plasma/FeatureLib/pfPython/pyVaultSystemNodeGlue.cpp
  35. 2
      Sources/Plasma/FeatureLib/pfPython/pyVaultTextNoteNode.cpp
  36. 4
      Sources/Plasma/FeatureLib/pfPython/pyVaultTextNoteNodeGlue.cpp
  37. 18
      Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNt.cpp
  38. 8
      Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtInt.h
  39. 15
      Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp
  40. 14
      Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Thread.cpp
  41. 9
      Sources/Plasma/NucleusLib/pnAsyncCoreExe/pnAceCore.cpp
  42. 17
      Sources/Plasma/NucleusLib/pnNetCli/pnNcChannel.cpp
  43. 2
      Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.cpp
  44. 3
      Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.h
  45. 1
      Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt
  46. 1
      Sources/Plasma/NucleusLib/pnUtils/pnUtAllIncludes.h
  47. 180
      Sources/Plasma/NucleusLib/pnUtils/pnUtRef.h
  48. 40
      Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp
  49. 2
      Sources/Plasma/PubUtilLib/plInputCore/plSceneInputInterface.cpp
  50. 20
      Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp
  51. 12
      Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp
  52. 4
      Sources/Plasma/PubUtilLib/plNetGameLib/Intern.h
  53. 62
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp
  54. 6
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCore.cpp
  55. 35
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.cpp
  56. 37
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.cpp
  57. 34
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.cpp
  58. 23
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglTrans.cpp
  59. 4
      Sources/Plasma/PubUtilLib/plNetMessage/plNetCommonMessage.h
  60. 446
      Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp
  61. 4
      Sources/Plasma/PubUtilLib/plVault/plVaultNodeAccess.cpp

2
Sources/Plasma/CoreLib/CMakeLists.txt

@ -43,7 +43,6 @@ set(CoreLib_SOURCES
hsMemory.cpp
hsQuat.cpp
hsRefCnt.cpp
hsSafeRefCnt.cpp
hsSTLStream.cpp
hsStream.cpp
hsStringTokenizer.cpp
@ -88,7 +87,6 @@ set(CoreLib_HEADERS
hsPoint2.h
hsQuat.h
hsRefCnt.h
hsSafeRefCnt.h
hsSTLStream.h
hsStream.h
hsStringTokenizer.h

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;
#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

55
Sources/Plasma/CoreLib/hsRefCnt.cpp

@ -48,20 +48,65 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
hsRefCnt::~hsRefCnt()
{
hsDebugCode(hsThrowIfFalse(fRefCnt == 1);)
#ifdef HS_DEBUGGING
hsThrowIfFalse(fRefCnt == 1);
#endif
}
void hsRefCnt::Ref()
void hsRefCnt::UnRef()
{
#ifdef HS_DEBUGGING
hsThrowIfFalse(fRefCnt >= 1);
#endif
if (fRefCnt == 1) // don't decrement if we call delete
delete this;
else
--fRefCnt;
}
hsAtomicRefCnt::~hsAtomicRefCnt()
{
fRefCnt++;
#ifdef HS_DEBUGGING
hsThrowIfFalse(fRefCnt == 1);
#endif
}
void hsRefCnt::UnRef()
void hsAtomicRefCnt::UnRef(const char* tag)
{
hsDebugCode(hsThrowIfFalse(fRefCnt >= 1);)
#ifdef HS_DEBUGGING
hsThrowIfFalse(fRefCnt >= 1);
#endif
#ifdef REFCOUNT_DEBUGGING
if (tag)
DEBUG_MSG("Dec %p %s: %u", this, tag, prev - 1);
else
DEBUG_MSG("Dec %p: %u", this, prev - 1);
#endif
if (fRefCnt == 1) // don't decrement if we call delete
delete this;
else
--fRefCnt;
}
void hsAtomicRefCnt::Ref(const char* tag)
{
#ifdef REFCOUNT_DEBUGGING
if (tag)
DEBUG_MSG("Inc %p %s: %u", this, tag, prev + 1);
else
DEBUG_MSG("Inc %p: %u", this, prev + 1);
#endif
++fRefCnt;
}
void hsAtomicRefCnt::TransferRef(const char* oldTag, const char* newTag)
{
#ifdef REFCOUNT_DEBUGGING
DEBUG_MSG("Inc %p %s: (xfer)", this, newTag);
DEBUG_MSG("Dec %p %s: (xfer)", this, oldTag);
#endif
}

31
Sources/Plasma/CoreLib/hsRefCnt.h

@ -42,16 +42,19 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#ifndef hsRefCnt_Defiend
#define hsRefCnt_Defiend
#include <atomic>
class hsRefCnt {
private:
int fRefCnt;
public:
hsRefCnt() : fRefCnt(1) {}
hsRefCnt(int initRefs = 1) : fRefCnt(initRefs) {}
virtual ~hsRefCnt();
virtual int RefCnt() const { return fRefCnt; }
virtual void UnRef();
virtual void Ref();
inline int RefCnt() const { return fRefCnt; }
void UnRef();
inline void Ref() { ++fRefCnt; }
};
#define hsRefCnt_SafeRef(obj) do { if (obj) (obj)->Ref(); } while (0)
@ -64,4 +67,24 @@ public:
dst = src; \
} while (0)
// Thread-safe version. TODO: Evaluate whether this is fast enough to
// merge with hsRefCnt above.
class hsAtomicRefCnt
{
private:
std::atomic<int> fRefCnt;
public:
hsAtomicRefCnt(int initRefs = 1) : fRefCnt(initRefs) { }
virtual ~hsAtomicRefCnt();
inline int RefCnt() const { return fRefCnt; }
void UnRef(const char* tag = nullptr);
void Ref(const char* tag = nullptr);
// Useless, but left here for debugging compatibility with AtomicRef
void TransferRef(const char* oldTag, const char* newTag);
};
#endif

44
Sources/Plasma/CoreLib/hsSafeRefCnt.cpp

@ -1,44 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#include "hsSafeRefCnt.h"
hsMutex hsSafeRefCnt::fMutex;

65
Sources/Plasma/CoreLib/hsSafeRefCnt.h

@ -1,65 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef HS_SAFE_REF_CNT_H
#define HS_SAFE_REF_CNT_H
#include "hsRefCnt.h"
#include "hsThread.h"
//
// Thread Safe RefCounter
//
class hsSafeRefCnt : public hsRefCnt
{
private:
static hsMutex fMutex;
protected:
virtual void IRef() { }
virtual void IUnRef() { };
public:
virtual int RefCnt() const { hsTempMutexLock temp(fMutex); return hsRefCnt::RefCnt(); }
void UnRef() { hsTempMutexLock temp(fMutex); IUnRef(); hsRefCnt::UnRef(); }
void Ref() { hsTempMutexLock temp(fMutex); IRef(); hsRefCnt::Ref(); }
};
#endif //HS_SAFE_REF_CNT_H

10
Sources/Plasma/FeatureLib/pfGameMgr/pfGameMgr.cpp

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

4
Sources/Plasma/FeatureLib/pfPython/cyAvatar.cpp

@ -1695,7 +1695,7 @@ void cyAvatar::ChangeAvatar(const char* genderName)
if (rvnPlr) {
VaultPlayerNode plr(rvnPlr);
plr.SetAvatarShapeName(wStr);
rvnPlr->DecRef();
rvnPlr->UnRef();
}
#endif
}
@ -1716,7 +1716,7 @@ void cyAvatar::ChangePlayerName(const char* playerName)
if (rvnPlr) {
VaultPlayerNode plr(rvnPlr);
plr.SetPlayerName(wStr);
rvnPlr->DecRef();
rvnPlr->UnRef();
}
}

4
Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp

@ -2474,7 +2474,7 @@ int cyMisc::GetKILevel()
if (RelVaultNode * rvn = VaultFindChronicleEntryIncRef(wStr)) {
VaultChronicleNode chron(rvn);
result = wcstol(chron.GetEntryValue(), nil, 0);
rvn->DecRef();
rvn->UnRef();
}
return result;
@ -2893,7 +2893,7 @@ void cyMisc::SendFriendInvite(const wchar_t email[], const wchar_t toName[])
}
NetCommSendFriendInvite(email, toName, inviteUuid);
pNode->DecRef();
pNode->UnRef();
}
}

2
Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp

@ -2082,7 +2082,7 @@ bool plPythonFileMod::MsgReceive(plMessage* msg)
Py_DECREF(ptuple);
ptuple = PyTuple_New(1);
PyTuple_SetItem(ptuple, 0, pyVaultAgeLinkNode::New(rvn));
rvn->DecRef();
rvn->UnRef();
}
}
break;

32
Sources/Plasma/FeatureLib/pfPython/pyAgeVault.cpp

@ -84,7 +84,7 @@ PyObject* pyAgeVault::GetAgeInfo()
RelVaultNode * rvn = VaultGetAgeInfoNodeIncRef();
if (rvn) {
PyObject * result = pyVaultAgeInfoNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
return result;
}
@ -97,7 +97,7 @@ PyObject* pyAgeVault::GetAgeDevicesFolder( void )
RelVaultNode * rvn = VaultGetAgeDevicesFolderIncRef();
if (rvn) {
PyObject * result = pyVaultFolderNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
return result;
}
@ -110,7 +110,7 @@ PyObject* pyAgeVault::GetSubAgesFolder( void )
RelVaultNode * rvn = VaultGetAgeSubAgesFolderIncRef();
if (rvn) {
PyObject * result = pyVaultFolderNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
return result;
}
@ -123,7 +123,7 @@ PyObject* pyAgeVault::GetChronicleFolder( void )
RelVaultNode * rvn = VaultGetAgeChronicleFolderIncRef();
if (rvn) {
PyObject * result = pyVaultFolderNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
return result;
}
@ -136,7 +136,7 @@ PyObject* pyAgeVault::GetBookshelfFolder ( void )
RelVaultNode * rvn = VaultAgeGetBookshelfFolderIncRef();
if (rvn) {
PyObject * result = pyVaultFolderNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
return result;
}
@ -149,7 +149,7 @@ PyObject* pyAgeVault::GetPeopleIKnowAboutFolder( void )
RelVaultNode * rvn = VaultGetAgePeopleIKnowAboutFolderIncRef();
if (rvn) {
PyObject * result = pyVaultFolderNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
return result;
}
@ -163,7 +163,7 @@ PyObject* pyAgeVault::GetPublicAgesFolder(void)
RelVaultNode * rvn = VaultGetAgePublicAgesFolderIncRef();
if (rvn) {
PyObject * result = pyVaultFolderNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
return result;
}
@ -176,7 +176,7 @@ PyObject* pyAgeVault::GetSubAgeLink( const pyAgeInfoStruct & info )
RelVaultNode * rvn = VaultFindAgeSubAgeLinkIncRef(info.GetAgeInfo());
if (rvn) {
PyObject * result = pyVaultAgeLinkNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
return result;
}
@ -190,7 +190,7 @@ plUUID pyAgeVault::GetAgeGuid( void )
if (rvn) {
VaultAgeInfoNode ageInfo(rvn);
plUUID uuid = ageInfo.GetAgeInstanceGuid();
rvn->DecRef();
rvn->UnRef();
return uuid;
}
return kNilUuid;
@ -206,7 +206,7 @@ PyObject* pyAgeVault::FindChronicleEntry( const char * entryName )
if (RelVaultNode * rvn = VaultFindAgeChronicleEntryIncRef(wEntryName)) {
PyObject * result = pyVaultChronicleNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
return result;
}
@ -237,7 +237,7 @@ void pyAgeVault::AddDevice( const char * deviceName, PyObject * cbObject, uint32
if (RelVaultNode * rvn = VaultAgeAddDeviceAndWaitIncRef(wStr)) {
cb->SetNode(rvn);
rvn->DecRef();
rvn->UnRef();
}
cb->VaultOperationComplete( cbContext, cb->GetNode() ? hsOK : hsFail); // cbHolder deletes itself here.
@ -268,7 +268,7 @@ PyObject * pyAgeVault::GetDevice( const char * deviceName )
if (RelVaultNode * rvn = VaultAgeGetDeviceIncRef(wStr)) {
PyObject * result = pyVaultTextNoteNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
return result;
}
@ -288,7 +288,7 @@ void pyAgeVault::SetDeviceInbox( const char * deviceName, const char * inboxName
if (RelVaultNode * rvn = VaultAgeSetDeviceInboxAndWaitIncRef(wDev, wInb)) {
cb->SetNode(rvn);
rvn->DecRef();
rvn->UnRef();
}
cb->VaultOperationComplete( cbContext, cb->GetNode() ? hsOK : hsFail ); // cbHolder deletes itself here.
@ -301,7 +301,7 @@ PyObject * pyAgeVault::GetDeviceInbox( const char * deviceName )
if (RelVaultNode * rvn = VaultAgeGetDeviceInboxIncRef(wStr)) {
PyObject * result = pyVaultTextNoteNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
return result;
}
@ -333,10 +333,10 @@ PyObject* pyAgeVault::FindNode( pyVaultNode* templateNode ) const
{
if (RelVaultNode * rvn = VaultGetAgeNodeIncRef()) {
RelVaultNode * find = rvn->GetChildNodeIncRef(templateNode->fNode, 1);
rvn->DecRef();
rvn->UnRef();
if (find) {
PyObject * result = pyVaultNode::New(find);
find->DecRef();
find->UnRef();
return result;
}
}

6
Sources/Plasma/FeatureLib/pfPython/pyDniInfoSource.cpp

@ -81,7 +81,7 @@ uint32_t pyDniInfoSource::GetAgeTime( void ) const
result = (uint32_t)utime->GetSecs();
else
result = 0;
node->DecRef();
node->UnRef();
return result;
}
@ -95,7 +95,7 @@ const char * pyDniInfoSource::GetAgeName( void ) const
VaultAgeInfoNode ageInfo(node);
fAgeName = StrDupToAnsi(ageInfo.GetAgeInstanceName());
node->DecRef();
node->UnRef();
return fAgeName;
}
@ -106,7 +106,7 @@ plUUID pyDniInfoSource::GetAgeGuid( void ) const
{
VaultAgeInfoNode ageInfo(node);
plUUID uuid = ageInfo.GetAgeInstanceGuid();
node->DecRef();
node->UnRef();
return uuid;
}

8
Sources/Plasma/FeatureLib/pfPython/pyGameScore.cpp

@ -129,7 +129,7 @@ void pyGameScore::CreateAgeScore(const plString& name, uint32_t type, int32_t po
{
uint32_t ownerId = ageInfo->GetNodeId();
pfGameScore::Create(ownerId, name, type, points, rcvr.getKey());
ageInfo->DecRef();
ageInfo->UnRef();
} else
hsAssert(false, "Age has no vault... Need to rewrite score python script?");
}
@ -145,7 +145,7 @@ void pyGameScore::CreatePlayerScore(const plString& name, uint32_t type, int32_t
{
uint32_t ownerId = node->GetNodeId();
pfGameScore::Create(ownerId, name, type, points, rcvr.getKey());
node->DecRef();
node->UnRef();
} else
hsAssert(false, "No PlayerInfo node... Need to rewrite python script?");
}
@ -161,7 +161,7 @@ void pyGameScore::FindAgeScores(const plString& name, pyKey& rcvr)
{
uint32_t ownerId = ageInfo->GetNodeId();
pfGameScore::Find(ownerId, name, rcvr.getKey());
ageInfo->DecRef();
ageInfo->UnRef();
} else
hsAssert(false, "Age has no vault... Need to rewrite score python script?");
}
@ -177,7 +177,7 @@ void pyGameScore::FindPlayerScores(const plString& name, pyKey& rcvr)
{
uint32_t ownerId = node->GetNodeId();
pfGameScore::Find(ownerId, name, rcvr.getKey());
node->DecRef();
node->UnRef();
}
else
hsAssert(false, "No PlayerInfo node.. Need to rewrite python script?");

70
Sources/Plasma/FeatureLib/pfPython/pyVault.cpp

@ -84,9 +84,9 @@ static PyObject * GetFolder (unsigned folderType) {
if (RelVaultNode * rvnPlr = VaultGetPlayerNodeIncRef()) {
if (RelVaultNode * rvnFldr = rvnPlr->GetChildFolderNodeIncRef(folderType, 1)) {
result = pyVaultFolderNode::New(rvnFldr);
rvnFldr->DecRef();
rvnFldr->UnRef();
}
rvnPlr->DecRef();
rvnPlr->UnRef();
}
return result;
@ -98,9 +98,9 @@ static PyObject * GetPlayerInfoList (unsigned folderType) {
if (RelVaultNode * rvnPlr = VaultGetPlayerNodeIncRef()) {
if (RelVaultNode * rvnFldr = rvnPlr->GetChildPlayerInfoListNodeIncRef(folderType, 1)) {
result = pyVaultPlayerInfoListNode::New(rvnFldr);
rvnFldr->DecRef();
rvnFldr->UnRef();
}
rvnPlr->DecRef();
rvnPlr->UnRef();
}
return result;
@ -112,9 +112,9 @@ static PyObject * GetAgeInfoList (unsigned folderType) {
if (RelVaultNode * rvnPlr = VaultGetPlayerNodeIncRef()) {
if (RelVaultNode * rvnFldr = rvnPlr->GetChildAgeInfoListNodeIncRef(folderType, 1)) {
result = pyVaultAgeInfoListNode::New(rvnFldr);
rvnFldr->DecRef();
rvnFldr->UnRef();
}
rvnPlr->DecRef();
rvnPlr->UnRef();
}
return result;
@ -127,9 +127,9 @@ PyObject* pyVault::GetPlayerInfo()
if (RelVaultNode * rvnPlr = VaultGetPlayerNodeIncRef()) {
if (RelVaultNode * rvnPlrInfo = rvnPlr->GetChildNodeIncRef(plVault::kNodeType_PlayerInfo, 1)) {
result = pyVaultPlayerInfoNode::New(rvnPlrInfo);
rvnPlrInfo->DecRef();
rvnPlrInfo->UnRef();
}
rvnPlr->DecRef();
rvnPlr->UnRef();
}
// just return an empty node
@ -231,13 +231,13 @@ PyObject* pyVault::GetKIUsage(void)
++notes;
else if (rvn->GetNodeType() == plVault::kNodeType_MarkerGame)
++markerGames;
rvn->DecRef();
rvn->UnRef();
}
rvnAgeJrnlz->DecRef();
rvnAgeJrnlz->UnRef();
break;
}
rvnPlr->DecRef();
rvnPlr->UnRef();
break;
}
@ -305,7 +305,7 @@ PyObject* pyVault::GetLinkToMyNeighborhood() const
if (RelVaultNode * rvn = VaultGetOwnedAgeLinkIncRef(&info)) {
PyObject * result = pyVaultAgeLinkNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
return result;
}
@ -319,7 +319,7 @@ PyObject* pyVault::GetLinkToCity() const
if (RelVaultNode * rvn = VaultGetOwnedAgeLinkIncRef(&info)) {
PyObject * result = pyVaultAgeLinkNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
return result;
}
@ -332,7 +332,7 @@ PyObject* pyVault::GetOwnedAgeLink( const pyAgeInfoStruct & info )
{
if (RelVaultNode * rvnLink = VaultGetOwnedAgeLinkIncRef(info.GetAgeInfo())) {
PyObject * result = pyVaultAgeLinkNode::New(rvnLink);
rvnLink->DecRef();
rvnLink->UnRef();
return result;
}
@ -345,7 +345,7 @@ PyObject* pyVault::GetVisitAgeLink( const pyAgeInfoStruct & info)
{
if (RelVaultNode * rvnLink = VaultGetVisitAgeLinkIncRef(info.GetAgeInfo())) {
PyObject * result = pyVaultAgeLinkNode::New(rvnLink);
rvnLink->DecRef();
rvnLink->UnRef();
return result;
}
@ -363,7 +363,7 @@ PyObject* pyVault::FindChronicleEntry( const char * entryName )
if (RelVaultNode * rvn = VaultFindChronicleEntryIncRef(wEntryName)) {
PyObject * result = pyVaultChronicleNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
return result;
}
@ -442,7 +442,7 @@ PyObject* pyVault::GetPsnlAgeSDL() const
{
PyObject * result = nil;
NetVaultNode * templateNode = new NetVaultNode;
templateNode->IncRef();
templateNode->Ref();
if (RelVaultNode * rvnFldr = VaultGetAgesIOwnFolderIncRef()) {
@ -465,14 +465,14 @@ PyObject* pyVault::GetPsnlAgeSDL() const
result = pySDLStateDataRecord::New(rec);
else
delete rec;
rvnSdl->DecRef();
rvnSdl->UnRef();
}
rvnInfo->DecRef();
rvnInfo->UnRef();
}
rvnFldr->DecRef();
rvnFldr->UnRef();
}
templateNode->DecRef();
templateNode->UnRef();
if (!result)
PYTHON_RETURN_NONE;
@ -487,7 +487,7 @@ void pyVault::UpdatePsnlAgeSDL( pySDLStateDataRecord & pyrec )
return;
NetVaultNode * templateNode = new NetVaultNode;
templateNode->IncRef();
templateNode->Ref();
if (RelVaultNode * rvnFldr = VaultGetAgesIOwnFolderIncRef()) {
@ -506,14 +506,14 @@ void pyVault::UpdatePsnlAgeSDL( pySDLStateDataRecord & pyrec )
if (RelVaultNode * rvnSdl = rvnInfo->GetChildNodeIncRef(templateNode, 1)) {
VaultSDLNode sdl(rvnSdl);
sdl.SetStateDataRecord(rec, plSDL::kDirtyOnly | plSDL::kTimeStampOnRead);
rvnSdl->DecRef();
rvnSdl->UnRef();
}
rvnInfo->DecRef();
rvnInfo->UnRef();
}
rvnFldr->DecRef();
rvnFldr->UnRef();
}
templateNode->DecRef();
templateNode->UnRef();
}
bool pyVault::InMyPersonalAge() const
@ -600,13 +600,13 @@ void _InvitePlayerToAge(ENetError result, void* state, void* param, RelVaultNode
void pyVault::InvitePlayerToAge( const pyAgeLinkStruct & link, uint32_t playerID )
{
NetVaultNode * templateNode = new NetVaultNode;
templateNode->IncRef();
templateNode->Ref();
templateNode->SetNodeType(plVault::kNodeType_TextNote);
VaultTextNoteNode visitAcc(templateNode);
visitAcc.SetNoteType(plVault::kNoteType_Visit);
visitAcc.SetVisitInfo(*link.GetAgeLink()->GetAgeInfo());
VaultCreateNode(templateNode, (FVaultCreateNodeCallback)_InvitePlayerToAge, nil, (void*)playerID);
templateNode->DecRef();
templateNode->UnRef();
}
//============================================================================
@ -626,20 +626,20 @@ void pyVault::UnInvitePlayerToAge( const char * str, uint32_t playerID )
if (RelVaultNode * rvnInfo = rvnLink->GetChildNodeIncRef(plVault::kNodeType_AgeInfo, 1)) {
VaultAgeInfoNode ageInfo(rvnInfo);
ageInfo.CopyTo(&info);
rvnInfo->DecRef();
rvnInfo->UnRef();
}
rvnLink->DecRef();
rvnLink->UnRef();
}
NetVaultNode * templateNode = new NetVaultNode;
templateNode->IncRef();
templateNode->Ref();
templateNode->SetNodeType(plVault::kNodeType_TextNote);
VaultTextNoteNode visitAcc(templateNode);
visitAcc.SetNoteType(plVault::kNoteType_UnVisit);
visitAcc.SetVisitInfo(info);
VaultCreateNode(templateNode, (FVaultCreateNodeCallback)_UninvitePlayerToAge, nil, (void*)playerID);
templateNode->DecRef();
templateNode->UnRef();
}
//============================================================================
@ -699,7 +699,7 @@ PyObject* pyVault::GetGlobalInbox()
PyObject * result = nil;
if (RelVaultNode * rvnGlobalInbox = VaultGetGlobalInboxIncRef()) {
result = pyVaultFolderNode::New(rvnGlobalInbox);
rvnGlobalInbox->DecRef();
rvnGlobalInbox->UnRef();
return result;
}
@ -714,7 +714,7 @@ PyObject* pyVault::FindNode( pyVaultNode* templateNode ) const
// See if we already have a matching node locally
if (RelVaultNode * rvn = VaultGetNodeIncRef(templateNode->GetNode())) {
PyObject * result = pyVaultNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
return result;
}
@ -728,7 +728,7 @@ PyObject* pyVault::FindNode( pyVaultNode* templateNode ) const
// If we fetched it successfully then it'll be in our local node cache now
if (RelVaultNode * rvn = VaultGetNodeIncRef(nodeIds[0])) {
PyObject * result = pyVaultNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
return result;
}
}

4
Sources/Plasma/FeatureLib/pfPython/pyVaultAgeInfoListNodeGlue.cpp

@ -112,10 +112,10 @@ PyObject *pyVaultAgeInfoListNode::New(RelVaultNode* nfsNode)
{
ptVaultAgeInfoListNode *newObj = (ptVaultAgeInfoListNode*)ptVaultAgeInfoListNode_type.tp_new(&ptVaultAgeInfoListNode_type, NULL, NULL);
if (newObj->fThis->fNode)
newObj->fThis->fNode->DecRef();
newObj->fThis->fNode->UnRef();
newObj->fThis->fNode = nfsNode;
if (newObj->fThis->fNode)
newObj->fThis->fNode->IncRef();
newObj->fThis->fNode->Ref();
return (PyObject*)newObj;
}

8
Sources/Plasma/FeatureLib/pfPython/pyVaultAgeInfoNode.cpp

@ -80,7 +80,7 @@ static PyObject * GetChildFolder (RelVaultNode * node, unsigned type) {
PyObject * result = nil;
if (RelVaultNode * rvn = node->GetChildFolderNodeIncRef(type, 1)) {
result = pyVaultFolderNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
}
return result;
}
@ -91,7 +91,7 @@ static PyObject * GetChildPlayerInfoList (RelVaultNode * node, unsigned type) {
PyObject * result = nil;
if (RelVaultNode * rvn = node->GetChildPlayerInfoListNodeIncRef(type, 1)) {
result = pyVaultPlayerInfoListNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
}
return result;
}
@ -101,7 +101,7 @@ static PyObject * GetChildAgeInfoList (RelVaultNode * node, unsigned type) {
PyObject * result = nil;
if (RelVaultNode * rvn = node->GetChildAgeInfoListNodeIncRef(type, 1)) {
result = pyVaultAgeInfoListNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
}
return result;
}
@ -175,7 +175,7 @@ PyObject * pyVaultAgeInfoNode::GetParentAgeLink () const
if (RelVaultNode * rvn = fNode->GetParentAgeLinkIncRef()) {
PyObject * result = pyVaultAgeLinkNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
return result;
}

4
Sources/Plasma/FeatureLib/pfPython/pyVaultAgeInfoNodeGlue.cpp

@ -288,10 +288,10 @@ PyObject *pyVaultAgeInfoNode::New(RelVaultNode* nfsNode)
{
ptVaultAgeInfoNode *newObj = (ptVaultAgeInfoNode*)ptVaultAgeInfoNode_type.tp_new(&ptVaultAgeInfoNode_type, NULL, NULL);
if (newObj->fThis->fNode)
newObj->fThis->fNode->DecRef();
newObj->fThis->fNode->UnRef();
newObj->fThis->fNode = nfsNode;
if (newObj->fThis->fNode)
newObj->fThis->fNode->IncRef();
newObj->fThis->fNode->Ref();
return (PyObject*)newObj;
}

2
Sources/Plasma/FeatureLib/pfPython/pyVaultAgeLinkNode.cpp

@ -84,7 +84,7 @@ PyObject* pyVaultAgeLinkNode::GetAgeInfo() const
PyObject * result = nil;
if (RelVaultNode * rvn = fNode->GetChildNodeIncRef(plVault::kNodeType_AgeInfo, 1)) {
result = pyVaultAgeInfoNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
}
if (result)

4
Sources/Plasma/FeatureLib/pfPython/pyVaultAgeLinkNodeGlue.cpp

@ -201,10 +201,10 @@ PyObject *pyVaultAgeLinkNode::New(RelVaultNode* nfsNode)
{
ptVaultAgeLinkNode *newObj = (ptVaultAgeLinkNode*)ptVaultAgeLinkNode_type.tp_new(&ptVaultAgeLinkNode_type, NULL, NULL);
if (newObj->fThis->fNode)
newObj->fThis->fNode->DecRef();
newObj->fThis->fNode->UnRef();
newObj->fThis->fNode = nfsNode;
if (newObj->fThis->fNode)
newObj->fThis->fNode->IncRef();
newObj->fThis->fNode->Ref();
return (PyObject*)newObj;
}

4
Sources/Plasma/FeatureLib/pfPython/pyVaultChronicleNodeGlue.cpp

@ -191,10 +191,10 @@ PyObject *pyVaultChronicleNode::New(RelVaultNode* nfsNode)
{
ptVaultChronicleNode *newObj = (ptVaultChronicleNode*)ptVaultChronicleNode_type.tp_new(&ptVaultChronicleNode_type, NULL, NULL);
if (newObj->fThis->fNode)
newObj->fThis->fNode->DecRef();
newObj->fThis->fNode->UnRef();
newObj->fThis->fNode = nfsNode;
if (newObj->fThis->fNode)
newObj->fThis->fNode->IncRef();
newObj->fThis->fNode->Ref();
return (PyObject*)newObj;
}

4
Sources/Plasma/FeatureLib/pfPython/pyVaultFolderNodeGlue.cpp

@ -192,10 +192,10 @@ PyObject *pyVaultFolderNode::New(RelVaultNode* nfsNode)
{
ptVaultFolderNode *newObj = (ptVaultFolderNode*)ptVaultFolderNode_type.tp_new(&ptVaultFolderNode_type, NULL, NULL);
if (newObj->fThis->fNode)
newObj->fThis->fNode->DecRef();
newObj->fThis->fNode->UnRef();
newObj->fThis->fNode = nfsNode;
if (newObj->fThis->fNode)
newObj->fThis->fNode->IncRef();
newObj->fThis->fNode->Ref();
return (PyObject*)newObj;
}

4
Sources/Plasma/FeatureLib/pfPython/pyVaultImageNodeGlue.cpp

@ -220,10 +220,10 @@ PyObject *pyVaultImageNode::New(RelVaultNode* nfsNode)
{
ptVaultImageNode *newObj = (ptVaultImageNode*)ptVaultImageNode_type.tp_new(&ptVaultImageNode_type, NULL, NULL);
if (newObj->fThis->fNode)
newObj->fThis->fNode->DecRef();
newObj->fThis->fNode->UnRef();
newObj->fThis->fNode = nfsNode;
if (newObj->fThis->fNode)
newObj->fThis->fNode->IncRef();
newObj->fThis->fNode->Ref();
return (PyObject*)newObj;
}

4
Sources/Plasma/FeatureLib/pfPython/pyVaultMarkerGameNodeGlue.cpp

@ -115,10 +115,10 @@ PyObject *pyVaultMarkerGameNode::New(RelVaultNode* nfsNode)
{
ptVaultMarkerGameNode *newObj = (ptVaultMarkerGameNode*)ptVaultMarkerGameNode_type.tp_new(&ptVaultMarkerGameNode_type, NULL, NULL);
if (newObj->fThis->fNode)
newObj->fThis->fNode->DecRef();
newObj->fThis->fNode->UnRef();
newObj->fThis->fNode = nfsNode;
if (newObj->fThis->fNode)
newObj->fThis->fNode->IncRef();
newObj->fThis->fNode->Ref();
return (PyObject*)newObj;
}

42
Sources/Plasma/FeatureLib/pfPython/pyVaultNode.cpp

@ -159,10 +159,10 @@ void pyVaultNode::pyVaultNodeOperationCallback::VaultOperationComplete( uint32_t
void pyVaultNode::pyVaultNodeOperationCallback::SetNode (RelVaultNode * rvn) {
if (rvn)
rvn->IncRef();
rvn->Ref();
SWAP(rvn, fNode);
if (rvn)
rvn->DecRef();
rvn->UnRef();
}
RelVaultNode * pyVaultNode::pyVaultNodeOperationCallback::GetNode () {
@ -182,13 +182,13 @@ pyVaultNode::pyVaultNode( RelVaultNode* nfsNode )
, fCreateAgeName(nil)
{
if (fNode)
fNode->IncRef("pyVaultNode");
fNode->Ref("pyVaultNode");
}
pyVaultNode::~pyVaultNode()
{
if (fNode)
fNode->DecRef("pyVaultNode");
fNode->UnRef("pyVaultNode");
free(fCreateAgeName);
}
@ -271,16 +271,16 @@ PyObject* pyVaultNode::GetCreatorNode( void )
if (fNode)
{
RelVaultNode * templateNode = new RelVaultNode;
templateNode->IncRef();
templateNode->Ref();
templateNode->SetNodeType(plVault::kNodeType_PlayerInfo);
VaultPlayerInfoNode plrInfo(templateNode);
plrInfo.SetPlayerId(fNode->GetCreatorId());
if (RelVaultNode * rvn = VaultGetNodeIncRef(templateNode)) {
result = pyVaultPlayerInfoNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
}
templateNode->DecRef();
templateNode->UnRef();
}
if (result)
@ -423,8 +423,8 @@ PyObject* pyVaultNode::AddNode(pyVaultNode* pynode, PyObject* cbObject, uint32_t
);
if (newNode) {
newNode->IncRef();
pynode->fNode->DecRef();
newNode->Ref();
pynode->fNode->UnRef();
pynode->fNode = newNode;
}
else {
@ -471,7 +471,7 @@ void pyVaultNode::LinkToNode(int nodeID, PyObject* cbObject, uint32_t cbContext)
if (RelVaultNode * rvn = VaultGetNodeIncRef(nodeID)) {
cb->SetNode(rvn);
cb->fPyNodeRef = pyVaultNodeRef::New(fNode, rvn);
rvn->DecRef();
rvn->UnRef();
}
VaultAddChildNode(fNode->GetNodeId(),
@ -536,7 +536,7 @@ void pyVaultNode::Save(PyObject* cbObject, uint32_t cbContext)
if (!fNode->GetNodeId() && fNode->GetNodeType()) {
ENetError result;
if (RelVaultNode * node = VaultCreateNodeAndWaitIncRef(fNode, &result)) {
fNode->DecRef();
fNode->UnRef();
fNode = node;
}
}
@ -560,7 +560,7 @@ void pyVaultNode::ForceSave()
if (!fNode->GetNodeId() && fNode->GetNodeType()) {
ENetError result;
if (RelVaultNode * node = VaultCreateNodeAndWaitIncRef(fNode, &result)) {
fNode->DecRef();
fNode->UnRef();
fNode = node;
}
}
@ -579,7 +579,7 @@ void pyVaultNode::SendTo(uint32_t destClientNodeID, PyObject* cbObject, uint32_t
if (!fNode->GetNodeId() && fNode->GetNodeType()) {
ENetError result;
if (RelVaultNode * node = VaultCreateNodeAndWaitIncRef(fNode, &result)) {
fNode->DecRef();
fNode->UnRef();
fNode = node;
}
}
@ -618,7 +618,7 @@ PyObject* pyVaultNode::GetChildNodeRefList()
PyObject* elementObj = pyVaultNodeRef::New(fNode, nodes[i]);
PyList_Append(pyEL, elementObj);
Py_DECREF(elementObj);
nodes[i]->DecRef();
nodes[i]->UnRef();
}
}
@ -657,13 +657,13 @@ PyObject * pyVaultNode::GetNode2( uint32_t nodeID ) const
if ( fNode )
{
RelVaultNode * templateNode = new RelVaultNode;
templateNode->IncRef();
templateNode->Ref();
templateNode->SetNodeId(nodeID);
if (RelVaultNode * rvn = fNode->GetChildNodeIncRef(templateNode, 1)) {
result = pyVaultNodeRef::New(fNode, rvn);
rvn->DecRef();
rvn->UnRef();
}
templateNode->DecRef();
templateNode->UnRef();
}
if (result)
@ -679,7 +679,7 @@ PyObject* pyVaultNode::FindNode( pyVaultNode * templateNode )
{
if (RelVaultNode * rvn = fNode->GetChildNodeIncRef(templateNode->fNode, 1)) {
result = pyVaultNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
}
}
@ -695,14 +695,14 @@ PyObject * pyVaultNode::GetChildNode (unsigned nodeId) {
PYTHON_RETURN_NONE;
RelVaultNode * templateNode = new RelVaultNode;
templateNode->IncRef();
templateNode->Ref();
templateNode->SetNodeId(nodeId);
RelVaultNode * rvn = fNode->GetChildNodeIncRef(templateNode, 1);
templateNode->DecRef();
templateNode->UnRef();
if (rvn) {
PyObject * result = pyVaultNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
return result;
}

4
Sources/Plasma/FeatureLib/pfPython/pyVaultNodeGlue.cpp

@ -542,10 +542,10 @@ PyObject *pyVaultNode::New(RelVaultNode* nfsNode)
{
ptVaultNode *newObj = (ptVaultNode*)ptVaultNode_type.tp_new(&ptVaultNode_type, NULL, NULL);
if (newObj->fThis->fNode)
newObj->fThis->fNode->DecRef();
newObj->fThis->fNode->UnRef();
newObj->fThis->fNode = nfsNode;
if (newObj->fThis->fNode)
newObj->fThis->fNode->IncRef();
newObj->fThis->fNode->Ref();
return (PyObject*)newObj;
}

18
Sources/Plasma/FeatureLib/pfPython/pyVaultNodeRef.cpp

@ -65,8 +65,8 @@ pyVaultNodeRef::pyVaultNodeRef(RelVaultNode * parent, RelVaultNode * child)
: fParent(parent)
, fChild(child)
{
fParent->IncRef();
fChild->IncRef();
fParent->Ref();
fChild->Ref();
}
pyVaultNodeRef::pyVaultNodeRef(int)
@ -78,9 +78,9 @@ pyVaultNodeRef::pyVaultNodeRef(int)
pyVaultNodeRef::~pyVaultNodeRef()
{
if (fParent)
fParent->DecRef();
fParent->UnRef();
if (fChild)
fChild->DecRef();
fChild->UnRef();
}
@ -115,7 +115,7 @@ unsigned pyVaultNodeRef::GetSaverID () {
unsigned saverId = 0;
if (RelVaultNode * child = VaultGetNodeIncRef(fChild->GetNodeId())) {
saverId = child->GetRefOwnerId(fParent->GetNodeId());
child->DecRef();
child->UnRef();
}
return saverId;
}
@ -129,7 +129,7 @@ PyObject * pyVaultNodeRef::GetSaver () {
if (unsigned saverId = child->GetRefOwnerId(fParent->GetNodeId())) {
// Find the player info node representing the saver
NetVaultNode * templateNode = new NetVaultNode;
templateNode->IncRef();
templateNode->Ref();
templateNode->SetNodeType(plVault::kNodeType_PlayerInfo);
VaultPlayerInfoNode access(templateNode);
access.SetPlayerId(saverId);
@ -144,15 +144,15 @@ PyObject * pyVaultNodeRef::GetSaver () {
}
}
templateNode->DecRef();
templateNode->UnRef();
}
child->DecRef();
child->UnRef();
}
if (!saver)
PYTHON_RETURN_NONE;
PyObject * result = pyVaultPlayerInfoNode::New(saver);
saver->DecRef();
saver->UnRef();
return result;
}

8
Sources/Plasma/FeatureLib/pfPython/pyVaultNodeRefGlue.cpp

@ -126,15 +126,15 @@ PyObject *pyVaultNodeRef::New(RelVaultNode * parent, RelVaultNode * child)
{
ptVaultNodeRef *newObj = (ptVaultNodeRef*)ptVaultNodeRef_type.tp_new(&ptVaultNodeRef_type, NULL, NULL);
if (newObj->fThis->fParent)
newObj->fThis->fParent->DecRef();
newObj->fThis->fParent->UnRef();
if (newObj->fThis->fChild)
newObj->fThis->fChild->DecRef();
newObj->fThis->fChild->UnRef();
newObj->fThis->fParent = parent;
newObj->fThis->fChild = child;
if (newObj->fThis->fParent)
newObj->fThis->fParent->IncRef();
newObj->fThis->fParent->Ref();
if (newObj->fThis->fChild)
newObj->fThis->fChild->IncRef();
newObj->fThis->fChild->Ref();
return (PyObject*)newObj;
}

24
Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerInfoListNode.cpp

@ -80,16 +80,16 @@ bool pyVaultPlayerInfoListNode::HasPlayer( uint32_t playerID )
return false;
NetVaultNode * templateNode = new NetVaultNode;
templateNode->IncRef();
templateNode->Ref();
templateNode->SetNodeType(plVault::kNodeType_PlayerInfo);
VaultPlayerInfoNode access(templateNode);
access.SetPlayerId(playerID);
RelVaultNode * rvn = fNode->GetChildNodeIncRef(templateNode, 1);
if (rvn)
rvn->DecRef();
rvn->UnRef();
templateNode->DecRef();
templateNode->UnRef();
return (rvn != nil);
}
@ -100,7 +100,7 @@ static void IAddPlayer_NodesFound(ENetError result, void* param, unsigned nodeId
NetVaultNode* parent = static_cast<NetVaultNode*>(param);
if (nodeIdCount)
VaultAddChildNode(parent->GetNodeId(), nodeIds[0], VaultGetPlayerId(), nullptr, nullptr);
parent->DecRef();
parent->UnRef();
}
void pyVaultPlayerInfoListNode::AddPlayer( uint32_t playerID )
@ -109,7 +109,7 @@ void pyVaultPlayerInfoListNode::AddPlayer( uint32_t playerID )
return;
NetVaultNode* templateNode = new NetVaultNode();
templateNode->IncRef();
templateNode->Ref();
templateNode->SetNodeType(plVault::kNodeType_PlayerInfo);
VaultPlayerInfoNode access(templateNode);
access.SetPlayerId(playerID);
@ -121,7 +121,7 @@ void pyVaultPlayerInfoListNode::AddPlayer( uint32_t playerID )
if (nodeIds.Count())
VaultAddChildNode(fNode->GetNodeId(), nodeIds[0], VaultGetPlayerId(), nullptr, nullptr);
else {
fNode->IncRef();
fNode->Ref();
VaultFindNodes(templateNode, IAddPlayer_NodesFound, fNode);
}
}
@ -132,17 +132,17 @@ void pyVaultPlayerInfoListNode::RemovePlayer( uint32_t playerID )
return;
NetVaultNode * templateNode = new NetVaultNode;
templateNode->IncRef();
templateNode->Ref();
templateNode->SetNodeType(plVault::kNodeType_PlayerInfo);
VaultPlayerInfoNode access(templateNode);
access.SetPlayerId(playerID);
if (RelVaultNode * rvn = fNode->GetChildNodeIncRef(templateNode, 1)) {
VaultRemoveChildNode(fNode->GetNodeId(), rvn->GetNodeId(), nil, nil);
rvn->DecRef();
rvn->UnRef();
}
templateNode->DecRef();
templateNode->UnRef();
}
PyObject * pyVaultPlayerInfoListNode::GetPlayer( uint32_t playerID )
@ -151,7 +151,7 @@ PyObject * pyVaultPlayerInfoListNode::GetPlayer( uint32_t playerID )
PYTHON_RETURN_NONE;
NetVaultNode * templateNode = new NetVaultNode;
templateNode->IncRef();
templateNode->Ref();
templateNode->SetNodeType(plVault::kNodeType_PlayerInfo);
VaultPlayerInfoNode access(templateNode);
access.SetPlayerId(playerID);
@ -159,10 +159,10 @@ PyObject * pyVaultPlayerInfoListNode::GetPlayer( uint32_t playerID )
PyObject * result = nil;
if (RelVaultNode * rvn = fNode->GetChildNodeIncRef(templateNode, 1)) {
result = pyVaultPlayerInfoNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
}
templateNode->DecRef();
templateNode->UnRef();
if (!result)
PYTHON_RETURN_NONE;

4
Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerInfoListNodeGlue.cpp

@ -180,10 +180,10 @@ PyObject *pyVaultPlayerInfoListNode::New(RelVaultNode* nfsNode)
{
ptVaultPlayerInfoListNode *newObj = (ptVaultPlayerInfoListNode*)ptVaultPlayerInfoListNode_type.tp_new(&ptVaultPlayerInfoListNode_type, NULL, NULL);
if (newObj->fThis->fNode)
newObj->fThis->fNode->DecRef();
newObj->fThis->fNode->UnRef();
newObj->fThis->fNode = nfsNode;
if (newObj->fThis->fNode)
newObj->fThis->fNode->IncRef();
newObj->fThis->fNode->Ref();
return (PyObject*)newObj;
}

4
Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerInfoNodeGlue.cpp

@ -172,10 +172,10 @@ PyObject *pyVaultPlayerInfoNode::New(RelVaultNode* nfsNode)
{
ptVaultPlayerInfoNode *newObj = (ptVaultPlayerInfoNode*)ptVaultPlayerInfoNode_type.tp_new(&ptVaultPlayerInfoNode_type, NULL, NULL);
if (newObj->fThis->fNode)
newObj->fThis->fNode->DecRef();
newObj->fThis->fNode->UnRef();
newObj->fThis->fNode = nfsNode;
if (newObj->fThis->fNode)
newObj->fThis->fNode->IncRef();
newObj->fThis->fNode->Ref();
return (PyObject*)newObj;
}

10
Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerNode.cpp

@ -68,9 +68,9 @@ static PyObject * GetPlayerVaultFolder (unsigned folderType) {
if (RelVaultNode * rvnPlr = VaultGetPlayerNodeIncRef()) {
if (RelVaultNode * rvnFldr = rvnPlr->GetChildFolderNodeIncRef(folderType, 1)) {
result = pyVaultFolderNode::New(rvnFldr);
rvnFldr->DecRef();
rvnFldr->UnRef();
}
rvnPlr->DecRef();
rvnPlr->UnRef();
}
return result;
@ -174,7 +174,7 @@ PyObject *pyVaultPlayerNode::GetPlayerInfo()
{
if (RelVaultNode * rvn = VaultGetPlayerInfoNodeIncRef()) {
PyObject * result = pyVaultPlayerInfoNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
return result;
}
@ -223,7 +223,7 @@ PyObject *pyVaultPlayerNode::GetVisitAgeLink(const pyAgeInfoStruct *info)
{
if (RelVaultNode * rvn = VaultGetVisitAgeLinkIncRef(info->GetAgeInfo())) {
PyObject * result = pyVaultAgeLinkNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
return result;
}
@ -244,7 +244,7 @@ PyObject *pyVaultPlayerNode::FindChronicleEntry(const char *entryName)
StrToUnicode(wStr, entryName, arrsize(wStr));
if (RelVaultNode * rvn = VaultFindChronicleEntryIncRef(wStr)) {
PyObject * result = pyVaultChronicleNode::New(rvn);
rvn->DecRef();
rvn->UnRef();
return result;
}

4
Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerNodeGlue.cpp

@ -322,10 +322,10 @@ PyObject *pyVaultPlayerNode::New(RelVaultNode* nfsNode)
{
ptVaultPlayerNode *newObj = (ptVaultPlayerNode*)ptVaultPlayerNode_type.tp_new(&ptVaultPlayerNode_type, NULL, NULL);
if (newObj->fThis->fNode)
newObj->fThis->fNode->DecRef();
newObj->fThis->fNode->UnRef();
newObj->fThis->fNode = nfsNode;
if (newObj->fThis->fNode)
newObj->fThis->fNode->IncRef();
newObj->fThis->fNode->Ref();
return (PyObject*)newObj;
}

4
Sources/Plasma/FeatureLib/pfPython/pyVaultSDLNodeGlue.cpp

@ -130,10 +130,10 @@ PyObject *pyVaultSDLNode::New(RelVaultNode* nfsNode)
{
ptVaultSDLNode *newObj = (ptVaultSDLNode*)ptVaultSDLNode_type.tp_new(&ptVaultSDLNode_type, NULL, NULL);
if (newObj->fThis->fNode)
newObj->fThis->fNode->DecRef();
newObj->fThis->fNode->UnRef();
newObj->fThis->fNode = nfsNode;
if (newObj->fThis->fNode)
newObj->fThis->fNode->IncRef();
newObj->fThis->fNode->Ref();
return (PyObject*)newObj;
}

4
Sources/Plasma/FeatureLib/pfPython/pyVaultSystemNodeGlue.cpp

@ -71,10 +71,10 @@ PyObject *pyVaultSystemNode::New(RelVaultNode* nfsNode)
{
ptVaultSystemNode *newObj = (ptVaultSystemNode*)ptVaultSystemNode_type.tp_new(&ptVaultSystemNode_type, NULL, NULL);
if (newObj->fThis->fNode)
newObj->fThis->fNode->DecRef();
newObj->fThis->fNode->UnRef();
newObj->fThis->fNode = nfsNode;
if (newObj->fThis->fNode)
newObj->fThis->fNode->IncRef();
newObj->fThis->fNode->Ref();
return (PyObject*)newObj;
}

2
Sources/Plasma/FeatureLib/pfPython/pyVaultTextNoteNode.cpp

@ -230,7 +230,7 @@ void pyVaultTextNoteNode::SetDeviceInbox( const char * devName, PyObject * cbObj
if (RelVaultNode * rvn = VaultAgeSetDeviceInboxAndWaitIncRef(wDev, DEFAULT_DEVICE_INBOX)) {
cb->SetNode(rvn);
rvn->DecRef();
rvn->UnRef();
}
cb->VaultOperationComplete( cbContext, cb->GetNode() ? hsOK : hsFail ); // cbHolder deletes itself here.

4
Sources/Plasma/FeatureLib/pfPython/pyVaultTextNoteNodeGlue.cpp

@ -319,10 +319,10 @@ PyObject *pyVaultTextNoteNode::New(RelVaultNode* nfsNode)
{
ptVaultTextNoteNode *newObj = (ptVaultTextNoteNode*)ptVaultTextNoteNode_type.tp_new(&ptVaultTextNoteNode_type, NULL, NULL);
if (newObj->fThis->fNode)
newObj->fThis->fNode->DecRef();
newObj->fThis->fNode->UnRef();
newObj->fThis->fNode = nfsNode;
if (newObj->fThis->fNode)
newObj->fThis->fNode->IncRef();
newObj->fThis->fNode->Ref();
return (PyObject*)newObj;
}

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

@ -80,7 +80,6 @@ static unsigned s_pageSizeMask;
//===========================================================================
CNtWaitHandle::CNtWaitHandle () {
m_refCount = 1;
m_event = CreateEvent(
(LPSECURITY_ATTRIBUTES) nil,
true, // manual reset
@ -94,17 +93,6 @@ CNtWaitHandle::~CNtWaitHandle () {
CloseHandle(m_event);
}
//===========================================================================
void CNtWaitHandle::IncRef () {
InterlockedIncrement(&m_refCount);
}
//===========================================================================
void CNtWaitHandle::DecRef () {
if (!InterlockedDecrement(&m_refCount))
delete this;
}
//===========================================================================
bool CNtWaitHandle::WaitForObject (unsigned timeMs) const {
return WAIT_TIMEOUT != WaitForSingleObject(m_event, timeMs);
@ -189,7 +177,7 @@ static void INtOpDispatch (
// set event *after* operation is complete
if (signalComplete) {
signalComplete->SignalObject();
signalComplete->DecRef();
signalComplete->UnRef();
}
// if we just deleted the last operation then stop dispatching
@ -203,7 +191,7 @@ static void INtOpDispatch (
if (op->pending)
break;
InterlockedDecrement(&ntObj->ioCount);
--ntObj->ioCount;
}
ntObj->critsect.Leave();
@ -300,7 +288,7 @@ bool INtConnInitialize (NtObject * ntObj) {
//===========================================================================
void INtConnCompleteOperation (NtObject * ntObj) {
// are we completing the last operation for this object?
if (InterlockedDecrement(&ntObj->ioCount))
if (--ntObj->ioCount)
return;
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
#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNASYNCCOREEXE_PRIVATE_NT_PNACENTINT_H
#include "hsRefCnt.h"
namespace Nt {
@ -87,15 +88,12 @@ public:
BOOL TryEnter () { return TryEnterCriticalSection(&m_handle); }
};
class CNtWaitHandle {
long m_refCount;
class CNtWaitHandle : public hsAtomicRefCnt {
HANDLE m_event;
public:
CNtWaitHandle ();
~CNtWaitHandle ();
void IncRef ();
void DecRef ();
bool WaitForObject (unsigned timeMs) const;
void SignalObject () const;
};
@ -131,7 +129,7 @@ struct NtObject {
LISTDECL(Operation, link) opList;
long nextCompleteSequence;
long nextStartSequence;
long ioCount;
std::atomic<long> ioCount;
bool closed;
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
#include "pnAceNtInt.h"
#include <mutex>
namespace Nt {
@ -222,7 +223,7 @@ static void SocketStartAsyncRead (NtSock * sock) {
bool readResult;
sock->critsect.Enter();
if (sock->handle != INVALID_HANDLE_VALUE) {
InterlockedIncrement(&sock->ioCount);
++sock->ioCount;
readResult = ReadFile(
sock->handle,
sock->buffer + sock->bytesLeft,
@ -238,7 +239,7 @@ static void SocketStartAsyncRead (NtSock * sock) {
DWORD err = GetLastError();
if (!readResult && (err != ERROR_IO_PENDING))
InterlockedDecrement(&sock->ioCount);
--sock->ioCount;
}
//===========================================================================
@ -378,7 +379,7 @@ static NtOpSocketWrite * SocketQueueAsyncWrite (
op->write.bytesProcessed = bytes;
memcpy(op->write.buffer, data, bytes);
InterlockedIncrement(&sock->ioCount);
++sock->ioCount;
PerfAddCounter(kAsyncPerfSocketBytesWaitQueued, bytes);
return op;
@ -1022,8 +1023,8 @@ void INtSocketOpCompleteSocketRead (
|| ((sock->opRead.read.bytesProcessed + sock->bytesLeft) > sizeof(sock->buffer))
) {
#ifdef HS_DEBUGGING
static long s_once;
if (!AtomicAdd(&s_once, 1)) {
static std::once_flag s_once;
std::call_once(s_once, [sock]() {
DumpInvalidData(
"NtSockErr.log",
sizeof(sock->buffer),
@ -1034,7 +1035,7 @@ void INtSocketOpCompleteSocketRead (
sock->opRead.read.bytes,
sock->opRead.read.bytesProcessed
);
}
});
#endif // ifdef HS_DEBUGGING
LogMsg(
@ -1419,7 +1420,7 @@ bool NtSocketWrite (
op->write.bytesProcessed = bytes;
PerfAddCounter(kAsyncPerfSocketBytesWaitQueued, bytes);
InterlockedIncrement(&sock->ioCount);
++sock->ioCount;
if (op == sock->opList.Head())
result = INtSocketOpCompleteQueuedSocketWrite((NtSock *) sock, op);

14
Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Thread.cpp

@ -48,6 +48,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "../../Pch.h"
#pragma hdrstop
#include "hsRefCnt.h"
/*****************************************************************************
*
@ -55,7 +57,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*
***/
struct AsyncThreadTaskList : AtomicRef {
struct AsyncThreadTaskList : hsAtomicRefCnt {
ENetError error;
AsyncThreadTaskList ();
~AsyncThreadTaskList ();
@ -79,7 +81,7 @@ static HANDLE s_taskPort;
//===========================================================================
AsyncThreadTaskList::AsyncThreadTaskList ()
: error(kNetSuccess)
: hsAtomicRefCnt(0), error(kNetSuccess)
{
PerfAddCounter(kAsyncPerfThreadTaskListCount, 1);
}
@ -139,7 +141,7 @@ static unsigned THREADCALL ThreadTaskProc (AsyncThread * thread) {
if (task) {
task->callback(task->param, task->taskList->error);
task->taskList->DecRef("task");
task->taskList->Ref("task");
delete task;
}
}
@ -227,7 +229,7 @@ void AsyncThreadTaskSetThreadCount (unsigned threads) {
AsyncThreadTaskList * AsyncThreadTaskListCreate () {
ASSERT(s_taskPort);
AsyncThreadTaskList * taskList = new AsyncThreadTaskList;
taskList->IncRef("TaskList");
taskList->Ref("TaskList");
return taskList;
}
@ -241,7 +243,7 @@ void AsyncThreadTaskListDestroy (
ASSERT(!taskList->error);
taskList->error = error;
taskList->DecRef(); // REF:TaskList
taskList->UnRef(); // REF:TaskList
}
//===========================================================================
@ -263,7 +265,7 @@ void AsyncThreadTaskAdd (
task->callback = callback;
task->param = param;
StrCopy(task->debugStr, debugStr, arrsize(task->debugStr)); // this will be sent with the deadlock checker email if this thread exceeds time set in plServer.ini
taskList->IncRef("Task");
taskList->Ref("Task");
PostQueuedCompletionStatus(s_taskPort, 0, (DWORD) task, NULL);
}

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"
#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) {
ASSERT(id < kNumAsyncPerfCounters);
return AtomicAdd(&s_perf[id], n);
return s_perf[id].fetch_add(n);
}
//============================================================================
long PerfSubCounter (unsigned id, unsigned n) {
ASSERT(id < kNumAsyncPerfCounters);
return AtomicAdd(&s_perf[id], -(signed)n);
return s_perf[id].fetch_sub(n);
}
//============================================================================
long PerfSetCounter (unsigned id, unsigned n) {
ASSERT(id < kNumAsyncPerfCounters);
return AtomicSet(&s_perf[id], n);
return s_perf[id].exchange(n);
}

17
Sources/Plasma/NucleusLib/pnNetCli/pnNcChannel.cpp

@ -48,6 +48,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "Pch.h"
#include "hsThread.h"
#include <list>
#include "hsRefCnt.h"
#pragma hdrstop
@ -72,7 +73,9 @@ private:
hsMutex m_critsect;
};
struct NetMsgChannel : AtomicRef {
struct NetMsgChannel : hsAtomicRefCnt {
NetMsgChannel() : hsAtomicRefCnt(0) { }
uint32_t m_protocol;
bool m_server;
@ -109,7 +112,7 @@ ChannelCrit::~ChannelCrit () {
while (s_channels->size()) {
NetMsgChannel* const channel = s_channels->front();
s_channels->remove(channel);
channel->DecRef("ChannelLink");
channel->UnRef("ChannelLink");
}
delete s_channels;
@ -275,7 +278,7 @@ static NetMsgChannel* FindOrCreateChannel_CS (uint32_t protocol, bool server) {
channel->m_largestRecv = 0;
s_channels->push_back(channel);
channel->IncRef("ChannelLink");
channel->Ref("ChannelLink");
}
return channel;
@ -298,7 +301,7 @@ NetMsgChannel * NetMsgChannelLock (
s_channelCrit.Enter();
if (nil != (channel = FindChannel_CS(protocol, server))) {
*largestRecv = channel->m_largestRecv;
channel->IncRef("ChannelLock");
channel->Ref("ChannelLock");
}
else {
*largestRecv = 0;
@ -313,7 +316,7 @@ void NetMsgChannelUnlock (
) {
s_channelCrit.Enter();
{
channel->DecRef("ChannelLock");
channel->UnRef("ChannelLock");
}
s_channelCrit.Leave();
}
@ -392,7 +395,7 @@ void NetMsgProtocolRegister (
// make sure no connections have been established on this protocol, otherwise
// we'll be modifying a live data structure; NetCli's don't lock their protocol
// to operate on it once they have linked to it!
ASSERT(channel->GetRefCount() == 1);
ASSERT(channel->RefCnt() == 1);
channel->m_dh_g = dh_g;
channel->m_dh_xa = dh_xa;
@ -411,7 +414,7 @@ void NetMsgProtocolDestroy (uint32_t protocol, bool server) {
s_channelCrit.EnterSafe();
if (NetMsgChannel* channel = FindChannel_CS(protocol, server)) {
s_channels->remove(channel);
channel->DecRef("ChannelLink");
channel->UnRef("ChannelLink");
}
s_channelCrit.LeaveSafe();
}

2
Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.cpp

@ -315,7 +315,7 @@ void NetVaultNode::DeallocNodeFields () {
//============================================================================
NetVaultNode::NetVaultNode ()
: fieldFlags(0), dirtyFlags(0)
: hsAtomicRefCnt(0), fieldFlags(0), dirtyFlags(0)
, nodeId(0), createTime(0), modifyTime(0)
, createAgeName(nil), creatorId(0)
, nodeType(0)

3
Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.h

@ -51,6 +51,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNNETPROTOCOL_PRIVATE_PNNPCOMMON_H
#include "pnUUID/pnUUID.h"
#include "hsRefCnt.h"
/*****************************************************************************
@ -156,7 +157,7 @@ struct NetGameRank {
// NetVaultNode
//============================================================================
// Threaded apps: App is responsible for locking node->critsect before accessing *any* field in this struct
struct NetVaultNode : AtomicRef {
struct NetVaultNode : hsAtomicRefCnt {
enum RwOptions {
kRwDirtyOnly = 1<<0, // READ : No meaning
// WRITE: Only write fields marked dirty

1
Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt

@ -14,7 +14,6 @@ set(pnUtils_HEADERS
pnUtMisc.h
pnUtPragma.h
pnUtPriQ.h
pnUtRef.h
pnUtSort.h
pnUtStr.h
pnUtTime.h

1
Sources/Plasma/NucleusLib/pnUtils/pnUtAllIncludes.h

@ -58,7 +58,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pnUtPriQ.h"
#include "pnUtTime.h"
#include "pnUtStr.h"
#include "pnUtRef.h"
#include "pnUtCmd.h"
#include "pnUtMisc.h"
#include "pnUtCrypt.h"

180
Sources/Plasma/NucleusLib/pnUtils/pnUtRef.h

@ -1,180 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/pnUtRef.h
*
***/
#ifndef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTREF_H
#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTREF_H
/****************************************************************************
*
* AtomicRef
* Thread safe reference count
*
***/
class AtomicRef {
#ifdef HS_DEBUGGING
bool zeroed;
#endif
public:
inline AtomicRef ()
: m_ref(0)
#ifdef HS_DEBUGGING
, zeroed(false)
#endif
{}
inline void AcknowledgeZeroRef () {
#ifdef HS_DEBUGGING
zeroed = false;
#endif
}
inline long IncRef () {
#ifdef HS_DEBUGGING
ASSERT(!zeroed);
#endif
long prev = AtomicAdd(&m_ref, 1);
#ifdef REFCOUNT_DEBUGGING
DEBUG_MSG("Inc %p: %u", this, prev+1);
#endif
return prev+1;
}
inline long IncRef (const char tag[]) {
#ifdef HS_DEBUGGING
ASSERT(!zeroed);
#endif
long prev = AtomicAdd(&m_ref, 1);
#ifdef REFCOUNT_DEBUGGING
DEBUG_MSG("Inc %p %s: %u", this, tag, prev+1);
#endif
return prev+1;
}
inline long IncRef (unsigned n) {
#ifdef HS_DEBUGGING
ASSERT(!zeroed);
#endif
long prev = AtomicAdd(&m_ref, n);
#ifdef REFCOUNT_DEBUGGING
DEBUG_MSG("Inc %p: %u", this, prev+n);
#endif
return prev+n;
}
inline long IncRef (unsigned n, const char tag[]) {
#ifdef HS_DEBUGGING
ASSERT(!zeroed);
#endif
long prev = AtomicAdd(&m_ref, n);
#ifdef REFCOUNT_DEBUGGING
DEBUG_MSG("Inc %p %s: %u", this, tag, prev+n);
#endif
return prev+n;
}
inline long DecRef () {
#ifdef HS_DEBUGGING
ASSERT(!zeroed);
#endif
long prev;
if ((prev = AtomicAdd(&m_ref, -1)) == 1) {
#ifdef HS_DEBUGGING
zeroed = true;
#endif
OnZeroRef();
}
#ifdef REFCOUNT_DEBUGGING
DEBUG_MSG("Dec %p: %u", this, prev-1);
#endif
return prev-1;
}
inline long DecRef (const char tag[]) {
#ifdef HS_DEBUGGING
ASSERT(!zeroed);
#endif
long prev;
if ((prev = AtomicAdd(&m_ref, -1)) == 1) {
#ifdef HS_DEBUGGING
zeroed = true;
#endif
OnZeroRef();
}
#ifdef REFCOUNT_DEBUGGING
DEBUG_MSG("Dec %p %s: %u", this, tag, prev-1);
#endif
return prev-1;
}
inline void TransferRef (
const char oldTag[],
const char newTag[]
) {
#ifdef HS_DEBUGGING
ASSERT(!zeroed);
#endif
#ifdef REFCOUNT_DEBUGGING
DEBUG_MSG("Inc %p %s: (xfer)", this, newTag);
DEBUG_MSG("Dec %p %s: (xfer)", this, oldTag);
#endif
}
inline unsigned GetRefCount () {
return m_ref;
}
inline virtual void OnZeroRef () {
delete this;
}
protected:
inline virtual ~AtomicRef () {
ASSERT(!m_ref);
}
private:
long m_ref;
};
#endif

40
Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp

@ -831,13 +831,13 @@ bool plClothingOutfit::IReadFromVault()
delete sdlDataRec;
}
}
nodes[i]->DecRef();
nodes[i]->UnRef();
}
fSynchClients = true; // set true if the next synch should be bcast
ForceUpdate(true);
rvn->DecRef();
rvn->UnRef();
return true;
}
@ -874,7 +874,7 @@ void plClothingOutfit::WriteToVault()
SDRs.Add(appearanceStateDesc->GetStateDataRecord(0));
WriteToVault(SDRs);
rvn->DecRef();
rvn->UnRef();
}
void plClothingOutfit::WriteToVault(const ARRAY(plStateDataRecord*) & SDRs)
@ -926,28 +926,28 @@ void plClothingOutfit::WriteToVault(const ARRAY(plStateDataRecord*) & SDRs)
if (nodes.Count()) {
node = nodes[0];
nodes.DeleteUnordered(0);
node->IncRef(); // REF: Work
node->DecRef(); // REF: Find
node->Ref(); // REF: Work
node->UnRef(); // REF: Find
}
else {
RelVaultNode * templateNode = new RelVaultNode;
templateNode->SetNodeType(plVault::kNodeType_SDL);
templates.Add(templateNode);
node = templateNode;
node->IncRef(); // REF: Create
node->IncRef(); // REF: Work
node->Ref(); // REF: Create
node->Ref(); // REF: Work
}
VaultSDLNode sdl(node);
sdl.SetStateDataRecord((*arr)[i], 0);
node->DecRef(); // REF: Work
node->UnRef(); // REF: Work
}
}
// Delete any leftover nodes
for (unsigned i = 0; i < nodes.Count(); ++i) {
VaultDeleteNode(nodes[i]->GetNodeId());
nodes[i]->DecRef(); // REF: Array
nodes[i]->UnRef(); // REF: Array
}
// Create actual new nodes from their templates
@ -956,13 +956,13 @@ void plClothingOutfit::WriteToVault(const ARRAY(plStateDataRecord*) & SDRs)
if (RelVaultNode * actual = VaultCreateNodeAndWaitIncRef(templates[i], &result)) {
actuals.Add(actual);
}
templates[i]->DecRef(); // REF: Create
templates[i]->UnRef(); // REF: Create
}
// Add new nodes to outfit folder
for (unsigned i = 0; i < actuals.Count(); ++i) {
VaultAddChildNodeAndWait(rvn->GetNodeId(), actuals[i]->GetNodeId(), NetCommGetPlayer()->playerInt);
actuals[i]->DecRef(); // REF: Create
actuals[i]->UnRef(); // REF: Create
}
// Cleanup morph SDRs
@ -970,7 +970,7 @@ void plClothingOutfit::WriteToVault(const ARRAY(plStateDataRecord*) & SDRs)
delete morphs[i];
}
rvn->DecRef();
rvn->UnRef();
}
// XXX HACK. DON'T USE (this function exists for the temp console command Clothing.SwapClothTexHACK)
@ -1489,7 +1489,7 @@ bool plClothingOutfit::WriteToFile(const plFileName &filename)
hsUNIXStream S;
if (!S.Open(filename, "wb")) {
rvn->DecRef();
rvn->UnRef();
return false;
}
@ -1503,9 +1503,9 @@ bool plClothingOutfit::WriteToFile(const plFileName &filename)
S.WriteLE32(sdl.GetSDLDataLength());
if (sdl.GetSDLDataLength())
S.Write(sdl.GetSDLDataLength(), sdl.GetSDLData());
nodes[i]->DecRef();
nodes[i]->UnRef();
}
rvn->DecRef();
rvn->UnRef();
S.Close();
return true;
@ -1652,7 +1652,7 @@ void plClothingMgr::AddItemsToCloset(hsTArray<plClosetItem> &items)
plClothingSDLModifier::PutSingleItemIntoSDR(&items[i], &rec);
RelVaultNode * templateNode = new RelVaultNode;
templateNode->IncRef();
templateNode->Ref();
templateNode->SetNodeType(plVault::kNodeType_SDL);
VaultSDLNode sdl(templateNode);
@ -1669,12 +1669,12 @@ void plClothingMgr::AddItemsToCloset(hsTArray<plClosetItem> &items)
actual->GetNodeId(),
NetCommGetPlayer()->playerInt
);
actual->DecRef(); // REF: Create
actual->UnRef(); // REF: Create
}
templates[i]->DecRef(); // REF: Create
templates[i]->UnRef(); // REF: Create
}
rvn->DecRef();
rvn->UnRef();
}
void plClothingMgr::GetClosetItems(hsTArray<plClosetItem> &out)
@ -1702,7 +1702,7 @@ void plClothingMgr::GetClosetItems(hsTArray<plClosetItem> &out)
}
}
rvn->DecRef();
rvn->UnRef();
}
void plClothingMgr::GetAllWithSameMesh(plClothingItem *item, hsTArray<plClothingItem*> &out)

2
Sources/Plasma/PubUtilLib/plInputCore/plSceneInputInterface.cpp

@ -865,7 +865,7 @@ void plSceneInputInterface::ILinkOffereeToAge()
VaultRegisterOwnedAgeAndWait(&link);
}
}
linkNode->DecRef();
linkNode->UnRef();
}
if (!fSpawnPoint.IsEmpty()) {

20
Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp

@ -535,14 +535,14 @@ bool plNetLinkingMgr::IProcessVaultNotifyMsg(plVaultNotifyMsg* msg)
{
VaultAgeInfoNode accInfo(rvnInfo);
accInfo.CopyTo(cur->GetAgeInfo());
rvnInfo->DecRef();
rvnInfo->UnRef();
}
IDoLink(fDeferredLink);
fDeferredLink = nil;
return true;
cVaultLink->DecRef();
cVaultLink->UnRef();
}
return false;
@ -786,7 +786,7 @@ void plNetLinkingMgr::IPostProcessLink( void )
accInfo.SetAgeInstName(ageInstName);
accInfo.SetAgeInstUuid(ageInstGuid);
accInfo.SetOnline(true);
rvnInfo->DecRef();
rvnInfo->UnRef();
}
switch (link->GetLinkingRules()) {
@ -811,9 +811,9 @@ void plNetLinkingMgr::IPostProcessLink( void )
);
if (fldr)
fldr->DecRef();
fldr->UnRef();
if (info)
info->DecRef();
info->UnRef();
}
}
break;
@ -838,9 +838,9 @@ void plNetLinkingMgr::IPostProcessLink( void )
);
if (fldr)
fldr->DecRef();
fldr->UnRef();
if (info)
info->DecRef();
info->UnRef();
}
}
break;
@ -878,7 +878,7 @@ uint8_t plNetLinkingMgr::IPreProcessLink(void)
accInfo.SetAgeInstName(nil);
accInfo.SetAgeInstUuid(kNilUuid);
accInfo.SetOnline(false);
rvnInfo->DecRef();
rvnInfo->UnRef();
}
#else
// Update our online status
@ -890,7 +890,7 @@ uint8_t plNetLinkingMgr::IPreProcessLink(void)
accInfo.SetAgeInstName(ageInstName);
accInfo.SetAgeInstUuid(ageInstGuid);
accInfo.SetOnline(true);
rvnInfo->DecRef();
rvnInfo->UnRef();
}
#endif
@ -1035,7 +1035,7 @@ uint8_t plNetLinkingMgr::IPreProcessLink(void)
break;
}
}
linkNode->DecRef();
linkNode->UnRef();
}
}

12
Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp

@ -278,7 +278,7 @@ static void PlayerInitCallback (
if (RelVaultNode * rvn = VaultGetOwnedAgeLinkIncRef(&info)) {
VaultAgeLinkNode acc(rvn);
acc.AddSpawnPoint(plSpawnPointInfo(kCityFerryTerminalLinkTitle, kCityFerryTerminalLinkSpawnPtName));
rvn->DecRef();
rvn->UnRef();
}
VaultProcessPlayerInbox();
@ -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();
}
}
@ -1126,7 +1126,7 @@ void NetCommSetActivePlayer (//--> plNetCommActivePlayerMsg
pInfo.SetOnline(false);
NetCliAuthVaultNodeSave(rvn, nil, nil);
rvn->DecRef();
rvn->UnRef();
}
VaultCull(s_player->playerInt);
@ -1324,7 +1324,7 @@ void NetCommSetCCRLevel (
if (RelVaultNode * rvnInfo = VaultGetPlayerInfoNodeIncRef()) {
VaultPlayerInfoNode pInfo(rvnInfo);
pInfo.SetCCRLevel(ccrLevel);
rvnInfo->DecRef();
rvnInfo->UnRef();
}
NetCliAuthSetCCRLevel(ccrLevel);

4
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 long s_perfTransCount[kNumTransTypes];
static std::atomic<long> s_perfTransCount[kNumTransTypes];
namespace Auth { struct CliAuConn; }
@ -287,7 +287,7 @@ enum ENetTransState {
kTransStateComplete,
};
struct NetTrans : AtomicRef {
struct NetTrans : hsAtomicRefCnt {
LINK(NetTrans) m_link;
ENetTransState m_state;
ENetError m_result;

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

@ -57,7 +57,7 @@ namespace Ngl { namespace Auth {
*
***/
struct CliAuConn : AtomicRef {
struct CliAuConn : hsAtomicRefCnt {
CliAuConn ();
~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];
@ -1280,7 +1280,7 @@ static unsigned GetNonZeroTimeMs () {
//============================================================================
static CliAuConn * GetConnIncRef_CS (const char tag[]) {
if (CliAuConn * conn = s_active) {
conn->IncRef(tag);
conn->Ref(tag);
return conn;
}
return nil;
@ -1312,7 +1312,7 @@ static void UnlinkAndAbandonConn_CS (CliAuConn * conn) {
AsyncSocketDisconnect(conn->sock, true);
}
else {
conn->DecRef("Lifetime");
conn->UnRef("Lifetime");
}
}
@ -1369,7 +1369,7 @@ static void CheckedReconnect (CliAuConn * conn, ENetError error) {
// Cancel all transactions in progress on this connection.
NetTransCancelByConnId(conn->seq, kNetErrTimeout);
// conn is dead.
conn->DecRef("Lifetime");
conn->UnRef("Lifetime");
ReportNetError(kNetProtocolCli2Auth, error);
}
else {
@ -1405,7 +1405,7 @@ static void NotifyConnSocketConnectFailed (CliAuConn * conn) {
CheckedReconnect(conn, kNetErrConnectFailed);
conn->DecRef("Connecting");
conn->UnRef("Connecting");
}
//============================================================================
@ -1426,7 +1426,7 @@ static void NotifyConnSocketDisconnect (CliAuConn * conn) {
CheckedReconnect(conn, kNetErrDisconnected);
conn->DecRef("Connected");
conn->UnRef("Connected");
}
//============================================================================
@ -1540,7 +1540,7 @@ static void Connect (
conn->lastHeardTimeMs = GetNonZeroTimeMs(); // used in connect timeout, and ping timeout
strncpy(conn->name, name, arrsize(conn->name));
conn->IncRef("Lifetime");
conn->Ref("Lifetime");
conn->AutoReconnect();
}
@ -1571,7 +1571,7 @@ static void AsyncLookupCallback (
//===========================================================================
static unsigned CliAuConnTimerDestroyed (void * param) {
CliAuConn * conn = (CliAuConn *) param;
conn->DecRef("TimerDestroyed");
conn->UnRef("TimerDestroyed");
return kAsyncTimeInfinite;
}
@ -1589,21 +1589,21 @@ static unsigned CliAuConnPingTimerProc (void * param) {
//============================================================================
CliAuConn::CliAuConn ()
: reconnectTimer(nil), reconnectStartMs(0)
: hsAtomicRefCnt(0), reconnectTimer(nil), reconnectStartMs(0)
, pingTimer(nil), pingSendTimeMs(0), lastHeardTimeMs(0)
, sock(nil), cli(nil), seq(0), serverChallenge(0)
, cancelId(nil), abandoned(false)
{
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];
}
//===========================================================================
@ -1617,7 +1617,7 @@ void CliAuConn::TimerReconnect () {
s_critsect.Leave();
}
else {
IncRef("Connecting");
Ref("Connecting");
// Remember the time we started the reconnect attempt, guarding against
// TimeGetMs() returning zero (unlikely), as a value of zero indicates
@ -1656,7 +1656,7 @@ void CliAuConn::StartAutoReconnect () {
void CliAuConn::AutoReconnect () {
ASSERT(!reconnectTimer);
IncRef("ReconnectTimer");
Ref("ReconnectTimer");
critsect.Enter();
{
AsyncTimerCreate(
@ -1690,7 +1690,7 @@ bool CliAuConn::AutoReconnectEnabled () {
//============================================================================
void CliAuConn::AutoPing () {
ASSERT(!pingTimer);
IncRef("PingTimer");
Ref("PingTimer");
critsect.Enter();
{
AsyncTimerCreate(
@ -3941,7 +3941,7 @@ void VaultFetchNodeTrans::Post () {
m_node
);
if (m_node)
m_node->DecRef("Recv");
m_node->UnRef("Recv");
}
//============================================================================
@ -3954,7 +3954,7 @@ bool VaultFetchNodeTrans::Recv (
if (IS_NET_SUCCESS(reply.result)) {
m_node = new NetVaultNode;
m_node->Read_LCS(reply.nodeBuffer, reply.nodeBytes, 0);
m_node->IncRef("Recv");
m_node->Ref("Recv");
}
m_result = reply.result;
@ -3980,12 +3980,12 @@ VaultFindNodeTrans::VaultFindNodeTrans (
, m_param(param)
, m_node(templateNode)
{
m_node->IncRef();
m_node->Ref();
}
//============================================================================
VaultFindNodeTrans::~VaultFindNodeTrans () {
m_node->DecRef();
m_node->UnRef();
}
//============================================================================
@ -4056,7 +4056,7 @@ VaultCreateNodeTrans::VaultCreateNodeTrans (
, m_param(param)
, m_nodeId(0)
{
m_templateNode->IncRef();
m_templateNode->Ref();
}
//============================================================================
@ -4086,7 +4086,7 @@ void VaultCreateNodeTrans::Post () {
m_param,
m_nodeId
);
m_templateNode->DecRef();
m_templateNode->UnRef();
}
//============================================================================
@ -5024,7 +5024,7 @@ bool NetAuthTrans::AcquireConn () {
//============================================================================
void NetAuthTrans::ReleaseConn () {
if (m_conn) {
m_conn->DecRef("AcquireConn");
m_conn->UnRef("AcquireConn");
m_conn = nil;
}
}
@ -5399,7 +5399,7 @@ void NetCliAuthSetCCRLevel (
};
conn->Send(msg, arrsize(msg));
conn->DecRef("SetCCRLevel");
conn->UnRef("SetCCRLevel");
}
//============================================================================
@ -5433,7 +5433,7 @@ void NetCliAuthSetAgePublic (
conn->Send(msg, arrsize(msg));
conn->DecRef("SetAgePublic");
conn->UnRef("SetAgePublic");
}
//============================================================================
@ -5733,7 +5733,7 @@ void NetCliAuthVaultSetSeen (
conn->Send(msg, arrsize(msg));
conn->DecRef("SetSeen");
conn->UnRef("SetSeen");
}
//============================================================================
@ -5753,7 +5753,7 @@ void NetCliAuthVaultSendNode (
conn->Send(msg, arrsize(msg));
conn->DecRef("SendNode");
conn->UnRef("SendNode");
}
//============================================================================
@ -5817,7 +5817,7 @@ void NetCliAuthPropagateBuffer (
conn->Send(msg, arrsize(msg));
conn->DecRef("PropBuffer");
conn->UnRef("PropBuffer");
}
@ -5834,7 +5834,7 @@ void NetCliAuthLogPythonTraceback (const wchar_t traceback[]) {
conn->Send(msg, arrsize(msg));
conn->DecRef("LogTraceback");
conn->UnRef("LogTraceback");
}
@ -5851,7 +5851,7 @@ void NetCliAuthLogStackDump (const wchar_t stackdump[]) {
conn->Send(msg, arrsize(msg));
conn->DecRef("LogStackDump");
conn->UnRef("LogStackDump");
}
//============================================================================
@ -5869,7 +5869,7 @@ void NetCliAuthLogClientDebuggerConnect () {
conn->Send(msg, arrsize(msg));
conn->DecRef();
conn->UnRef();
}
//============================================================================
@ -5908,7 +5908,7 @@ void NetCliAuthKickPlayer (
};
conn->Send(msg, arrsize(msg));
conn->DecRef("KickPlayer");
conn->UnRef("KickPlayer");
}
//============================================================================

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

@ -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);

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

@ -60,7 +60,7 @@ namespace Ngl { namespace File {
*
***/
struct CliFileConn : AtomicRef {
struct CliFileConn : hsAtomicRefCnt {
LINK(CliFileConn) link;
hsReaderWriterLock sockLock; // to protect the socket pointer so we don't nuke it while using it
AsyncSocket sock;
@ -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;
@ -251,7 +251,7 @@ static unsigned GetNonZeroTimeMs () {
//============================================================================
static CliFileConn * GetConnIncRef_CS (const char tag[]) {
if (CliFileConn * conn = s_active) {
conn->IncRef(tag);
conn->Ref(tag);
return conn;
}
return nil;
@ -291,7 +291,7 @@ static void UnlinkAndAbandonConn_CS (CliFileConn * conn) {
conn->sockLock.UnlockForReading();
}
if (needsDecref) {
conn->DecRef("Lifetime");
conn->UnRef("Lifetime");
}
}
@ -346,9 +346,9 @@ static void NotifyConnSocketConnectFailed (CliFileConn * conn) {
if (s_running && conn->AutoReconnectEnabled())
conn->StartAutoReconnect();
else
conn->DecRef("Lifetime"); // if we are not reconnecting, this socket is done, so remove the lifetime ref
conn->UnRef("Lifetime"); // if we are not reconnecting, this socket is done, so remove the lifetime ref
}
conn->DecRef("Connecting");
conn->UnRef("Connecting");
}
//============================================================================
@ -424,10 +424,10 @@ static void NotifyConnSocketDisconnect (CliFileConn * conn) {
if (conn->AutoReconnectEnabled())
conn->StartAutoReconnect();
else
conn->DecRef("Lifetime"); // if we are not reconnecting, this socket is done, so remove the lifetime ref
conn->UnRef("Lifetime"); // if we are not reconnecting, this socket is done, so remove the lifetime ref
}
conn->DecRef("Connected");
conn->UnRef("Connected");
}
//============================================================================
@ -552,7 +552,7 @@ static void Connect (
conn->seq = ConnNextSequence();
conn->lastHeardTimeMs = GetNonZeroTimeMs(); // used in connect timeout, and ping timeout
conn->IncRef("Lifetime");
conn->Ref("Lifetime");
conn->AutoReconnect();
}
@ -581,13 +581,14 @@ static void AsyncLookupCallback (
//============================================================================
CliFileConn::CliFileConn ()
: sock(nil), seq(0), cancelId(nil), abandoned(false), buildId(0), serverType(0)
: hsAtomicRefCnt(0), sock(nil), seq(0), cancelId(nil), abandoned(false)
, buildId(0), serverType(0)
, reconnectTimer(nil), reconnectStartMs(0), connectStartMs(0)
, numImmediateDisconnects(0), numFailedConnects(0)
, pingTimer(nil), pingSendTimeMs(0), lastHeardTimeMs(0)
{
memset(name, 0, sizeof(name));
AtomicAdd(&s_perf[kPerfConnCount], 1);
++s_perf[kPerfConnCount];
}
//============================================================================
@ -595,7 +596,7 @@ CliFileConn::~CliFileConn () {
ASSERT(!cancelId);
ASSERT(!reconnectTimer);
Destroy();
AtomicAdd(&s_perf[kPerfConnCount], -1);
--s_perf[kPerfConnCount];
}
//===========================================================================
@ -609,7 +610,7 @@ void CliFileConn::TimerReconnect () {
s_critsect.Leave();
}
else {
IncRef("Connecting");
Ref("Connecting");
// Remember the time we started the reconnect attempt, guarding against
// TimeGetMs() returning zero (unlikely), as a value of zero indicates
@ -654,7 +655,7 @@ void CliFileConn::AutoReconnect () {
timerCritsect.Enter();
{
ASSERT(!reconnectTimer);
IncRef("ReconnectTimer");
Ref("ReconnectTimer");
AsyncTimerCreate(
&reconnectTimer,
CliFileConnTimerReconnectProc,
@ -668,7 +669,7 @@ void CliFileConn::AutoReconnect () {
//===========================================================================
static unsigned CliFileConnTimerDestroyed (void * param) {
CliFileConn * sock = (CliFileConn *) param;
sock->DecRef("TimerDestroyed");
sock->UnRef("TimerDestroyed");
return kAsyncTimeInfinite;
}
@ -693,7 +694,7 @@ static unsigned CliFileConnPingTimerProc (void * param) {
//============================================================================
void CliFileConn::AutoPing () {
ASSERT(!pingTimer);
IncRef("PingTimer");
Ref("PingTimer");
timerCritsect.Enter();
{
sockLock.LockForReading();
@ -1270,7 +1271,7 @@ bool NetFileTrans::AcquireConn () {
//============================================================================
void NetFileTrans::ReleaseConn () {
if (m_conn) {
m_conn->DecRef("AcquireConn");
m_conn->UnRef("AcquireConn");
m_conn = nil;
}
}

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

@ -55,7 +55,7 @@ namespace Ngl { namespace Game {
*
***/
struct CliGmConn : AtomicRef {
struct CliGmConn : hsAtomicRefCnt {
LINK(CliGmConn) link;
CCritSect critsect;
@ -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];
/*****************************************************************************
@ -176,7 +176,7 @@ static unsigned GetNonZeroTimeMs () {
static CliGmConn * GetConnIncRef_CS (const char tag[]) {
if (CliGmConn * conn = s_active)
if (conn->cli) {
conn->IncRef(tag);
conn->Ref(tag);
return conn;
}
return nil;
@ -205,7 +205,7 @@ static void UnlinkAndAbandonConn_CS (CliGmConn * conn) {
AsyncSocketDisconnect(conn->sock, true);
}
else {
conn->DecRef("Lifetime");
conn->UnRef("Lifetime");
}
}
@ -260,8 +260,8 @@ static void NotifyConnSocketConnectFailed (CliGmConn * conn) {
s_critsect.Leave();
NetTransCancelByConnId(conn->seq, kNetErrTimeout);
conn->DecRef("Connecting");
conn->DecRef("Lifetime");
conn->UnRef("Connecting");
conn->UnRef("Lifetime");
if (notify)
ReportNetError(kNetProtocolCli2Game, kNetErrConnectFailed);
@ -288,8 +288,8 @@ static void NotifyConnSocketDisconnect (CliGmConn * conn) {
// Cancel all transactions in process on this connection.
NetTransCancelByConnId(conn->seq, kNetErrTimeout);
conn->DecRef("Connected");
conn->DecRef("Lifetime");
conn->UnRef("Connected");
conn->UnRef("Lifetime");
if (notify)
ReportNetError(kNetProtocolCli2Game, kNetErrDisconnected);
@ -361,8 +361,8 @@ static void Connect (
conn->seq = ConnNextSequence();
conn->lastHeardTimeMs = GetNonZeroTimeMs();
conn->IncRef("Lifetime");
conn->IncRef("Connecting");
conn->Ref("Lifetime");
conn->Ref("Connecting");
s_critsect.Enter();
{
@ -403,7 +403,7 @@ static void Connect (
//===========================================================================
static unsigned CliGmConnTimerDestroyed (void * param) {
CliGmConn * conn = (CliGmConn *) param;
conn->DecRef("TimerDestroyed");
conn->UnRef("TimerDestroyed");
return kAsyncTimeInfinite;
}
@ -415,23 +415,24 @@ static unsigned CliGmConnPingTimerProc (void * param) {
//============================================================================
CliGmConn::CliGmConn ()
: sock(nil), cancelId(nil), cli(nil), seq(0), abandoned(false)
: hsAtomicRefCnt(0), sock(nil), cancelId(nil), cli(nil)
, 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];
}
//============================================================================
void CliGmConn::AutoPing () {
ASSERT(!pingTimer);
IncRef("PingTimer");
Ref("PingTimer");
critsect.Enter();
{
AsyncTimerCreate(
@ -693,7 +694,7 @@ bool NetGameTrans::AcquireConn () {
//============================================================================
void NetGameTrans::ReleaseConn () {
if (m_conn) {
m_conn->DecRef("AcquireConn");
m_conn->UnRef("AcquireConn");
m_conn = nil;
}
}
@ -860,7 +861,7 @@ void NetCliGamePropagateBuffer (
conn->Send(msg, arrsize(msg));
conn->DecRef("PropBuffer");
conn->UnRef("PropBuffer");
}
//============================================================================
@ -882,5 +883,5 @@ void NetCliGameSendGameMgrMsg (GameMsgHeader * msgHdr) {
conn->Send(msg, arrsize(msg));
conn->DecRef("GameMgrMsg");
conn->UnRef("GameMgrMsg");
}

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

@ -56,7 +56,7 @@ namespace Ngl { namespace GateKeeper {
*
***/
struct CliGkConn : AtomicRef {
struct CliGkConn : hsAtomicRefCnt {
CliGkConn ();
~CliGkConn ();
@ -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];
@ -208,7 +208,7 @@ static unsigned GetNonZeroTimeMs () {
//============================================================================
static CliGkConn * GetConnIncRef_CS (const char tag[]) {
if (CliGkConn * conn = s_active) {
conn->IncRef(tag);
conn->Ref(tag);
return conn;
}
return nil;
@ -240,7 +240,7 @@ static void UnlinkAndAbandonConn_CS (CliGkConn * conn) {
AsyncSocketDisconnect(conn->sock, true);
}
else {
conn->DecRef("Lifetime");
conn->UnRef("Lifetime");
}
}
@ -303,7 +303,7 @@ static void CheckedReconnect (CliGkConn * conn, ENetError error) {
// Cancel all transactions in progress on this connection.
NetTransCancelByConnId(conn->seq, kNetErrTimeout);
// conn is dead.
conn->DecRef("Lifetime");
conn->UnRef("Lifetime");
ReportNetError(kNetProtocolCli2GateKeeper, error);
}
else {
@ -339,7 +339,7 @@ static void NotifyConnSocketConnectFailed (CliGkConn * conn) {
CheckedReconnect(conn, kNetErrConnectFailed);
conn->DecRef("Connecting");
conn->UnRef("Connecting");
}
//============================================================================
@ -359,8 +359,8 @@ static void NotifyConnSocketDisconnect (CliGkConn * conn) {
// Cancel all transactions in process on this connection.
NetTransCancelByConnId(conn->seq, kNetErrTimeout);
conn->DecRef("Connected");
conn->DecRef("Lifetime");
conn->UnRef("Connected");
conn->UnRef("Lifetime");
}
//============================================================================
@ -474,7 +474,7 @@ static void Connect (
conn->lastHeardTimeMs = GetNonZeroTimeMs(); // used in connect timeout, and ping timeout
strncpy(conn->name, name, arrsize(conn->name));
conn->IncRef("Lifetime");
conn->Ref("Lifetime");
conn->AutoReconnect();
}
@ -507,7 +507,7 @@ static void AsyncLookupCallback (
//===========================================================================
static unsigned CliGkConnTimerDestroyed (void * param) {
CliGkConn * conn = (CliGkConn *) param;
conn->DecRef("TimerDestroyed");
conn->UnRef("TimerDestroyed");
return kAsyncTimeInfinite;
}
@ -525,21 +525,21 @@ static unsigned CliGkConnPingTimerProc (void * param) {
//============================================================================
CliGkConn::CliGkConn ()
: reconnectTimer(nil), reconnectStartMs(0)
: hsAtomicRefCnt(0), reconnectTimer(nil), reconnectStartMs(0)
, pingTimer(nil), pingSendTimeMs(0), lastHeardTimeMs(0)
, sock(nil), cli(nil), seq(0), serverChallenge(0)
, cancelId(nil), abandoned(false)
{
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];
}
//===========================================================================
@ -553,7 +553,7 @@ void CliGkConn::TimerReconnect () {
s_critsect.Leave();
}
else {
IncRef("Connecting");
Ref("Connecting");
// Remember the time we started the reconnect attempt, guarding against
// TimeGetMs() returning zero (unlikely), as a value of zero indicates
@ -592,7 +592,7 @@ void CliGkConn::StartAutoReconnect () {
void CliGkConn::AutoReconnect () {
ASSERT(!reconnectTimer);
IncRef("ReconnectTimer");
Ref("ReconnectTimer");
critsect.Enter();
{
AsyncTimerCreate(
@ -626,7 +626,7 @@ bool CliGkConn::AutoReconnectEnabled () {
//============================================================================
void CliGkConn::AutoPing () {
ASSERT(!pingTimer);
IncRef("PingTimer");
Ref("PingTimer");
critsect.Enter();
{
AsyncTimerCreate(
@ -970,7 +970,7 @@ bool NetGateKeeperTrans::AcquireConn () {
//============================================================================
void NetGateKeeperTrans::ReleaseConn () {
if (m_conn) {
m_conn->DecRef("AcquireConn");
m_conn->UnRef("AcquireConn");
m_conn = nil;
}
}

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

@ -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;
@ -81,7 +81,7 @@ static NetTrans * FindTransIncRef_CS (unsigned transId, const char tag[]) {
// There shouldn't be more than a few transactions; just do a linear scan
for (NetTrans * trans = s_transactions.Head(); trans; trans = s_transactions.Next(trans))
if (trans->m_transId == transId) {
trans->IncRef(tag);
trans->Ref(tag);
return trans;
}
@ -117,7 +117,8 @@ static void CancelTrans_CS (NetTrans * trans, ENetError error) {
//============================================================================
NetTrans::NetTrans (ENetProtocol protocol, ETransType transType)
: m_state(kTransStateWaitServerConnect)
: hsAtomicRefCnt(0)
, m_state(kTransStateWaitServerConnect)
, m_result(kNetPending)
, m_transId(0)
, m_connId(0)
@ -126,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);
}
@ -197,7 +198,7 @@ unsigned NetTransGetTimeoutMs () {
//============================================================================
void NetTransSend (NetTrans * trans) {
trans->IncRef("Lifetime");
trans->Ref("Lifetime");
s_critsect.Enter();
{
static unsigned s_transId;
@ -225,7 +226,7 @@ bool NetTransRecv (unsigned transId, const uint8_t msg[], unsigned bytes) {
if (!result)
NetTransCancel(transId, kNetErrInternalError);
trans->DecRef("Recv");
trans->UnRef("Recv");
return result;
}
@ -345,13 +346,13 @@ void NetTransUpdate () {
while (NetTrans * trans = completed.Head()) {
completed.Unlink(trans);
trans->Post();
trans->DecRef("Lifetime");
trans->UnRef("Lifetime");
}
// Post completed parent transactions
while (NetTrans * trans = parentCompleted.Head()) {
parentCompleted.Unlink(trans);
trans->Post();
trans->DecRef("Lifetime");
trans->UnRef("Lifetime");
}
}

4
Sources/Plasma/PubUtilLib/plNetMessage/plNetCommonMessage.h

@ -43,12 +43,12 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define plNetCommonMessage_inc
#include "HeadSpin.h"
#include "hsSafeRefCnt.h"
#include "hsRefCnt.h"
//
// refcntable data
//
class plNetCommonMessageData : public hsSafeRefCnt
class plNetCommonMessageData : public hsAtomicRefCnt
{
private:
char *fData; // sent

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

File diff suppressed because it is too large Load Diff

4
Sources/Plasma/PubUtilLib/plVault/plVaultNodeAccess.cpp

@ -439,10 +439,10 @@ bool VaultAgeLinkNode::CopyTo (plAgeLinkStruct * link) {
if (RelVaultNode * info = me->GetChildNodeIncRef(plVault::kNodeType_AgeInfo, 1)) {
VaultAgeInfoNode access(info);
access.CopyTo(link->GetAgeInfo());
me->DecRef();
me->UnRef();
return true;
}
me->DecRef();
me->UnRef();
}
link->Clear();
return false;

Loading…
Cancel
Save