Skip to content

Commit 9f753a9

Browse files
committed
Make reference counter atomic
1 parent ead47fc commit 9f753a9

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

Core/Libraries/Source/WWVegas/WWLib/DbgHelpLoader.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,15 @@ bool DbgHelpLoader::load()
6767
Inst = new (p) DbgHelpLoader();
6868
}
6969

70-
++Inst->m_referenceCount;
70+
// Always increment the reference count.
71+
const long referenceCount = InterlockedIncrement(&Inst->m_referenceCount);
7172

7273
// Optimization: return early if it failed before.
7374
if (Inst->m_failed)
7475
return false;
7576

7677
// Return early if someone else already loaded it.
77-
if (Inst->m_referenceCount > 1)
78+
if (referenceCount > 1)
7879
return true;
7980

8081
// Try load dbghelp.dll from the system directory first.
@@ -124,7 +125,7 @@ void DbgHelpLoader::unload()
124125
if (Inst == NULL)
125126
return;
126127

127-
if (--Inst->m_referenceCount != 0)
128+
if (InterlockedDecrement(&Inst->m_referenceCount) != 0)
128129
return;
129130

130131
freeResources();

Core/Libraries/Source/WWVegas/WWLib/DbgHelpLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class DbgHelpLoader
180180

181181
Processes m_initializedProcesses;
182182
HMODULE m_dllModule;
183-
int m_referenceCount;
183+
Interlocked32 m_referenceCount;
184184
bool m_failed;
185185
bool m_loadedFromSystem;
186186
};

Core/Libraries/Source/WWVegas/WWLib/WWCommon.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ enum
3838

3939
#if defined(_MSC_VER) && _MSC_VER < 1300
4040
typedef unsigned MemValueType;
41+
typedef long Interlocked32;
4142
#else
4243
typedef unsigned long long MemValueType;
44+
typedef volatile long Interlocked32;
4345
#endif

0 commit comments

Comments
 (0)