From: Gurusamy Sarathy Date: Thu, 16 Oct 1997 22:26:07 +0000 (+0000) Subject: Merge changes to Thread and add makefile fixups to accomodate Thread X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a98bd6f47916086cf27b0923091768d4e675e0b1;p=p5sagit%2Fp5-mst-13.2.git Merge changes to Thread and add makefile fixups to accomodate Thread build. Once again, builds and runs all Thread tests using either compiler. p4raw-id: //depot/win32/perl@144 --- diff --git a/embed.h b/embed.h index 5f3b765..f3601e8 100644 --- a/embed.h +++ b/embed.h @@ -1090,6 +1090,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 diff --git a/ext/Thread/Thread.xs b/ext/Thread/Thread.xs index 3dc2516..c4e87a3 100644 --- a/ext/Thread/Thread.xs +++ b/ext/Thread/Thread.xs @@ -2,12 +2,25 @@ #include "perl.h" #include "XSUB.h" +#ifdef WIN32 +#define ssize_t int +#include +#define THR_RET_TYPE DWORD +#define THR_FUNC_TYPE THR_RET_TYPE WINAPI +#else +#define THR_RET_TYPE void * +#define THR_FUNC_TYPE THR_RET_TYPE +#endif + /* Magic signature for Thread's mg_private is "Th" */ #define Thread_MAGIC_SIGNATURE 0x5468 static U32 threadnum = 0; static int sig_pipe[2]; +static void remove_thread _((Thread t)); +static THR_FUNC_TYPE threadstart _((void *)); + static void remove_thread(t) Thread t; @@ -23,7 +36,8 @@ Thread t; MUTEX_UNLOCK(&threads_mutex); } -static void * + +static THR_FUNC_TYPE threadstart(arg) void *arg; { @@ -92,7 +106,11 @@ void *arg; * from our pthread_t structure to our struct thread, since we're * the only thread who can get at it anyway. */ +#ifdef WIN32 + if (TlsSetValue(thr_key, (void *) thr) == 0) +#else if (pthread_setspecific(thr_key, (void *) thr)) +#endif croak("panic: pthread_setspecific"); /* Only now can we use SvPEEK (which calls sv_newmortal which does dTHR) */ @@ -182,7 +200,7 @@ void *arg; croak("panic: illegal state %u at end of threadstart", ThrSTATE(thr)); /* NOTREACHED */ } - return (void *) returnav; /* Available for anyone to join with us */ + return (THR_RET_TYPE) returnav;/* Available for anyone to join with us */ /* unless we are detached in which case */ /* noone will see the value anyway. */ #endif @@ -199,7 +217,11 @@ char *class; Thread savethread; int i; SV *sv; +#ifndef WIN32 sigset_t fullmask, oldmask; +#else + DWORD junk; +#endif savethread = thr; sv = newSVpv("", 0); @@ -253,16 +275,22 @@ char *class; /* Get set... * Increment the global thread count. */ +#ifndef WIN32 sigfillset(&fullmask); if (sigprocmask(SIG_SETMASK, &fullmask, &oldmask) == -1) croak("panic: sigprocmask"); if (pthread_create(&self, NULL, threadstart, (void*) thr)) +#else + if ((self = CreateThread(NULL,0,threadstart,(void*)thr,0,&junk)) == 0) +#endif return NULL; /* XXX should clean up first */ /* Go */ MUTEX_UNLOCK(&thr->mutex); +#ifndef WIN32 if (sigprocmask(SIG_SETMASK, &oldmask, 0)) croak("panic: sigprocmask"); #endif +#endif sv = newSViv(thr->tid); sv_magic(sv, oursv, '~', 0, 0); SvMAGIC(sv)->mg_private = Thread_MAGIC_SIGNATURE; @@ -312,7 +340,12 @@ join(t) croak("can't join with thread"); /* NOTREACHED */ } +#ifdef WIN32 + if ((WaitForSingleObject(t->Tself,INFINITE) == WAIT_FAILED) + || (GetExitCodeThread(t->Tself,(LPDWORD)&av) == 0)) +#else if (pthread_join(t->Tself, (void **) &av)) +#endif croak("pthread_join failed"); /* Could easily speed up the following if necessary */ @@ -393,7 +426,11 @@ yield() pthread_yield(); #else #ifndef NO_SCHED_YIELD +#ifdef WIN32 + Sleep(0); /* same semantics as POSIX sched_yield() */ +#else sched_yield(); +#endif /* WIN32 */ #endif /* NO_SCHED_YIELD */ #endif /* OLD_PTHREADS_API */ diff --git a/interp.sym b/interp.sym index 1583ea2..4d2bfb9 100644 --- a/interp.sym +++ b/interp.sym @@ -89,6 +89,8 @@ minus_p multiline mystrk nrs +nthreads +nthreads_cond ofmt ofs ofslen @@ -139,6 +141,7 @@ sv_arenaroot tainted tainting thrsv +threads_mutex tmps_floor tmps_ix tmps_max diff --git a/perl.c b/perl.c index 2d94f4d..279e217 100644 --- a/perl.c +++ b/perl.c @@ -277,7 +277,6 @@ register PerlInterpreter *sv_interp; "perl_destruct: waiting for %d threads...\n", nthreads - 1)); for (t = thr->next; t != thr; t = t->next) { - MUTEX_LOCK(&threads_mutex); MUTEX_LOCK(&t->mutex); switch (ThrSTATE(t)) { AV *av; diff --git a/win32/Makefile b/win32/Makefile index 70cf2f0..19dce90 100644 --- a/win32/Makefile +++ b/win32/Makefile @@ -243,7 +243,7 @@ CORE_H = ..\av.h \ .\include\sys\socket.h \ .\win32.h -EXTENSIONS=DynaLoader Socket IO Fcntl Opcode SDBM_File attrs +EXTENSIONS=DynaLoader Socket IO Fcntl Opcode SDBM_File attrs Thread DYNALOADER=$(EXTDIR)\DynaLoader\DynaLoader SOCKET=$(EXTDIR)\Socket\Socket @@ -252,6 +252,7 @@ OPCODE=$(EXTDIR)\Opcode\Opcode SDBM_FILE=$(EXTDIR)\SDBM_File\SDBM_File IO=$(EXTDIR)\IO\IO ATTRS=$(EXTDIR)\attrs\attrs +THREAD=$(EXTDIR)\Thread\Thread SOCKET_DLL=..\lib\auto\Socket\Socket.dll FCNTL_DLL=..\lib\auto\Fcntl\Fcntl.dll @@ -259,6 +260,7 @@ 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 +THREAD_DLL=..\lib\auto\Thread\Thread.dll STATICLINKMODULES=DynaLoader DYNALOADMODULES= \ @@ -267,7 +269,8 @@ DYNALOADMODULES= \ $(OPCODE_DLL) \ $(SDBM_FILE_DLL)\ $(IO_DLL) \ - $(ATTRS_DLL) + $(ATTRS_DLL) \ + $(THREAD_DLL) POD2HTML=$(PODDIR)\pod2html POD2MAN=$(PODDIR)\pod2man @@ -388,6 +391,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 +$(THREAD_DLL): $(PERLEXE) $(THREAD).xs + cd $(EXTDIR)\$(*B) + ..\..\miniperl -I..\..\lib Makefile.PL INSTALLDIRS=perl + $(MAKE) + cd ..\..\win32 + $(ATTRS_DLL): $(PERLEXE) $(ATTRS).xs cd $(EXTDIR)\$(*B) ..\..\miniperl -I..\..\lib Makefile.PL INSTALLDIRS=perl @@ -450,9 +459,9 @@ distclean: clean $(PERLIMPLIB) ..\miniperl.lib $(MINIMOD) -del /f *.def *.map -del /f $(SOCKET_DLL) $(IO_DLL) $(SDBM_FILE_DLL) $(FCNTL_DLL) \ - $(OPCODE_DLL) $(ATTRS_DLL) + $(OPCODE_DLL) $(ATTRS_DLL) $(THREAD_DLL) -del /f $(SOCKET).c $(IO).c $(SDBM_FILE).c $(FCNTL).c $(OPCODE).c \ - $(DYNALOADER).c $(ATTRS).c + $(DYNALOADER).c $(ATTRS).c $(THREAD).c -del /f $(PODDIR)\*.html -del /f $(PODDIR)\*.bat -del /f ..\config.sh ..\splittree.pl perlmain.c dlutils.c \ diff --git a/win32/makefile.mk b/win32/makefile.mk index a8ab369..6a482ba 100644 --- a/win32/makefile.mk +++ b/win32/makefile.mk @@ -311,7 +311,7 @@ CORE_H = ..\av.h \ .\win32.h -EXTENSIONS=DynaLoader Socket IO Fcntl Opcode SDBM_File attrs +EXTENSIONS=DynaLoader Socket IO Fcntl Opcode SDBM_File attrs Thread DYNALOADER=$(EXTDIR)\DynaLoader\DynaLoader SOCKET=$(EXTDIR)\Socket\Socket @@ -320,6 +320,7 @@ OPCODE=$(EXTDIR)\Opcode\Opcode SDBM_FILE=$(EXTDIR)\SDBM_File\SDBM_File IO=$(EXTDIR)\IO\IO ATTRS=$(EXTDIR)\attrs\attrs +THREAD=$(EXTDIR)\Thread\Thread SOCKET_DLL=..\lib\auto\Socket\Socket.dll FCNTL_DLL=..\lib\auto\Fcntl\Fcntl.dll @@ -327,6 +328,7 @@ 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 +THREAD_DLL=..\lib\auto\Thread\Thread.dll STATICLINKMODULES=DynaLoader DYNALOADMODULES= \ @@ -335,7 +337,8 @@ DYNALOADMODULES= \ $(OPCODE_DLL) \ $(SDBM_FILE_DLL)\ $(IO_DLL) \ - $(ATTRS_DLL) + $(ATTRS_DLL) \ + $(THREAD_DLL) POD2HTML=$(PODDIR)\pod2html POD2MAN=$(PODDIR)\pod2man @@ -489,6 +492,11 @@ $(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 +$(THREAD_DLL): $(PERLEXE) $(THREAD).xs + cd $(EXTDIR)\$(*B) && \ + ..\..\miniperl -I..\..\lib Makefile.PL INSTALLDIRS=perl + cd $(EXTDIR)\$(*B) && $(MAKE) + $(ATTRS_DLL): $(PERLEXE) $(ATTRS).xs cd $(EXTDIR)\$(*B) && \ ..\..\miniperl -I..\..\lib Makefile.PL INSTALLDIRS=perl @@ -541,9 +549,9 @@ distclean: clean $(PERLIMPLIB) ..\miniperl.lib $(MINIMOD) -del /f *.def *.map -del /f $(SOCKET_DLL) $(IO_DLL) $(SDBM_FILE_DLL) $(FCNTL_DLL) \ - $(OPCODE_DLL) $(ATTRS_DLL) + $(OPCODE_DLL) $(ATTRS_DLL) $(THREAD_DLL) -del /f $(SOCKET).c $(IO).c $(SDBM_FILE).c $(FCNTL).c $(OPCODE).c \ - $(DYNALOADER).c $(ATTRS).c + $(DYNALOADER).c $(ATTRS).c $(THREAD).c -del /f $(PODDIR)\*.html -del /f $(PODDIR)\*.bat -del /f ..\config.sh ..\splittree.pl perlmain.c dlutils.c config.h.new