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
1 change: 0 additions & 1 deletion src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ if(CLR_CMAKE_TARGET_WIN32)
version.lib
shlwapi.lib
bcrypt.lib
RuntimeObject.lib
)
else()
list(APPEND CORECLR_LIBRARIES
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/ilasm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ if(CLR_CMAKE_TARGET_WIN32)
version.lib
shlwapi.lib
bcrypt.lib
RuntimeObject.lib
coreclrminipal
)
else()
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/ildasm/exe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ if(CLR_CMAKE_HOST_WIN32)
version.lib
shlwapi.lib
bcrypt.lib
RuntimeObject.lib
coreclrminipal
)
else()
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/jit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,6 @@ else()
shlwapi.lib
bcrypt.lib
crypt32.lib
RuntimeObject.lib
coreclrminipal
)
endif(CLR_CMAKE_HOST_UNIX)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,9 @@ private static void InitializeCom(ApartmentState state = ApartmentState.MTA)
if ((t_comState & ComState.InitializedByUs) != 0)
return;

#if ENABLE_WINRT
int hr = Interop.WinRT.RoInitialize(
(state == ApartmentState.STA) ? Interop.WinRT.RO_INIT_SINGLETHREADED
: Interop.WinRT.RO_INIT_MULTITHREADED);
#else
int hr = Interop.Ole32.CoInitializeEx(IntPtr.Zero,
(state == ApartmentState.STA) ? Interop.Ole32.COINIT_APARTMENTTHREADED
: Interop.Ole32.COINIT_MULTITHREADED);
#endif
if (hr < 0)
{
// RPC_E_CHANGED_MODE indicates this thread has been already initialized with a different
Expand Down Expand Up @@ -339,11 +333,7 @@ private static void UninitializeCom()
if ((t_comState & ComState.InitializedByUs) == 0)
return;

#if ENABLE_WINRT
Interop.WinRT.RoUninitialize();
#else
Interop.Ole32.CoUninitialize();
#endif

t_comState &= ~ComState.InitializedByUs;
}
Expand Down
128 changes: 11 additions & 117 deletions src/coreclr/vm/threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2356,20 +2356,6 @@ void Thread::BaseCoUninitialize()
::CoUninitialize();
}// BaseCoUninitialize

#ifdef FEATURE_COMINTEROP
void Thread::BaseWinRTUninitialize()
{
STATIC_CONTRACT_THROWS;
STATIC_CONTRACT_GC_TRIGGERS;
STATIC_CONTRACT_MODE_PREEMPTIVE;

_ASSERTE(GetThread() == this);
_ASSERTE(IsWinRTInitialized());

RoUninitialize();
}
#endif // FEATURE_COMINTEROP

void Thread::CoUninitialize()
{
CONTRACTL {
Expand All @@ -2380,30 +2366,14 @@ void Thread::CoUninitialize()

// Running threads might have performed a CoInitialize which must
// now be balanced.
BOOL needsUninitialize = IsCoInitialized()
#ifdef FEATURE_COMINTEROP
|| IsWinRTInitialized()
#endif // FEATURE_COMINTEROP
;

if (!IsAtProcessExit() && needsUninitialize)
if (!IsAtProcessExit() && IsCoInitialized())
{
GCX_PREEMP();
CONTRACT_VIOLATION(ThrowsViolation);

if (IsCoInitialized())
{
BaseCoUninitialize();
ResetThreadState(TS_CoInitialized);
}

#ifdef FEATURE_COMINTEROP
if (IsWinRTInitialized())
{
BaseWinRTUninitialize();
ResetWinRTInitialized();
}
#endif // FEATURE_COMNITEROP
BaseCoUninitialize();
ResetThreadState(TS_CoInitialized);
}
}
#endif // FEATURE_COMINTEROP_APARTMENT_SUPPORT
Expand Down Expand Up @@ -2590,30 +2560,13 @@ void Thread::CleanupCOMState()
// now be balanced. However only the thread that called COInitialize can
// call CoUninitialize.

BOOL needsUninitialize = IsCoInitialized()
#ifdef FEATURE_COMINTEROP
|| IsWinRTInitialized()
#endif // FEATURE_COMINTEROP
;

if (needsUninitialize)
if (IsCoInitialized())
{
GCX_PREEMP();
CONTRACT_VIOLATION(ThrowsViolation);

if (IsCoInitialized())
{
BaseCoUninitialize();
ResetCoInitialized();
}

#ifdef FEATURE_COMINTEROP
if (IsWinRTInitialized())
{
BaseWinRTUninitialize();
ResetWinRTInitialized();
}
#endif // FEATURE_COMINTEROP
BaseCoUninitialize();
ResetCoInitialized();
}
}
#endif // FEATURE_COMINTEROP_APARTMENT_SUPPORT
Expand Down Expand Up @@ -3757,33 +3710,15 @@ Thread::ApartmentState Thread::SetApartment(ApartmentState state)
// the thread.
if (state == AS_Unknown)
{
BOOL needUninitialize = (m_State & TS_CoInitialized)
#ifdef FEATURE_COMINTEROP
|| IsWinRTInitialized()
#endif // FEATURE_COMINTEROP
;

if (needUninitialize)
if (m_State & TS_CoInitialized)
{
GCX_PREEMP();

// If we haven't CoInitialized the thread, then we don't have anything to do.
if (m_State & TS_CoInitialized)
{
// CoUninitialize the thread and reset the STA/MTA/CoInitialized state bits.
::CoUninitialize();

ThreadState uninitialized = static_cast<ThreadState>(TS_InSTA | TS_InMTA | TS_CoInitialized);
ResetThreadState(uninitialized);
}
// CoUninitialize the thread and reset the STA/MTA/CoInitialized state bits.
::CoUninitialize();

#ifdef FEATURE_COMINTEROP
if (IsWinRTInitialized())
{
BaseWinRTUninitialize();
ResetWinRTInitialized();
}
#endif // FEATURE_COMINTEROP
ThreadState uninitialized = static_cast<ThreadState>(TS_InSTA | TS_InMTA | TS_CoInitialized);
ResetThreadState(uninitialized);
}
return GetApartment();
}
Expand Down Expand Up @@ -3871,47 +3806,6 @@ Thread::ApartmentState Thread::SetApartment(ApartmentState state)
_ASSERTE(!"Unexpected HRESULT returned from CoInitializeEx!");
}

