mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-01-18 11:05:48 +08:00
Add basic NT thread support.
This commit is contained in:
parent
dbb981f96e
commit
61e8984d7a
@ -182,6 +182,42 @@ typedef struct lwpcv {
|
||||
|
||||
LDAP_END_DECL
|
||||
|
||||
#elif HAVE_NT_THREADS
|
||||
|
||||
#include <windows.h>
|
||||
#include <process.h>
|
||||
|
||||
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
|
||||
|
||||
/***********************************
|
||||
|
137
libraries/liblthread/liblthread.dsp
Normal file
137
libraries/liblthread/liblthread.dsp
Normal file
@ -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
|
29
libraries/liblthread/liblthread.dsw
Normal file
29
libraries/liblthread/liblthread.dsw
Normal file
@ -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>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <portable.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <lthread.h>
|
||||
#include <lthread_rdwr.h>
|
||||
|
||||
|
@ -469,6 +469,161 @@ pthread_cond_broadcast( pthread_cond_t *cv )
|
||||
}
|
||||
|
||||
|
||||
#elif defined( HAVE_NT_MULTITHREADS )
|
||||
|
||||
#include <process.h>
|
||||
#include <winsock2.h>
|
||||
|
||||
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
|
||||
|
||||
/***********************************************************************
|
||||
|
Loading…
Reference in New Issue
Block a user