From 0ee85183fac8129a3c1b890849f32f30fd3940ec Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Thu, 16 Aug 2007 15:45:16 +0000 Subject: [PATCH] Fix the threaded RTS on Windows When calling EnterCriticalSection and LeaveCriticalSection from C-- code, we go via wrappers which use ccall (rather than stdcall). --- includes/OSThreads.h | 7 +++++-- rts/win32/OSThreads.c | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/includes/OSThreads.h b/includes/OSThreads.h index 9a3b5aa..dd7f91a 100644 --- a/includes/OSThreads.h +++ b/includes/OSThreads.h @@ -82,8 +82,11 @@ typedef pthread_key_t ThreadLocalKey; #if CMINUSMINUS -#define ACQUIRE_LOCK(mutex) EnterCriticalSection(mutex) -#define RELEASE_LOCK(mutex) LeaveCriticalSection(mutex) +/* We jump through a hoop here to get a CCall EnterCriticalSection + and LeaveCriticalSection, as that's what C-- wants. */ + +#define ACQUIRE_LOCK(mutex) CCallEnterCriticalSection(mutex) +#define RELEASE_LOCK(mutex) CCallLeaveCriticalSection(mutex) #define ASSERT_LOCK_HELD(mutex) /* nothing */ #else diff --git a/rts/win32/OSThreads.c b/rts/win32/OSThreads.c index 24fbabe..13a3666 100644 --- a/rts/win32/OSThreads.c +++ b/rts/win32/OSThreads.c @@ -13,6 +13,7 @@ #if defined(THREADED_RTS) #include "OSThreads.h" #include "RtsUtils.h" +#include /* For reasons not yet clear, the entire contents of process.h is protected * by __STRICT_ANSI__ not being defined. @@ -231,6 +232,14 @@ forkOS_createThread ( HsStablePtr entry ) (unsigned*)&pId) == 0); } +void CCallEnterCriticalSection(LPCRITICAL_SECTION s) { + EnterCriticalSection(s); +} + +void CCallLeaveCriticalSection(LPCRITICAL_SECTION s) { + LeaveCriticalSection(s); +} + #else /* !defined(THREADED_RTS) */ int -- 1.7.10.4