Skip to content

Commit 196e005

Browse files
joye-ramonexrSimpodin
authored andcommitted
std::atomic для dwReference в smem_value
1 parent dca9a0c commit 196e005

File tree

3 files changed

+20
-53
lines changed

3 files changed

+20
-53
lines changed

ogsr_engine/xrCore/xrsharedmem.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,15 @@ void smem_container::clean()
8282

8383
void smem_container::dump()
8484
{
85+
string_path fname;
86+
FS.update_path(fname, fsgame::app_data_root, "$smem_container_dump$.txt");
87+
8588
cs.Enter();
8689
cdb::iterator it = container.begin();
8790
cdb::iterator end = container.end();
88-
FILE* F = fopen("x:\\$smem_dump$.txt", "w");
89-
for (; it != end; it++)
90-
fprintf(F, "%4u : crc[%6x], %u bytes\n", (*it)->dwReference, (*it)->dwCRC, (*it)->dwSize);
91+
FILE* F = fopen(fname, "w");
92+
for (; it != end; ++it)
93+
fprintf(F, "%4u : crc[%6x], %u bytes\n", (*it)->dwReference.load(), (*it)->dwCRC, (*it)->dwSize);
9194
fclose(F);
9295
cs.Leave();
9396
}

ogsr_engine/xrCore/xrsharedmem.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
#pragma warning(disable : 4200)
66
struct XRCORE_API smem_value
77
{
8-
u32 dwReference;
8+
std::atomic<u32> dwReference{};
9+
910
u32 dwCRC;
1011
u32 dwSize; // size in bytes !!!
11-
u32 _align_16;
12+
1213
u8 value[];
1314
};
1415

@@ -60,9 +61,10 @@ class ref_smem
6061
{
6162
if (0 == p_)
6263
return;
63-
p_->dwReference--;
64+
--p_->dwReference;
6465
if (0 == p_->dwReference)
6566
{
67+
// Msg("ref_smem: deleting %d bytes of shared memory", p_->dwSize);
6668
if (g_pSharedMemoryContainer->disabled())
6769
xr_free(p_);
6870

@@ -74,8 +76,10 @@ class ref_smem
7476
void _set(ref_smem const& rhs)
7577
{
7678
smem_value* v = rhs.p_;
77-
if (0 != v)
78-
v->dwReference++;
79+
80+
if (v)
81+
++v->dwReference;
82+
7983
_dec();
8084
p_ = v;
8185
}
@@ -94,8 +98,10 @@ class ref_smem
9498
void create(u32 dwLength, T* ptr)
9599
{
96100
smem_value* v = g_pSharedMemoryContainer->dock(dwLength * sizeof(T), ptr);
97-
if (0 != v)
98-
v->dwReference++;
101+
102+
if (v)
103+
++v->dwReference;
104+
99105
_dec();
100106
p_ = v;
101107
}
@@ -104,7 +110,7 @@ class ref_smem
104110
ref_smem<T>& operator=(ref_smem<T> const& rhs)
105111
{
106112
_set(rhs);
107-
return (ref_smem<T>&)*this;
113+
return static_cast<ref_smem<T>&>(*this);
108114
}
109115
T* operator*() const { return p_ ? (T*)p_->value : 0; }
110116
bool operator!() const { return p_ == 0; }

ogsr_engine/xr_3da/xr_ioc_cmd.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -59,43 +59,6 @@ class CCC_Quit : public IConsole_Command
5959
};
6060

6161
//-----------------------------------------------------------------------
62-
#ifdef DEBUG_MEMORY_MANAGER
63-
class CCC_MemStat : public IConsole_Command
64-
{
65-
public:
66-
CCC_MemStat(LPCSTR N) : IConsole_Command(N) { bEmptyArgsHandled = TRUE; };
67-
virtual void Execute(LPCSTR args)
68-
{
69-
string_path fn;
70-
if (args && args[0])
71-
xr_sprintf(fn, sizeof(fn), "%s.dump", args);
72-
else
73-
strcpy_s_s(fn, sizeof(fn), "x:\\$memory$.dump");
74-
Memory.mem_statistic(fn);
75-
// g_pStringContainer->dump ();
76-
// g_pSharedMemoryContainer->dump ();
77-
}
78-
};
79-
#endif // DEBUG_MEMORY_MANAGER
80-
81-
#ifdef DEBUG_MEMORY_MANAGER
82-
class CCC_DbgMemCheck : public IConsole_Command
83-
{
84-
public:
85-
CCC_DbgMemCheck(LPCSTR N) : IConsole_Command(N) { bEmptyArgsHandled = TRUE; };
86-
virtual void Execute(LPCSTR args)
87-
{
88-
if (Memory.debug_mode)
89-
{
90-
Memory.dbg_check();
91-
}
92-
else
93-
{
94-
Msg("~ Run with -mem_debug options.");
95-
}
96-
}
97-
};
98-
#endif // DEBUG_MEMORY_MANAGER
9962

10063
class CCC_DbgStrCheck : public IConsole_Command
10164
{
@@ -533,11 +496,6 @@ void CCC_Register()
533496
CMD1(CCC_MotionsStat, "stat_motions");
534497
CMD1(CCC_TexturesStat, "stat_textures");
535498

536-
#ifdef DEBUG_MEMORY_MANAGER
537-
CMD1(CCC_MemStat, "dbg_mem_dump");
538-
CMD1(CCC_DbgMemCheck, "dbg_mem_check");
539-
#endif // DEBUG_MEMORY_MANAGER
540-
541499
#ifdef DEBUG
542500
CMD3(CCC_Mask, "mt_particles", &psDeviceFlags, mtParticles);
543501

0 commit comments

Comments
 (0)