From 61e8984d7aaaada398c84bdd60d33bcba2c940e5 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Mon, 23 Nov 1998 00:14:12 +0000 Subject: [PATCH] Add basic NT thread support. --- include/lthread.h | 36 +++++++ libraries/liblthread/liblthread.dsp | 137 ++++++++++++++++++++++++ libraries/liblthread/liblthread.dsw | 29 ++++++ libraries/liblthread/rdwr.c | 1 + libraries/liblthread/thread.c | 155 ++++++++++++++++++++++++++++ 5 files changed, 358 insertions(+) create mode 100644 libraries/liblthread/liblthread.dsp create mode 100644 libraries/liblthread/liblthread.dsw diff --git a/include/lthread.h b/include/lthread.h index b97398dd08..3485406d93 100644 --- a/include/lthread.h +++ b/include/lthread.h @@ -182,6 +182,42 @@ typedef struct lwpcv { LDAP_END_DECL +#elif HAVE_NT_THREADS + +#include +#include + +typedef void (*VFP)(void*); + +/* thread attributes and thread type */ +typedef int pthread_attr_t; +typedef HANDLE pthread_t; + +/* default attr states */ +#define pthread_mutexattr_default NULL +#define pthread_condattr_default NULL + +/* thread state - joinable or not */ +#define PTHREAD_CREATE_JOINABLE 0 +#define PTHREAD_CREATE_DETACHED 0 +/* thread scope - who is in scheduling pool */ +#define PTHREAD_SCOPE_PROCESS 0 +#define PTHREAD_SCOPE_SYSTEM 0 + +/* mutex attributes and mutex type */ +typedef int pthread_mutexattr_t; +typedef HANDLE pthread_mutex_t; + +/* mutex and condition variable scope - process or system */ +#define PTHREAD_SHARE_PRIVATE USYNC_THREAD +#define PTHREAD_SHARE_PROCESS USYNC_PROCESS + +/* condition variable attributes and condition variable type */ +typedef int pthread_condattr_t; +typedef HANDLE pthread_cond_t; +typedef int any_t; + + #else /*********************************** diff --git a/libraries/liblthread/liblthread.dsp b/libraries/liblthread/liblthread.dsp new file mode 100644 index 0000000000..c5ab6cdf6a --- /dev/null +++ b/libraries/liblthread/liblthread.dsp @@ -0,0 +1,137 @@ +# Microsoft Developer Studio Project File - Name="liblthread" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 5.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Static Library" 0x0104 + +CFG=liblthread - Win32 MT Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "liblthread.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "liblthread.mak" CFG="liblthread - Win32 MT Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "liblthread - Win32 Release" (based on "Win32 (x86) Static Library") +!MESSAGE "liblthread - Win32 Debug" (based on "Win32 (x86) Static Library") +!MESSAGE "liblthread - Win32 MT Debug" (based on "Win32 (x86) Static Library") +!MESSAGE "liblthread - Win32 MT Release" (based on\ + "Win32 (x86) Static Library") +!MESSAGE + +# Begin Project +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe + +!IF "$(CFG)" == "liblthread - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "..\Release" +# PROP Intermediate_Dir "Release\" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /W3 /GX /O2 /I "..\..\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo /out:"..\Release\olthread32.lib" + +!ELSEIF "$(CFG)" == "liblthread - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "..\Debug" +# PROP Intermediate_Dir "Debug" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /W3 /GX /Z7 /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo /out:"..\Debug\olthread32.lib" + +!ELSEIF "$(CFG)" == "liblthread - Win32 MT Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "MT Debug" +# PROP BASE Intermediate_Dir "MT Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "..\Debug" +# PROP Intermediate_Dir "Debug\MT" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /Z7 /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MTd /W3 /GX /Z7 /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo /out:"..\Debug\olthread32.lib" +# ADD LIB32 /nologo /out:"..\Debug\olthread32mt.lib" + +!ELSEIF "$(CFG)" == "liblthread - Win32 MT Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "MT Release" +# PROP BASE Intermediate_Dir "MT Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "..\Release" +# PROP Intermediate_Dir "Release\MT" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /I "..\..\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo /out:"..\Release\olthread32.lib" +# ADD LIB32 /nologo /out:"..\Release\olthread32mt.lib" + +!ENDIF + +# Begin Target + +# Name "liblthread - Win32 Release" +# Name "liblthread - Win32 Debug" +# Name "liblthread - Win32 MT Debug" +# Name "liblthread - Win32 MT Release" +# Begin Source File + +SOURCE=.\rdwr.c +# End Source File +# Begin Source File + +SOURCE=.\stack.c +# End Source File +# Begin Source File + +SOURCE=.\thread.c +# End Source File +# End Target +# End Project diff --git a/libraries/liblthread/liblthread.dsw b/libraries/liblthread/liblthread.dsw new file mode 100644 index 0000000000..ee14c84283 --- /dev/null +++ b/libraries/liblthread/liblthread.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 5.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "liblthread"=.\liblthread.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/libraries/liblthread/rdwr.c b/libraries/liblthread/rdwr.c index f1053440c2..6611bb30c9 100644 --- a/libraries/liblthread/rdwr.c +++ b/libraries/liblthread/rdwr.c @@ -21,6 +21,7 @@ #include #include + #include #include diff --git a/libraries/liblthread/thread.c b/libraries/liblthread/thread.c index cdf4414428..af2a14eb88 100644 --- a/libraries/liblthread/thread.c +++ b/libraries/liblthread/thread.c @@ -469,6 +469,161 @@ pthread_cond_broadcast( pthread_cond_t *cv ) } +#elif defined( HAVE_NT_MULTITHREADS ) + +#include +#include + +int +pthread_attr_init( pthread_attr_t *attr ) +{ + *attr = 0; + return( 0 ); +} + +int +pthread_attr_destroy( pthread_attr_t *attr ) +{ + return( 0 ); +} + +int +pthread_attr_getdetachstate( pthread_attr_t *attr, int *detachstate ) +{ + *detachstate = *attr; + return( 0 ); +} + +int +pthread_attr_setdetachstate( pthread_attr_t *attr, int detachstate ) +{ + *attr = detachstate; + return( 0 ); +} + +int +pthread_create( + pthread_t *tid, + pthread_attr_t *attr, + VFP func, + void *arg +) +{ + *tid = (pthread_t)_beginthread( (void *) func, 0, arg ); + return ( (unsigned long)*tid == -1 ? -1 : 0 ); +} + +void +pthread_yield() +{ + +} + +void +pthread_exit( void ) +{ + _endthread( ); +} + +void +pthread_join( pthread_t tid, int *pStatus ) +{ + DWORD status; + status = WaitForSingleObject( tid, INFINITE ); + if ( pStatus != NULL) + { + if ( status != WAIT_FAILED ) + *pStatus = 0; + else + *pStatus = WAIT_ABANDONED; + } +} + + +void +pthread_kill( pthread_t tid, int sig ) +{ + return; +} + + +int +pthread_mutex_init( pthread_mutex_t *mp, pthread_mutexattr_t *attr ) +{ + *mp = CreateMutex( NULL, 0, NULL ); + return ( 0 ); +} + +int +pthread_mutex_destroy( pthread_mutex_t *mp ) +{ + CloseHandle( *mp ); + return ( 0 ); +} + +int +pthread_mutex_lock( pthread_mutex_t *mp ) +{ + WaitForSingleObject( *mp, INFINITE ); + return ( 0 ); +} + +int +pthread_mutex_unlock( pthread_mutex_t *mp ) +{ + ReleaseMutex( *mp ); + return ( 0 ); +} + +int +pthread_mutex_trylock( pthread_mutex_t *mp ) +{ + DWORD status; + + status = WaitForSingleObject( *mp, 0 ); + if ( (status == WAIT_FAILED) || (status == WAIT_TIMEOUT) ) + return 0; + else + return 1; +} + +int +pthread_cond_init( pthread_cond_t *cv, pthread_condattr_t *attr ) +{ + *cv = CreateEvent( NULL, FALSE, FALSE, NULL ); + return( 0 ); +} + +int +pthread_cond_destroy( pthread_cond_t *cv ) +{ + CloseHandle( *cv ); + return( 0 ); +} + +int +pthread_cond_wait( pthread_cond_t *cv, pthread_mutex_t *mp ) +{ + ReleaseMutex( *mp ); + WaitForSingleObject( *cv, INFINITE ); + WaitForSingleObject( *mp, INFINITE ); + return( 0 ); +} + +int +pthread_cond_signal( pthread_cond_t *cv ) +{ + SetEvent( *cv ); + return( 0 ); +} + +int +pthread_cond_broadcast( pthread_cond_t *cv ) +{ + SetEvent( *cv ); + return( 0 ); +} + #else /*********************************************************************** -- 2.39.5