File tree Expand file tree Collapse file tree
Core/Libraries/Source/WWVegas/WWLib Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -90,26 +90,12 @@ MutexClass::LockClass::~LockClass()
9090
9191// ----------------------------------------------------------------------------
9292
93- CriticalSectionClass::CriticalSectionClass () : handle( nullptr ), locked(false )
93+ CriticalSectionClass::CriticalSectionClass () : locked(false )
9494{
9595 #ifdef _UNIX
9696 // assert(0);
9797 #else
98- // Allocate with proper alignment for CRITICAL_SECTION
99- // On 64-bit: requires 8-byte alignment, on 32-bit: requires 4-byte alignment
100- #if defined(_WIN64) || defined(__LP64__)
101- size_t alignment = 8 ;
102- #else
103- size_t alignment = 4 ;
104- #endif
105-
106- handle = _aligned_malloc (sizeof (CRITICAL_SECTION), alignment);
107- if (handle != nullptr ) {
108- InitializeCriticalSection ((CRITICAL_SECTION*)handle);
109- }
110- else {
111- WWASSERT (false ); // Allocation failed
112- }
98+ InitializeCriticalSection ((CRITICAL_SECTION*)handle);
11399 #endif
114100}
115101
@@ -119,10 +105,7 @@ CriticalSectionClass::~CriticalSectionClass()
119105 // assert(0);
120106 #else
121107 WWASSERT (!locked); // Can't delete locked critical section!
122- if (handle != nullptr ) {
123- DeleteCriticalSection ((CRITICAL_SECTION*)handle);
124- _aligned_free (handle);
125- }
108+ DeleteCriticalSection ((CRITICAL_SECTION*)handle);
126109 #endif
127110}
128111
Original file line number Diff line number Diff line change @@ -81,7 +81,10 @@ class MutexClass
8181
8282class CriticalSectionClass
8383{
84- void * handle;
84+ // Inline storage for CRITICAL_SECTION to avoid heap allocation entirely.
85+ // CRITICAL_SECTION is 40 bytes on x64 and 24 bytes on x86; 40 bytes with
86+ // 8-byte alignment is sufficient for both platforms.
87+ alignas (8 ) char handle[40 ];
8588 unsigned locked;
8689
8790 // Lock and unlock are private so that you can't use them directly. Use LockClass as a sentry instead!
You can’t perform that action at this time.
0 commit comments