From: Gurusamy Sarathy Date: Mon, 13 Oct 1997 23:18:38 +0000 (+0000) Subject: Initial merge of win32 threads patch. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=059e4e88d1fa9d5d262346f1d85723e36d59494c;p=p5sagit%2Fp5-mst-13.2.git Initial merge of win32 threads patch. p4raw-id: //depot/win32/perl@123 --- diff --git a/embed.h b/embed.h index a824b0a..9596eb7 100644 --- a/embed.h +++ b/embed.h @@ -1088,6 +1088,7 @@ #define taint_env Perl_taint_env #define taint_proper Perl_taint_proper #define thisexpr Perl_thisexpr +#define thr_key Perl_thr_key #define timesbuf Perl_timesbuf #define tokenbuf Perl_tokenbuf #define too_few_arguments Perl_too_few_arguments @@ -1298,6 +1299,8 @@ #define multiline (curinterp->Imultiline) #define mystrk (curinterp->Imystrk) #define nrs (curinterp->Inrs) +#define nthreads (curinterp->Inthreads) +#define nthreads_cond (curinterp->Inthreads_cond) #define ofmt (curinterp->Iofmt) #define ofs (curinterp->Iofs) #define ofslen (curinterp->Iofslen) @@ -1347,6 +1350,7 @@ #define sv_root (curinterp->Isv_root) #define tainted (curinterp->Itainted) #define tainting (curinterp->Itainting) +#define threads_mutex (curinterp->Ithreads_mutex) #define tmps_floor (curinterp->Itmps_floor) #define tmps_ix (curinterp->Itmps_ix) #define tmps_max (curinterp->Itmps_max) @@ -1449,6 +1453,8 @@ #define Imultiline multiline #define Imystrk mystrk #define Inrs nrs +#define Inthreads nthreads +#define Inthreads_cond nthreads_cond #define Iofmt ofmt #define Iofs ofs #define Iofslen ofslen @@ -1498,6 +1504,7 @@ #define Isv_root sv_root #define Itainted tainted #define Itainting tainting +#define Ithreads_mutex threads_mutex #define Itmps_floor tmps_floor #define Itmps_ix tmps_ix #define Itmps_max tmps_max @@ -1609,6 +1616,8 @@ #define multiline Perl_multiline #define mystrk Perl_mystrk #define nrs Perl_nrs +#define nthreads Perl_nthreads +#define nthreads_cond Perl_nthreads_cond #define ofmt Perl_ofmt #define ofs Perl_ofs #define ofslen Perl_ofslen @@ -1656,6 +1665,7 @@ #define sv_objcount Perl_sv_objcount #define sv_root Perl_sv_root #define tainted Perl_tainted +#define threads_mutex Perl_threads_mutex #define tmps_floor Perl_tmps_floor #define tmps_ix Perl_tmps_ix #define tmps_max Perl_tmps_max diff --git a/global.sym b/global.sym index 023cd6a..d99ed57 100644 --- a/global.sym +++ b/global.sym @@ -236,6 +236,7 @@ sv_no sv_undef sv_yes thisexpr +thr_key timesbuf tokenbuf uid diff --git a/interp.sym b/interp.sym index 00eee65..0994d23 100644 --- a/interp.sym +++ b/interp.sym @@ -89,6 +89,8 @@ minus_p multiline mystrk nrs +nthreads_cond +nthreads ofmt ofs ofslen @@ -138,6 +140,7 @@ sv_root sv_arenaroot tainted tainting +threads_mutex tmps_floor tmps_ix tmps_max diff --git a/perl.c b/perl.c index 4897da0..e654675 100644 --- a/perl.c +++ b/perl.c @@ -122,7 +122,7 @@ register PerlInterpreter *sv_interp; if (!linestr) { #ifdef USE_THREADS INIT_THREADS; - New(53, thr, 1, struct thread); + Newz(53, thr, 1, struct thread); MUTEX_INIT(&malloc_mutex); MUTEX_INIT(&sv_mutex); MUTEX_INIT(&eval_mutex); @@ -142,11 +142,28 @@ register PerlInterpreter *sv_interp; thr->private = 0; thr->tid = 0; #else +#ifdef WIN32 + DuplicateHandle(GetCurrentProcess(), + GetCurrentThread(), + GetCurrentProcess(), + &self, + 0, + FALSE, + DUPLICATE_SAME_ACCESS); + /* XXX TlsAlloc() should probably be done in the DLL entry + * point also. + */ + if ((thr_key = TlsAlloc()) == TLS_OUT_OF_INDEXES) + croak("panic: pthread_key_create"); + if (TlsSetValue(thr_key, (LPVOID) thr) != TRUE) + croak("panic: pthread_setspecific"); +#else self = pthread_self(); if (pthread_key_create(&thr_key, 0)) croak("panic: pthread_key_create"); if (pthread_setspecific(thr_key, (void *) thr)) croak("panic: pthread_setspecific"); +#endif /* WIN32 */ #endif /* FAKE_THREADS */ #endif /* USE_THREADS */ diff --git a/perl.h b/perl.h index 6af9ff8..fdd5ef6 100644 --- a/perl.h +++ b/perl.h @@ -67,10 +67,17 @@ register struct op *op asm(stringify(OP_IN_REGISTER)); #ifdef FAKE_THREADS #include "fakethr.h" #else +#ifdef WIN32 +/*typedef CRITICAL_SECTION perl_mutex;*/ +typedef HANDLE perl_mutex; +typedef HANDLE perl_cond; +typedef DWORD perl_key; +#else #include typedef pthread_mutex_t perl_mutex; typedef pthread_cond_t perl_cond; typedef pthread_key_t perl_key; +#endif /* WIN32 */ #endif /* FAKE_THREADS */ #endif /* USE_THREADS */ diff --git a/thread.h b/thread.h index f379f6b..ab01d2a 100644 --- a/thread.h +++ b/thread.h @@ -39,6 +39,89 @@ typedef struct thread *perl_thread; } STMT_END #define COND_DESTROY(c) #else + +#ifdef WIN32 + +typedef HANDLE perl_thread; + +/* XXX Critical Sections used instead of mutexes: lightweight, + * but can't be communicated to child processes, and can't get + * HANDLE to it for use elsewhere + */ +/* +#define MUTEX_INIT(m) InitializeCriticalSection(m) +#define MUTEX_LOCK(m) EnterCriticalSection(m) +#define MUTEX_UNLOCK(m) LeaveCriticalSection(m) +#define MUTEX_DESTROY(m) DeleteCriticalSection(m) +*/ + +#define MUTEX_INIT(m) \ + STMT_START { \ + if ((*(m) = CreateMutex(NULL,FALSE,NULL)) == NULL) \ + croak("panic: MUTEX_INIT"); \ + } STMT_END +#define MUTEX_LOCK(m) \ + STMT_START { \ + if (WaitForSingleObject(*(m),INFINITE) == WAIT_FAILED) \ + croak("panic: MUTEX_LOCK"); \ + } STMT_END +#define MUTEX_UNLOCK(m) \ + STMT_START { \ + if (ReleaseMutex(*(m)) == 0) \ + croak("panic: MUTEX_UNLOCK"); \ + } STMT_END +#define MUTEX_DESTROY(m) \ + STMT_START { \ + if (CloseHandle(*(m)) == 0) \ + croak("panic: MUTEX_DESTROY"); \ + } STMT_END + +#define COND_INIT(c) \ + STMT_START { \ + if ((*(c) = CreateEvent(NULL,TRUE,FALSE,NULL)) == NULL) \ + croak("panic: COND_INIT"); \ + } STMT_END +#define COND_SIGNAL(c) \ + STMT_START { \ + if (PulseEvent(*(c)) == 0) \ + croak("panic: COND_SIGNAL (%ld)",GetLastError()); \ + } STMT_END +#define COND_BROADCAST(c) \ + STMT_START { \ + if (PulseEvent(*(c)) == 0) \ + croak("panic: COND_BROADCAST"); \ + } STMT_END +/* #define COND_WAIT(c, m) \ + STMT_START { \ + if (WaitForSingleObject(*(c),INFINITE) == WAIT_FAILED) \ + croak("panic: COND_WAIT"); \ + } STMT_END +*/ +#define COND_WAIT(c, m) \ + STMT_START { \ + if (SignalObjectAndWait(*(m),*(c),INFINITE,FALSE) == WAIT_FAILED)\ + croak("panic: COND_WAIT"); \ + else \ + MUTEX_LOCK(m); \ + } STMT_END +#define COND_DESTROY(c) \ + STMT_START { \ + if (CloseHandle(*(c)) == 0) \ + croak("panic: COND_DESTROY"); \ + } STMT_END + +#define DETACH(t) \ + STMT_START { \ + if (CloseHandle((t)->Tself) == 0) \ + croak("panic: DETACH"); \ + } STMT_END + +#define THR ((struct thread *) TlsGetValue(thr_key)) +#define pthread_getspecific(k) TlsGetValue(k) +#define pthread_setspecific(k,v) (TlsSetValue(k,v) == 0) + +#else /* !WIN32 */ + /* POSIXish threads */ typedef pthread_t perl_thread; #ifdef OLD_PTHREADS_API @@ -80,6 +163,7 @@ struct thread *getTHR _((void)); #else #define THR ((struct thread *) pthread_getspecific(thr_key)) #endif /* OLD_PTHREADS_API */ +#endif /* WIN32 */ #define dTHR struct thread *thr = THR #endif /* FAKE_THREADS */ diff --git a/win32/Makefile b/win32/Makefile index 9e4437f..be954f0 100644 --- a/win32/Makefile +++ b/win32/Makefile @@ -49,7 +49,8 @@ RUNTIME = -MD !ENDIF INCLUDES = -I.\include -I. -I.. #PCHFLAGS = -Fp"$(INTDIR)/modules.pch" -YX -DEFINES = -DWIN32 -D_CONSOLE -DPERLDLL +DEFINES = -DWIN32 -D_CONSOLE -DUSE_THREADS -D_WIN32_WINNT=0x400 +LOCDEFS = -DPERLDLL SUBSYS = console !IF "$(RUNTIME)" == "-MD" @@ -82,7 +83,7 @@ LIBFILES = oldnames.lib kernel32.lib user32.lib gdi32.lib \ oleaut32.lib netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib \ version.lib odbc32.lib odbccp32.lib -CFLAGS = -nologo -W3 $(INCLUDES) $(DEFINES) $(PCHFLAGS) $(OPTIMIZE) +CFLAGS = -nologo -W3 $(INCLUDES) $(DEFINES) $(LOCDEFS) $(PCHFLAGS) $(OPTIMIZE) LINK_FLAGS = -nologo $(LIBFILES) $(LINK_DBG) -machine:I386 OBJOUT_FLAG = -Fo @@ -226,6 +227,7 @@ CORE_H = ..\av.h \ ..\regexp.h \ ..\scope.h \ ..\sv.h \ + ..\thread.h \ ..\unixish.h \ ..\util.h \ ..\XSUB.h \ @@ -236,7 +238,7 @@ CORE_H = ..\av.h \ .\include\sys\socket.h \ .\win32.h -EXTENSIONS=DynaLoader Socket IO Fcntl Opcode SDBM_File +EXTENSIONS=DynaLoader Socket IO Fcntl Opcode SDBM_File attrs DYNALOADER=$(EXTDIR)\DynaLoader\DynaLoader SOCKET=$(EXTDIR)\Socket\Socket @@ -244,12 +246,14 @@ FCNTL=$(EXTDIR)\Fcntl\Fcntl OPCODE=$(EXTDIR)\Opcode\Opcode SDBM_FILE=$(EXTDIR)\SDBM_File\SDBM_File IO=$(EXTDIR)\IO\IO +ATTRS=$(EXTDIR)\attrs\attrs SOCKET_DLL=..\lib\auto\Socket\Socket.dll FCNTL_DLL=..\lib\auto\Fcntl\Fcntl.dll OPCODE_DLL=..\lib\auto\Opcode\Opcode.dll SDBM_FILE_DLL=..\lib\auto\SDBM_File\SDBM_File.dll IO_DLL=..\lib\auto\IO\IO.dll +ATTRS_DLL=..\lib\auto\attrs\attrs.dll STATICLINKMODULES=DynaLoader DYNALOADMODULES= \ @@ -257,7 +261,8 @@ DYNALOADMODULES= \ $(FCNTL_DLL) \ $(OPCODE_DLL) \ $(SDBM_FILE_DLL)\ - $(IO_DLL) + $(IO_DLL) \ + $(ATTRS_DLL) POD2HTML=$(PODDIR)\pod2html POD2MAN=$(PODDIR)\pod2man @@ -293,7 +298,7 @@ config.w32 : $(CFGSH_TMPL) ..\config.sh : config.w32 $(MINIPERL) config_sh.PL $(MINIPERL) -I..\lib config_sh.PL "INST_DRV=$(INST_DRV)" \ - "INST_TOP=$(INST_TOP)" "cc=$(CC)" "ccflags=$(RUNTIME) -DWIN32" \ + "INST_TOP=$(INST_TOP)" "cc=$(CC)" "ccflags=$(OPTIMIZE) $(DEFINES)" \ "cf_email=$(EMAIL)" "libs=$(LIBFILES)" "incpath=$(CCINCDIR)" \ "libpth=$(CCLIBDIR)" "libc=$(LIBC)" \ config.w32 > ..\config.sh @@ -372,7 +377,13 @@ $(DYNALOADER).c: $(MINIPERL) $(EXTDIR)\DynaLoader\dl_win32.xs $(CONFIGPM) $(EXTDIR)\DynaLoader\dl_win32.xs: dl_win32.xs copy dl_win32.xs $(EXTDIR)\DynaLoader\dl_win32.xs -$(IO_DLL): $(PERLEXE) $(CONFIGPM) $(IO).xs +$(ATTRS_DLL): $(PERLEXE) $(ATTRS).xs + cd $(EXTDIR)\$(*B) + ..\..\miniperl -I..\..\lib Makefile.PL INSTALLDIRS=perl + $(MAKE) + cd ..\..\win32 + +$(IO_DLL): $(PERLEXE) $(IO).xs cd $(EXTDIR)\$(*B) ..\..\miniperl -I..\..\lib Makefile.PL INSTALLDIRS=perl $(MAKE) @@ -396,7 +407,7 @@ $(OPCODE_DLL): $(PERLEXE) $(OPCODE).xs $(MAKE) cd ..\..\win32 -$(SOCKET_DLL): $(SOCKET).xs $(PERLEXE) +$(SOCKET_DLL): $(PERLEXE) $(SOCKET).xs cd $(EXTDIR)\$(*B) ..\..\miniperl -I..\..\lib Makefile.PL INSTALLDIRS=perl $(MAKE) @@ -428,9 +439,9 @@ distclean: clean $(PERLIMPLIB) ..\miniperl.lib $(MINIMOD) -del /f *.def *.map -del /f $(SOCKET_DLL) $(IO_DLL) $(SDBM_FILE_DLL) $(FCNTL_DLL) \ - $(OPCODE_DLL) + $(OPCODE_DLL) $(ATTRS_DLL) -del /f $(SOCKET).c $(IO).c $(SDBM_FILE).c $(FCNTL).c $(OPCODE).c \ - $(DYNALOADER).c + $(DYNALOADER).c $(ATTRS).c -del /f $(PODDIR)\*.html -del /f $(PODDIR)\*.bat -del /f ..\config.sh ..\splittree.pl perlmain.c dlutils.c \ diff --git a/win32/makedef.pl b/win32/makedef.pl index 04e6fd9..2ef1bb5 100644 --- a/win32/makedef.pl +++ b/win32/makedef.pl @@ -108,7 +108,6 @@ Perl_setenv_getix Perl_skipspace Perl_sublex_done Perl_sublex_start -Perl_sv_peek Perl_sv_ref Perl_sv_setptrobj Perl_timesbuf @@ -136,11 +135,7 @@ Perl_my_memcmp Perl_my_memset Perl_cshlen Perl_cshname -Perl_condpair_magic -Perl_magic_mutexfree Perl_opsave -Perl_unlock_condpair -Perl_vtbl_mutex !END!OF!SKIP! # All symbols have a Perl_ prefix because that's what embed.h diff --git a/win32/makefile.mk b/win32/makefile.mk index b91fffc..1deb30d 100644 --- a/win32/makefile.mk +++ b/win32/makefile.mk @@ -60,7 +60,8 @@ IMPLIB = implib RUNTIME = -D_RTLDLL INCLUDES = -I.\include -I. -I.. -I$(CCINCDIR) #PCHFLAGS = -H -H$(INTDIR)\bcmoduls.pch -DEFINES = -DWIN32 -DPERLDLL +DEFINES = -DWIN32 -DUSE_THREADS -D_WIN32_WINNT=0x0400 +LOCDEFS = -DPERLDLL SUBSYS = console LIBC = cw32mti.lib LIBFILES = import32.lib $(LIBC) odbc32.lib odbccp32.lib @@ -75,7 +76,7 @@ OPTIMIZE = -O $(RUNTIME) LINK_DBG = .ENDIF -CFLAGS = -w -tWM -tWD $(INCLUDES) $(DEFINES) $(PCHFLAGS) $(OPTIMIZE) +CFLAGS = -w -tWM -tWD $(INCLUDES) $(DEFINES) $(LOCDEFS) $(PCHFLAGS) $(OPTIMIZE) LINK_FLAGS = $(LINK_DBG) -L$(CCLIBDIR) OBJOUT_FLAG = -o @@ -92,7 +93,8 @@ RUNTIME = -MD .ENDIF INCLUDES = -I.\include -I. -I.. #PCHFLAGS = -Fp$(INTDIR)\vcmoduls.pch -YX -DEFINES = -DWIN32 -D_CONSOLE -DPERLDLL +DEFINES = -DWIN32 -D_CONSOLE -DUSE_THREADS -D_WIN32_WINNT=0x0400 +LOCDEFS = -DPERLDLL SUBSYS = console .IF "$(RUNTIME)" == "-MD" @@ -125,7 +127,7 @@ LIBFILES = oldnames.lib kernel32.lib user32.lib gdi32.lib \ oleaut32.lib netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib \ version.lib odbc32.lib odbccp32.lib -CFLAGS = -nologo -W3 $(INCLUDES) $(DEFINES) $(PCHFLAGS) $(OPTIMIZE) +CFLAGS = -nologo -W3 $(INCLUDES) $(DEFINES) $(LOCDEFS) $(PCHFLAGS) $(OPTIMIZE) LINK_FLAGS = -nologo $(LIBFILES) $(LINK_DBG) -machine:I386 OBJOUT_FLAG = -Fo @@ -176,7 +178,7 @@ GLOBEXE=..\perlglob.exe CONFIGPM=..\lib\Config.pm MINIMOD=..\lib\ExtUtils\Miniperl.pm -PL2BAT=bin\PL2BAT.BAT +PL2BAT=bin\pl2bat.pl GLOBBAT = perlglob.bat .IF "$(CCTYPE)" == "BORLAND" @@ -292,6 +294,7 @@ CORE_H = ..\av.h \ ..\regexp.h \ ..\scope.h \ ..\sv.h \ + ..\thread.h \ ..\unixish.h \ ..\util.h \ ..\XSUB.h \ @@ -303,7 +306,7 @@ CORE_H = ..\av.h \ .\win32.h -EXTENSIONS=DynaLoader Socket IO Fcntl Opcode SDBM_File +EXTENSIONS=DynaLoader Socket IO Fcntl Opcode SDBM_File attrs DYNALOADER=$(EXTDIR)\DynaLoader\DynaLoader SOCKET=$(EXTDIR)\Socket\Socket @@ -311,12 +314,14 @@ FCNTL=$(EXTDIR)\Fcntl\Fcntl OPCODE=$(EXTDIR)\Opcode\Opcode SDBM_FILE=$(EXTDIR)\SDBM_File\SDBM_File IO=$(EXTDIR)\IO\IO +ATTRS=$(EXTDIR)\attrs\attrs SOCKET_DLL=..\lib\auto\Socket\Socket.dll FCNTL_DLL=..\lib\auto\Fcntl\Fcntl.dll OPCODE_DLL=..\lib\auto\Opcode\Opcode.dll SDBM_FILE_DLL=..\lib\auto\SDBM_File\SDBM_File.dll IO_DLL=..\lib\auto\IO\IO.dll +ATTRS_DLL=..\lib\auto\attrs\attrs.dll STATICLINKMODULES=DynaLoader DYNALOADMODULES= \ @@ -324,7 +329,8 @@ DYNALOADMODULES= \ $(FCNTL_DLL) \ $(OPCODE_DLL) \ $(SDBM_FILE_DLL)\ - $(IO_DLL) + $(IO_DLL) \ + $(ATTRS_DLL) POD2HTML=$(PODDIR)\pod2html POD2MAN=$(PODDIR)\pod2man @@ -366,7 +372,7 @@ config.w32 : $(CFGSH_TMPL) ..\config.sh : config.w32 $(MINIPERL) config_sh.PL $(MINIPERL) -I..\lib config_sh.PL "INST_DRV=$(INST_DRV)" \ - "INST_TOP=$(INST_TOP)" "cc=$(CC)" "ccflags=$(RUNTIME) -DWIN32" \ + "INST_TOP=$(INST_TOP)" "cc=$(CC)" "ccflags=$(OPTIMIZE) $(DEFINES)" \ "cf_email=$(EMAIL)" "libs=$(LIBFILES:f)" \ "libpth=$(strip $(CCLIBDIR) $(LIBFILES:d))" "libc=$(LIBC)" \ config.w32 > ..\config.sh @@ -472,7 +478,12 @@ $(DYNALOADER).c: $(MINIPERL) $(EXTDIR)\DynaLoader\dl_win32.xs $(CONFIGPM) $(EXTDIR)\DynaLoader\dl_win32.xs: dl_win32.xs copy dl_win32.xs $(EXTDIR)\DynaLoader\dl_win32.xs -$(IO_DLL): $(PERLEXE) $(CONFIGPM) $(IO).xs +$(ATTRS_DLL): $(PERLEXE) $(ATTRS).xs + cd $(EXTDIR)\$(*B) && \ + ..\..\miniperl -I..\..\lib Makefile.PL INSTALLDIRS=perl + cd $(EXTDIR)\$(*B) && $(MAKE) + +$(IO_DLL): $(PERLEXE) $(IO).xs cd $(EXTDIR)\$(*B) && \ ..\..\miniperl -I..\..\lib Makefile.PL INSTALLDIRS=perl cd $(EXTDIR)\$(*B) && $(MAKE) @@ -492,7 +503,7 @@ $(OPCODE_DLL): $(PERLEXE) $(OPCODE).xs ..\..\miniperl -I..\..\lib Makefile.PL INSTALLDIRS=perl cd $(EXTDIR)\$(*B) && $(MAKE) -$(SOCKET_DLL): $(SOCKET).xs $(PERLEXE) +$(SOCKET_DLL): $(PERLEXE) $(SOCKET).xs cd $(EXTDIR)\$(*B) && \ ..\..\miniperl -I..\..\lib Makefile.PL INSTALLDIRS=perl cd $(EXTDIR)\$(*B) && $(MAKE) @@ -514,9 +525,9 @@ distclean: clean $(PERLIMPLIB) ..\miniperl.lib $(MINIMOD) -del /f *.def *.map -del /f $(SOCKET_DLL) $(IO_DLL) $(SDBM_FILE_DLL) $(FCNTL_DLL) \ - $(OPCODE_DLL) + $(OPCODE_DLL) $(ATTRS_DLL) -del /f $(SOCKET).c $(IO).c $(SDBM_FILE).c $(FCNTL).c $(OPCODE).c \ - $(DYNALOADER).c + $(DYNALOADER).c $(ATTRS).c -del /f $(PODDIR)\*.html -del /f $(PODDIR)\*.bat -cd $(EXTDIR) && del /s *.lib *.def *.map *.bs Makefile *.obj pm_to_blib diff --git a/win32/pod.mak b/win32/pod.mak index 538cfa3..9881ed8 100644 --- a/win32/pod.mak +++ b/win32/pod.mak @@ -9,7 +9,7 @@ POD2HTML = pod2html \ all: $(CONVERTERS) html PERL = ..\miniperl.exe -PL2BAT = ..\win32\bin\pl2bat.bat +PL2BAT = ..\win32\bin\pl2bat.pl POD = \ perl.pod \