Commit 48ccd03c authored by sof's avatar sof

[project @ 2002-01-31 23:04:15 by sof]

Win32 implementation, first pass.
parent 1e8a345a
......@@ -10,7 +10,7 @@
#include "Rts.h"
#if defined(RTS_SUPPORTS_THREADS)
#include "OSThreads.h"
#include "RtsUtils.h"
#if defined(HAVE_PTHREAD_H) && !defined(WANT_NATIVE_WIN32_THREADS)
/*
......@@ -72,10 +72,17 @@ void initMutexVar (MutexVar* pMut)
}
#elif defined(HAVE_WINDOWS_H)
#include <process.h>
/* Win32 threads and synchronisation objects */
/* A CondVar is represented by a Win32 Event object,
* a MutexVar by a Mutex kernel object.
*
* ToDo: go through the defn and usage of these to
* make sure the semantics match up with that of
* the (assumed) pthreads behaviour. This is really
* just a first pass at getting something compilable.
*/
void initCondVar( CondVar* pCond )
......@@ -85,54 +92,80 @@ void initCondVar( CondVar* pCond )
TRUE, /* initially signalled */
NULL); /* unnamed => process-local. */
pthread_cond_init(pCond, NULL);
if ( h == NULL ) {
belch("initCondVar: unable to create");
}
*pCond = h;
return;
}
void closeCondVar( CondVar* pCond )
{
pthread_cond_destroy(pCond);
if ( CloseHandle(*pCond) == 0 ) {
belch("closeCondVar: failed to close");
}
return;
}
rtsBool
broadcastCondVar ( CondVar* pCond )
{
return (pthread_cond_broadcast(pCond) == 0);
PulseEvent(*pCond);
return rtsTrue;
}
rtsBool
signalCondVar ( CondVar* pCond )
{
return (pthread_cond_signal(pCond) == 0);
SetEvent(*pCond);
return rtsTrue;
}
rtsBool
waitCondVar ( CondVar* pCond, MutexVar* pMut )
{
return (pthread_cond_wait(pCond,pMut) == 0);
ReleaseMutex(*pMut);
WaitForSingleObject(*pCond, INFINITE);
/* Hmm..use WaitForMultipleObjects() ? */
WaitForSingleObject(*pMut, INFINITE);
return rtsTrue;
}
void shutdownThread()
{
pthread_exit(NULL);
_endthreadex(0);
}
static unsigned __stdcall startProcWrapper(void* pReal);
static unsigned __stdcall startProcWrapper(void* pReal)
{
((void (*)(void*))pReal)(NULL);
return 0;
}
int createOSThread ( OSThreadId* pId, void *(*startProc)(void*))
{
return pthread_create(pId, NULL, startProc, NULL);
return _beginthreadex ( NULL, /* default security attributes */
0,
startProcWrapper,
(void*)startProc,
0,
(unsigned*)pId);
}
OSThreadId osThreadId()
{
return pthread_self();
return GetCurrentThreadId();
}
void initMutexVar (MutexVar* pMut)
{
pthread_mutex_init(pMut);
HANDLE h = CreateMutex ( NULL, /* default sec. attributes */
FALSE, /* not owned => initially signalled */
NULL
);
*pMut = h;
return;
}
......
......@@ -23,7 +23,7 @@ typedef pthread_t OSThreadId;
#include <windows.h>
typedef HANDLE CondVar;
typedef HANDLE MutexVar;
typedef HANDLE OSThreadId;
typedef DWORD OSThreadId;
#define INIT_MUTEX_VAR 0
#define INIT_COND_VAR 0
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment