Skip to content

Commit 0360335

Browse files
Replace Win32 PAL CRITICAL_SECTION with minipal Mutex (#115858)
* Remove unused ThreadStore::CanAcquireLock(). * Create PAL critical section Delete unused debugging APIs in PAL CS code * Remove PAL tests for CRITICAL_SECTION Remove any non-running tests requiring CRITICAL_SECTION Remove unused PAL header referencing CRITICAL_SECTION (internal.h) --------- Co-authored-by: Jan Kotas <[email protected]>
1 parent b2b6b84 commit 0360335

File tree

120 files changed

+722
-7148
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+722
-7148
lines changed

src/coreclr/debug/daccess/daccess.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ extern TADDR g_ClrModuleBase;
4242
// To include definition of IsThrowableThreadAbortException
4343
// #include <exstatecommon.h>
4444

45-
CRITICAL_SECTION g_dacCritSec;
45+
minipal_mutex g_dacMutex;
4646
ClrDataAccess* g_dacImpl;
4747

4848
EXTERN_C BOOL WINAPI DllMain2(HANDLE instance, DWORD reason, LPVOID reserved)
@@ -72,7 +72,7 @@ EXTERN_C BOOL WINAPI DllMain2(HANDLE instance, DWORD reason, LPVOID reserved)
7272
return FALSE;
7373
}
7474
#endif
75-
InitializeCriticalSection(&g_dacCritSec);
75+
minipal_mutex_init(&g_dacMutex);
7676

7777
g_procInitialized = true;
7878
break;
@@ -82,7 +82,7 @@ EXTERN_C BOOL WINAPI DllMain2(HANDLE instance, DWORD reason, LPVOID reserved)
8282
// It's possible for this to be called without ATTACH completing (eg. if it failed)
8383
if (g_procInitialized)
8484
{
85-
DeleteCriticalSection(&g_dacCritSec);
85+
minipal_mutex_destroy(&g_dacMutex);
8686
}
8787
g_procInitialized = false;
8888
break;

src/coreclr/debug/daccess/dacdbiimpl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060

6161

62-
// Global allocator for DD. Access is protected under the g_dacCritSec lock.
62+
// Global allocator for DD. Access is protected under the g_dacMutex lock.
6363
IDacDbiInterface::IAllocator * g_pAllocator = NULL;
6464

6565
//---------------------------------------------------------------------------------------
@@ -362,7 +362,7 @@ interface IMDInternalImport* DacDbiInterfaceImpl::GetMDImport(
362362
const ReflectionModule * pReflectionModule,
363363
bool fThrowEx)
364364
{
365-
// Since this is called from an existing DAC-primitive, we already hold the g_dacCritSec lock.
365+
// Since this is called from an existing DAC-primitive, we already hold the g_dacMutex lock.
366366
// The lock conveniently protects our cache.
367367
SUPPORTS_DAC;
368368

src/coreclr/debug/daccess/dacdbiimpl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ class DacDbiInterfaceImpl :
11071107
};
11081108

11091109

1110-
// Global allocator for DD. Access is protected under the g_dacCritSec lock.
1110+
// Global allocator for DD. Access is protected under the g_dacMutex lock.
11111111
extern "C" IDacDbiInterface::IAllocator * g_pAllocator;
11121112

11131113

@@ -1116,7 +1116,7 @@ class DDHolder
11161116
public:
11171117
DDHolder(DacDbiInterfaceImpl* pContainer, bool fAllowReentrant)
11181118
{
1119-
EnterCriticalSection(&g_dacCritSec);
1119+
minipal_mutex_enter(&g_dacMutex);
11201120

11211121
// If we're not re-entrant, then assert.
11221122
if (!fAllowReentrant)
@@ -1139,7 +1139,7 @@ class DDHolder
11391139
g_dacImpl = m_pOldContainer;
11401140
g_pAllocator = m_pOldAllocator;
11411141

1142-
LeaveCriticalSection(&g_dacCritSec);
1142+
minipal_mutex_leave(&g_dacMutex);
11431143
}
11441144

11451145
protected:

src/coreclr/debug/daccess/dacimpl.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef __DACIMPL_H__
1414
#define __DACIMPL_H__
1515

