Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/coreclr/dlls/mscordac/mscordac_unixexports.src
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ nativeStringResourceTable_mscorrc
#CreateFileW
#CreateEventW
#CreateEventExW
#CreateSemaphoreExW
#CreateThread
#CloseHandle
#DebugBreak
Expand Down Expand Up @@ -98,7 +97,6 @@ nativeStringResourceTable_mscorrc
#RaiseException
#RaiseFailFastException
#ReadFile
#ReleaseSemaphore
#ResetEvent
#ResumeThread
#SearchPathW
Expand Down
32 changes: 32 additions & 0 deletions src/coreclr/inc/clrhost.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,36 @@ inline BOOL IsInCantAllocStressLogRegion()
return t_CantAllocCount != 0;
}

extern thread_local size_t t_CantStopCount;

// For debugging, we can track arbitrary Can't-Stop regions.
// In V1.0, this was on the Thread object, but we need to track this for threads w/o a Thread object.
FORCEINLINE void IncCantStopCount()
{
t_CantStopCount++;
}

FORCEINLINE void DecCantStopCount()
{
t_CantStopCount--;
}

typedef StateHolder<IncCantStopCount, DecCantStopCount> CantStopHolder;

#ifdef _DEBUG
// For debug-only, this can be used w/ a holder to ensure that we're keeping our CS count balanced.
// We should never use this w/ control flow.
inline size_t GetCantStopCount()
{
return t_CantStopCount;
}

// At places where we know we're calling out to native code, we can assert that we're NOT in a CS region.
// This is _debug only since we only use it for asserts; not for real code-flow control in a retail build.
inline bool IsInCantStopRegion()
{
return (GetCantStopCount() > 0);
}
#endif // _DEBUG

#endif
3 changes: 0 additions & 3 deletions src/coreclr/inc/corhost.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@


#include "windows.h" // worth to include before mscoree.h so we are guaranteed to pick few definitions
#ifdef CreateSemaphore
#undef CreateSemaphore
#endif

#include "mscoree.h"

Expand Down
7 changes: 2 additions & 5 deletions src/coreclr/inc/corpriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
#include "corimage.h"
#include "metadata.h"


class UTSemReadWrite;

// Creation function to get IMetaDataDispenser(Ex) interface.
STDAPI CreateMetaDataDispenser(
REFIID riid,
Expand Down Expand Up @@ -112,8 +109,8 @@ DECLARE_INTERFACE_(IMetaDataHelper, IUnknown)

STDMETHOD_(IUnknown *, GetCachedInternalInterface)(BOOL fWithLock) PURE; // S_OK or error
STDMETHOD(SetCachedInternalInterface)(IUnknown * pUnk) PURE; // S_OK or error
STDMETHOD_(UTSemReadWrite*, GetReaderWriterLock)() PURE; // return the reader writer lock
STDMETHOD(SetReaderWriterLock)(UTSemReadWrite * pSem) PURE;
STDMETHOD_(minipal_rwlock*, GetReaderWriterLock)() PURE; // return the reader writer lock
STDMETHOD(SetReaderWriterLock)(minipal_rwlock * pLock) PURE;
}; // IMetaDataHelper


Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/inc/metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
#define _METADATA_H_

#include "ex.h"
#include <minipal/rwlock.h>

class IMetaModelCommon;
class MDInternalRW;
class UTSemReadWrite;

