diff options
Diffstat (limited to 'src/vm/gcenv.os.cpp')
-rw-r--r-- | src/vm/gcenv.os.cpp | 209 |
1 files changed, 205 insertions, 4 deletions
diff --git a/src/vm/gcenv.os.cpp b/src/vm/gcenv.os.cpp index 6c08558e03..77be88c96d 100644 --- a/src/vm/gcenv.os.cpp +++ b/src/vm/gcenv.os.cpp @@ -329,11 +329,7 @@ bool GCToOSInterface::GetCurrentProcessAffinityMask(uintptr_t* processMask, uint { LIMITED_METHOD_CONTRACT; -#ifndef FEATURE_PAL return !!::GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)processMask, (PDWORD_PTR)systemMask); -#else - return false; -#endif } // Get number of processors assigned to the current process @@ -700,3 +696,208 @@ void CLRCriticalSection::Leave() WRAPPER_NO_CONTRACT; UnsafeLeaveCriticalSection(&m_cs); } + +// An implementatino of GCEvent that delegates to +// a CLREvent, which in turn delegates to the PAL. This event +// is also host-aware. +class GCEvent::Impl +{ +private: + CLREvent m_event; + +public: + Impl() = default; + + bool IsValid() + { + WRAPPER_NO_CONTRACT; + + return !!m_event.IsValid(); + } + + void CloseEvent() + { + WRAPPER_NO_CONTRACT; + + assert(m_event.IsValid()); + m_event.CloseEvent(); + } + + void Set() + { + WRAPPER_NO_CONTRACT; + + assert(m_event.IsValid()); + m_event.Set(); + } + + void Reset() + { + WRAPPER_NO_CONTRACT; + + assert(m_event.IsValid()); + m_event.Reset(); + } + + uint32_t Wait(uint32_t timeout, bool alertable) + { + WRAPPER_NO_CONTRACT; + + assert(m_event.IsValid()); + return m_event.Wait(timeout, alertable); + } + + bool CreateAutoEvent(bool initialState) + { + CONTRACTL { + NOTHROW; + GC_NOTRIGGER; + } CONTRACTL_END; + + return !!m_event.CreateAutoEventNoThrow(initialState); + } + + bool CreateManualEvent(bool initialState) + { + CONTRACTL { + NOTHROW; + GC_NOTRIGGER; + } CONTRACTL_END; + + return !!m_event.CreateManualEventNoThrow(initialState); + } + + bool CreateOSAutoEvent(bool initialState) + { + CONTRACTL { + NOTHROW; + GC_NOTRIGGER; + } CONTRACTL_END; + + return !!m_event.CreateOSAutoEventNoThrow(initialState); + } + + bool CreateOSManualEvent(bool initialState) + { + CONTRACTL { + NOTHROW; + GC_NOTRIGGER; + } CONTRACTL_END; + + return !!m_event.CreateOSManualEventNoThrow(initialState); + } +}; + +GCEvent::GCEvent() + : m_impl(nullptr) +{ +} + +void GCEvent::CloseEvent() +{ + WRAPPER_NO_CONTRACT; + + assert(m_impl != nullptr); + m_impl->CloseEvent(); +} + +void GCEvent::Set() +{ + WRAPPER_NO_CONTRACT; + + assert(m_impl != nullptr); + m_impl->Set(); +} + +void GCEvent::Reset() +{ + WRAPPER_NO_CONTRACT; + + assert(m_impl != nullptr); + m_impl->Reset(); +} + +uint32_t GCEvent::Wait(uint32_t timeout, bool alertable) +{ + WRAPPER_NO_CONTRACT; + + assert(m_impl != nullptr); + return m_impl->Wait(timeout, alertable); +} + +bool GCEvent::CreateManualEventNoThrow(bool initialState) +{ + CONTRACTL { + NOTHROW; + GC_NOTRIGGER; + } CONTRACTL_END; + + assert(m_impl == nullptr); + NewHolder<GCEvent::Impl> event = new (nothrow) GCEvent::Impl(); + if (!event) + { + return false; + } + + event->CreateManualEvent(initialState); + m_impl = event.Extract(); + return true; +} + +bool GCEvent::CreateAutoEventNoThrow(bool initialState) +{ + CONTRACTL { + NOTHROW; + GC_NOTRIGGER; + } CONTRACTL_END; + + assert(m_impl == nullptr); + NewHolder<GCEvent::Impl> event = new (nothrow) GCEvent::Impl(); + if (!event) + { + return false; + } + + event->CreateAutoEvent(initialState); + m_impl = event.Extract(); + return IsValid(); +} + +bool GCEvent::CreateOSAutoEventNoThrow(bool initialState) +{ + CONTRACTL { + NOTHROW; + GC_NOTRIGGER; + } CONTRACTL_END; + + assert(m_impl == nullptr); + NewHolder<GCEvent::Impl> event = new (nothrow) GCEvent::Impl(); + if (!event) + { + return false; + } + + event->CreateOSAutoEvent(initialState); + m_impl = event.Extract(); + return IsValid(); +} + +bool GCEvent::CreateOSManualEventNoThrow(bool initialState) +{ + CONTRACTL { + NOTHROW; + GC_NOTRIGGER; + } CONTRACTL_END; + + assert(m_impl == nullptr); + NewHolder<GCEvent::Impl> event = new (nothrow) GCEvent::Impl(); + if (!event) + { + return false; + } + + event->CreateOSManualEvent(initialState); + m_impl = event.Extract(); + return IsValid(); +} + |