16+
#include <minipal/mutex.h>
1617
#include "gcinterface.dac.h"
1718
//---------------------------------------------------------------------------------------
1819
// Setting DAC_HASHTABLE tells the DAC to use the hand rolled hashtable for
@@ -26,7 +27,7 @@
2627
#include <unordered_map>
2728
#pragma pop_macro("return")
2829
#endif //DAC_HASHTABLE
29-
extern CRITICAL_SECTION g_dacCritSec;
30+
extern minipal_mutex g_dacMutex;
3031

3132
// Convert between CLRDATA_ADDRESS and TADDR.
3233
// Note that CLRDATA_ADDRESS is sign-extended (for compat with Windbg and OS conventions). Converting
@@ -3809,26 +3810,26 @@ class EnumMethodInstances
38093810
//----------------------------------------------------------------------------
38103811

38113812
#define DAC_ENTER() \
3812-
EnterCriticalSection(&g_dacCritSec); \
3813+
minipal_mutex_enter(&g_dacMutex); \
38133814
ClrDataAccess* __prevDacImpl = g_dacImpl; \
38143815
g_dacImpl = this;
38153816

38163817
// When entering a child object we validate that
38173818
// the process's host instance cache hasn't been flushed
38183819
// since the child was created.
38193820
#define DAC_ENTER_SUB(dac) \
3820-
EnterCriticalSection(&g_dacCritSec); \
3821+
minipal_mutex_enter(&g_dacMutex); \
38213822
if (dac->m_instanceAge != m_instanceAge) \
38223823
{ \
3823-
LeaveCriticalSection(&g_dacCritSec); \
3824+
minipal_mutex_leave(&g_dacMutex); \
38243825
return E_INVALIDARG; \
38253826
} \
38263827
ClrDataAccess* __prevDacImpl = g_dacImpl; \
38273828
g_dacImpl = (dac)
38283829

38293830
#define DAC_LEAVE() \
38303831
g_dacImpl = __prevDacImpl; \
3831-
LeaveCriticalSection(&g_dacCritSec)
3832+
minipal_mutex_leave(&g_dacMutex)
38323833

38333834

38343835
#define SOSHelperEnter() \

src/coreclr/debug/di/rspriv.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <windows.h>
1616

1717
#include <utilcode.h>
18-
18+
#include <minipal/mutex.h>
1919

2020
#ifdef _DEBUG
2121
#define LOGGING
@@ -798,7 +798,7 @@ class RSLock
798798
}
799799

800800

801-
CRITICAL_SECTION m_lock;
801+
minipal_mutex m_lock;
802802

803803
#ifdef _DEBUG
804804
public:
@@ -839,9 +839,8 @@ class RSLock
839839
typedef RSLock::RSLockHolder RSLockHolder;
840840
typedef RSLock::RSInverseLockHolder RSInverseLockHolder;
841841

842-
// In the RS, we should be using RSLocks instead of raw critical sections.
843-
#define CRITICAL_SECTION USE_RSLOCK_INSTEAD_OF_CRITICAL_SECTION
844-
842+
// In the RS, we should be using RSLocks instead of raw minipal_mutex.
843+
#define minipal_mutex USE_RSLOCK_INSTEAD_OF_MINIPAL_MUTEX
845844