// Since WinRT sits on top of COM we need to make sure that it is initialized
// in the same threading mode as we just started COM itself
// with (or that we detected COM had already been started with).
if (!IsWinRTInitialized())
{
GCX_PREEMP();

BOOL isSTA = m_State & TS_InSTA;
_ASSERTE(isSTA || (m_State & TS_InMTA));

HRESULT hrWinRT = RoInitialize(isSTA ? RO_INIT_SINGLETHREADED : RO_INIT_MULTITHREADED);

if (SUCCEEDED(hrWinRT))
{
if (hrWinRT == S_OK)
{
SetThreadStateNC(TSNC_WinRTInitialized);
}
else
{
_ASSERTE(hrWinRT == S_FALSE);

// If the thread has already been initialized, back it out. We may not
// always be able to call RoUninitialize on shutdown so if there's
// a way to avoid having to, we should take advantage of that.
RoUninitialize();
}
}
else if (hrWinRT == E_OUTOFMEMORY)
{
COMPlusThrowOM();
}
else
{
// We don't check for RPC_E_CHANGEDMODE, since we're using the mode that was read in by
// initializing COM above. COM and WinRT need to always be in the same mode, so we should never
// see that return code at this point.
_ASSERTE(!"Unexpected HRESULT From RoInitialize");
}
}

return GetApartment();
}

Expand Down
20 changes: 1 addition & 19 deletions src/coreclr/vm/threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -627,10 +627,7 @@ class Thread
TSNC_DebuggerSleepWaitJoin = 0x04000000, // Indicates to the debugger that this thread is in a sleep wait or join state
// This almost mirrors the TS_Interruptible state however that flag can change
// during GC-preemptive mode whereas this one cannot.
#ifdef FEATURE_COMINTEROP
TSNC_WinRTInitialized = 0x08000000, // the thread has initialized WinRT
#endif // FEATURE_COMINTEROP

// unused = 0x08000000,
TSNC_TSLTakenForStartup = 0x10000000, // The ThreadStoreLock (TSL) is held by another mechanism during
// thread startup so can be skipped.

Expand Down Expand Up @@ -748,20 +745,6 @@ class Thread
ResetThreadState(TS_CoInitialized);
}

#ifdef FEATURE_COMINTEROP
BOOL IsWinRTInitialized()
{
LIMITED_METHOD_CONTRACT;
return HasThreadStateNC(TSNC_WinRTInitialized);
}

void ResetWinRTInitialized()
{
LIMITED_METHOD_CONTRACT;
ResetThreadStateNC(TSNC_WinRTInitialized);
}
#endif // FEATURE_COMINTEROP

void CleanupCOMState();

#endif // FEATURE_COMINTEROP_APARTMENT_SUPPORT
Expand Down Expand Up @@ -1119,7 +1102,6 @@ class Thread
#ifdef FEATURE_COMINTEROP_APARTMENT_SUPPORT
void CoUninitialize();
void BaseCoUninitialize();
void BaseWinRTUninitialize();
#endif // FEATURE_COMINTEROP_APARTMENT_SUPPORT

void CooperativeCleanup();
Expand Down
1 change: 0 additions & 1 deletion src/native/corehost/apphost/static/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ if(CLR_CMAKE_TARGET_WIN32)
shlwapi.lib
shell32.lib
bcrypt.lib
RuntimeObject.lib
)

# additional requirements for System.IO.Compression.Native
Expand Down
Loading