inline int IsGlobalMethodParentTk(mdTypeDef td)
{
Expand Down Expand Up @@ -950,9 +950,9 @@ DECLARE_INTERFACE_(IMDInternalImport, IUnknown)
STDMETHOD_(IUnknown *, GetCachedPublicInterface)(BOOL fWithLock) PURE; // return the cached public interface
__checkReturn
STDMETHOD(SetCachedPublicInterface)(IUnknown *pUnk) PURE; // no return value
STDMETHOD_(UTSemReadWrite*, GetReaderWriterLock)() PURE; // return the reader writer lock
STDMETHOD_(minipal_rwlock*, GetReaderWriterLock)() PURE; // return the reader writer lock
__checkReturn
STDMETHOD(SetReaderWriterLock)(UTSemReadWrite * pSem) PURE;
STDMETHOD(SetReaderWriterLock)(minipal_rwlock * pLock) PURE;

STDMETHOD_(mdModule, GetModuleFromScope)() PURE; // [OUT] Put mdModule token here.

Expand Down
53 changes: 0 additions & 53 deletions src/coreclr/inc/utsem.h

This file was deleted.

3 changes: 0 additions & 3 deletions src/coreclr/inc/winwrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@

#include "palclr.h"

#undef CreateSemaphore
#define CreateSemaphore(_secattr, _count, _maxcount, _name) CreateSemaphoreExW((_secattr), (_count), (_maxcount), (_name), 0, MAXIMUM_ALLOWED | SYNCHRONIZE | SEMAPHORE_MODIFY_STATE)

#undef GetFileVersionInfo
#define GetFileVersionInfo(_filename, _handle, _len, _data) GetFileVersionInfoEx(0, (_filename), (_handle), (_len), (_data))
#undef GetFileVersionInfoSize
Expand Down
38 changes: 22 additions & 16 deletions src/coreclr/md/compiler/mdutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#if defined(FEATURE_METADATA_IN_VM)

LOADEDMODULES * LOADEDMODULES::s_pLoadedModules = NULL;
UTSemReadWrite * LOADEDMODULES::m_pSemReadWrite = NULL;
minipal_rwlock * LOADEDMODULES::m_pReadWriteLock = NULL;

//---------------------------------------------------------------------------------------
//
Expand All @@ -37,14 +37,15 @@ LOADEDMODULES::InitializeStatics()
{
// Initialize global read-write lock
{
NewHolder<UTSemReadWrite> pSemReadWrite = new (nothrow) UTSemReadWrite();
IfNullGo(pSemReadWrite);
IfFailGo(pSemReadWrite->Init());
minipal_rwlock *pReadWriteLock = NULL;
IfFailGo(CreateMDReadWriteLock(&pReadWriteLock));

if (InterlockedCompareExchangeT<UTSemReadWrite *>(&m_pSemReadWrite, pSemReadWrite, NULL) == NULL)
if (InterlockedCompareExchangeT<minipal_rwlock *>(&m_pReadWriteLock, pReadWriteLock, NULL) == NULL)
{ // We won the initialization race
pSemReadWrite.SuppressRelease();
pReadWriteLock = NULL;
}

DestroyMDReadWriteLock(pReadWriteLock);
}

// Initialize the global instance
Expand All @@ -53,7 +54,8 @@ LOADEDMODULES::InitializeStatics()
IfNullGo(pLoadedModules);

{
LOCKWRITE();
CMDReadWriteLock lockHolder(m_pReadWriteLock COMMA_INDEBUG(NULL));
IfFailGo(lockHolder.LockWrite());

if (VolatileLoad(&s_pLoadedModules) == NULL)
{
Expand All @@ -78,7 +80,8 @@ HRESULT LOADEDMODULES::AddModuleToLoadedList(RegMeta * pRegMeta)
IfFailGo(InitializeStatics());

{
LOCKWRITE();
CMDReadWriteLock lockHolder(m_pReadWriteLock COMMA_INDEBUG(NULL));
IfFailGo(lockHolder.LockWrite());

ppRegMeta = s_pLoadedModules->Append();
IfNullGo(ppRegMeta);
Expand Down Expand Up @@ -110,7 +113,8 @@ BOOL LOADEDMODULES::RemoveModuleFromLoadedList(RegMeta * pRegMeta)
IfFailGo(InitializeStatics());

{
LOCKWRITE();
CMDReadWriteLock lockHolder(m_pReadWriteLock COMMA_INDEBUG(NULL));
IfFailGo(lockHolder.LockWrite());

// Search for this module in list of loaded modules.
int count = s_pLoadedModules->Count();
Expand Down Expand Up @@ -174,7 +178,8 @@ BOOL LOADEDMODULES::IsEntryInList(
IfFailGo(InitializeStatics());

{
LOCKREAD();
CMDReadWriteLock lockHolder(m_pReadWriteLock COMMA_INDEBUG(NULL));
IfFailGo(lockHolder.LockRead());

// Loop through each loaded modules
int count = s_pLoadedModules->Count();
Expand Down Expand Up @@ -219,7 +224,8 @@ LOADEDMODULES::ResolveTypeRefWithLoadedModules(
IfFailGo(InitializeStatics());

{
LOCKREAD();
CMDReadWriteLock lockHolder(m_pReadWriteLock COMMA_INDEBUG(NULL));
IfFailGo(lockHolder.LockRead());

// Get the Nesting hierarchy.
IfFailGo(ImportHelper::GetNesterHierarchy(
Expand All @@ -236,11 +242,11 @@ LOADEDMODULES::ResolveTypeRefWithLoadedModules(

{
// Do not lock the TypeRef RegMeta (again), as it is already locked for read by the caller.
// The code:UTSemReadWrite will block ReadLock even for thread holding already the read lock if
// some other thread is waiting for WriteLock on the same lock. That would cause dead-lock if we
// try to lock for read again here.
CMDSemReadWrite cSemRegMeta((pRegMeta == pTypeRefRegMeta) ? NULL : pRegMeta->GetReaderWriterLock());
IfFailGo(cSemRegMeta.LockRead());
// The read-write lock may block a recursive read acquisition while a writer is waiting.
CMDReadWriteLock regMetaLock(
(pRegMeta == pTypeRefRegMeta) ? NULL : pRegMeta->GetReaderWriterLock()
COMMA_INDEBUG(pRegMeta->GetMiniMd()));
IfFailGo(regMetaLock.LockRead());

hr = ImportHelper::FindNestedTypeDef(
pRegMeta->GetMiniMd(),
Expand Down
4 changes: 1 addition & 3 deletions src/coreclr/md/compiler/mdutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class RegMeta;
// this list.
//
//*********************************************************************
class UTSemReadWrite;

class LOADEDMODULES : public CDynArray<RegMeta *>
{
private:
Expand All @@ -50,7 +48,7 @@ class LOADEDMODULES : public CDynArray<RegMeta *>

public:
// Named for locking macros - see code:LOCKREAD
static UTSemReadWrite * m_pSemReadWrite;
static minipal_rwlock * m_pReadWriteLock;

static HRESULT AddModuleToLoadedList(RegMeta *pRegMeta);
static BOOL RemoveModuleFromLoadedList(RegMeta *pRegMeta); // true if found and removed.
Expand Down
Loading
Loading