846845
/* ------------------------------------------------------------------------- *
847846
* Helper macros. Use the ATT_* macros below instead of these.
@@ -11200,7 +11199,7 @@ inline CordbEval * UnwrapCookieCordbEval(CordbProcess *pProc, UINT cookie)
1120011199

1120111200

1120211201
// We defined this at the top of the file - undef it now so that we don't pollute other files.
11203-
#undef CRITICAL_SECTION
11202+
#undef minipal_mutex
1120411203

1120511204

1120611205
#ifdef RSCONTRACTS

src/coreclr/debug/di/rspriv.inl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,14 +528,15 @@ inline void RSLock::Init(const char * szTag, int eAttr, ERSLockLevel level)
528528

529529
_ASSERTE(IsInit());
530530

531-
InitializeCriticalSection(&m_lock);
531+
bool init = minipal_mutex_init(&m_lock);
532+
_ASSERTE(init);
532533
}
533534

534535
// Cleanup a lock.
535536
inline void RSLock::Destroy()
536537
{
537538
CONSISTENCY_CHECK_MSGF(IsInit(), ("RSLock '%s' not inited", m_szTag));
538-
DeleteCriticalSection(&m_lock);
539+
minipal_mutex_destroy(&m_lock);
539540

540541
#ifdef _DEBUG
541542
m_eAttr = cLockUninit; // No longer initialized.
@@ -549,10 +550,11 @@ inline void RSLock::Lock()
549550

550551
#ifdef RSCONTRACTS
551552
DbgRSThread * pThread = DbgRSThread::GetThread();
553+
552554
pThread->NotifyTakeLock(this);
553555
#endif
554556

555-
EnterCriticalSection(&m_lock);
557+
minipal_mutex_enter(&m_lock);
556558
#ifdef _DEBUG
557559
m_tidOwner = ::GetCurrentThreadId();
558560
m_count++;
@@ -583,7 +585,7 @@ inline void RSLock::Unlock()
583585
pThread->NotifyReleaseLock(this);
584586
#endif
585587

586-
LeaveCriticalSection(&m_lock);
588+
minipal_mutex_leave(&m_lock);
587589
}
588590

589591
template <class T>

src/coreclr/debug/inc/dbgtransportsession.h

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
#ifndef RIGHT_SIDE_COMPILE
99
#include <utilcode.h>
1010
#include <crst.h>
11-
1211
#endif // !RIGHT_SIDE_COMPILE
1312

13+
#include <minipal/mutex.h>
1414
#include <minipal/guid.h>
1515

1616
#if defined(FEATURE_DBGIPC_TRANSPORT_VM) || defined(FEATURE_DBGIPC_TRANSPORT_DI)
@@ -271,7 +271,7 @@ inline UINT32 DBGIPC_HTONL(UINT32 x)
271271

272272
// Lock abstraction (we can't use the same lock implementation on LS and RS since we really want a Crst on the
273273
// LS and this isn't available in the RS environment).
274-
class DbgTransportLock
274+
class DbgTransportLock final
275275
{
276276
public:
277277
void Init();
@@ -281,12 +281,32 @@ class DbgTransportLock
281281

282282
private:
283283
#ifdef RIGHT_SIDE_COMPILE
284-
CRITICAL_SECTION m_sLock;
284+
minipal_mutex m_sLock;
285285
#else // RIGHT_SIDE_COMPILE
286286
CrstExplicitInit m_sLock;
287287
#endif // RIGHT_SIDE_COMPILE
288288
};
289289

290+
class TransportLockHolder final
291+
{
292+
DbgTransportLock& _lock;
293+
public:
294+
TransportLockHolder(DbgTransportLock& lock)
295+
: _lock(lock)
296+
{
297+
_lock.Enter();
298+
}
299+
~TransportLockHolder()
300+
{
301+
_lock.Leave();
302+
}
303+
304+
TransportLockHolder(TransportLockHolder const&) = delete;
305+
TransportLockHolder& operator=(TransportLockHolder const&) = delete;
306+
TransportLockHolder(TransportLockHolder&& other) = delete;
307+
TransportLockHolder&& operator=(TransportLockHolder&&) = delete;
308+
};
309+
290310
// The transport has only one queue for IPC events, but each IPC event can be marked as one of two types.
291311
// The transport will signal the handle corresponding to the type of each IPC event. (See
292312
// code:DbgTransportSession::GetIPCEventReadyEvent and code:DbgTransportSession::GetDebugEventReadyEvent.)
@@ -555,26 +575,6 @@ class DbgTransportSession
555575
}
556576
};
557577

558-
// Holder class used to take a transport lock in a given scope and automatically release it once that
559-
// scope is exited.
560-
class TransportLockHolder
561-
{
562-
public:
563-
TransportLockHolder(DbgTransportLock *pLock)
564-
{
565-
m_pLock = pLock;
566-
m_pLock->Enter();
567-
}
568-
569-
~TransportLockHolder()
570-
{
571-
m_pLock->Leave();
572-
}
573-
574-
private:
575-
DbgTransportLock *m_pLock;
576-
};
577-
578578
#ifdef _DEBUG
579579
// Store statistics for various session activities that will be useful for performance analysis and tracking
580580
// down bugs.

0 commit comments

Comments
 (0)