From: Gurusamy Sarathy Date: Tue, 29 Feb 2000 15:31:56 +0000 (+0000) Subject: more adjustments needed for change#5342 under use5005threads X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=06d860507700419d9cf04cbf3dc2f06c906c546d;p=p5sagit%2Fp5-mst-13.2.git more adjustments needed for change#5342 under use5005threads p4raw-link: @5342 on //depot/perl: ba869debd80c55cfae8e9d4de0991d62f9efcb9b p4raw-id: //depot/perl@5351 --- diff --git a/ext/Thread/Thread.xs b/ext/Thread/Thread.xs index 6cc1081..4b5e6db 100644 --- a/ext/Thread/Thread.xs +++ b/ext/Thread/Thread.xs @@ -98,7 +98,7 @@ threadstart(void *arg) DEBUG_S(PerlIO_printf(Perl_debug_log, "new thread %p waiting to start\n", thr)); - /* Don't call *anything* requiring dTHR until after SET_THR() */ + /* Don't call *anything* requiring dTHR until after PERL_SET_THX() */ /* * Wait until our creator releases us. If we didn't do this, then * it would be potentially possible for out thread to carry on and @@ -114,7 +114,7 @@ threadstart(void *arg) * from our pthread_t structure to our struct perl_thread, since * we're the only thread who can get at it anyway. */ - SET_THR(thr); + PERL_SET_THX(thr); /* Only now can we use SvPEEK (which calls sv_newmortal which does dTHR) */ DEBUG_S(PerlIO_printf(Perl_debug_log, "new thread %p starting at %s\n", @@ -252,7 +252,7 @@ newthread (pTHX_ SV *startsv, AV *initargs, char *classname) * XPUSHs() below want to grow the child's stack. This is * safe, since the other thread is not yet created, and we * are the only ones who know about it */ - SET_THR(thr); + PERL_SET_THX(thr); SPAGAIN; DEBUG_S(PerlIO_printf(Perl_debug_log, "%p: newthread (%p), tid is %u, preparing stack\n", @@ -266,7 +266,7 @@ newthread (pTHX_ SV *startsv, AV *initargs, char *classname) PUTBACK; /* On your marks... */ - SET_THR(savethread); + PERL_SET_THX(savethread); MUTEX_LOCK(&thr->mutex); #ifdef THREAD_CREATE diff --git a/perl.c b/perl.c index 9da19e0..cba035f 100644 --- a/perl.c +++ b/perl.c @@ -47,6 +47,37 @@ static I32 read_e_script(pTHXo_ int idx, SV *buf_sv, int maxlen); #define perl_free Perl_free #endif +#if defined(USE_THREADS) +# define INIT_TLS_AND_INTERP \ + STMT_START { \ + if (!PL_curinterp) { \ + PERL_SET_INTERP(my_perl); \ + INIT_THREADS; \ + ALLOC_THREAD_KEY; \ + } \ + } STMT_END +#else +# if defined(USE_ITHREADS) +# define INIT_TLS_AND_INTERP \ + STMT_START { \ + if (!PL_curinterp) { \ + PERL_SET_INTERP(my_perl); \ + INIT_THREADS; \ + ALLOC_THREAD_KEY; \ + } \ + PERL_SET_THX(my_perl); \ + } STMT_END +# else +# define INIT_TLS_AND_INTERP \ + STMT_START { \ + if (!PL_curinterp) { \ + PERL_SET_INTERP(my_perl); \ + } \ + PERL_SET_THX(my_perl); \ + } STMT_END +# endif +#endif + #ifdef PERL_IMPLICIT_SYS PerlInterpreter * perl_alloc_using(struct IPerlMem* ipM, struct IPerlMem* ipMS, @@ -59,25 +90,11 @@ perl_alloc_using(struct IPerlMem* ipM, struct IPerlMem* ipMS, #ifdef PERL_OBJECT my_perl = (PerlInterpreter*)new(ipM) CPerlObj(ipM, ipMS, ipMP, ipE, ipStd, ipLIO, ipD, ipS, ipP); - if (!PL_curinterp) { - PERL_SET_INTERP(my_perl); -#if defined(USE_THREADS) || defined(USE_ITHREADS) - INIT_THREADS; - ALLOC_THREAD_KEY; -#endif - } - PERL_SET_THX(my_perl); + INIT_TLS_AND_INTERP; #else /* New() needs interpreter, so call malloc() instead */ my_perl = (PerlInterpreter*)(*ipM->pMalloc)(ipM, sizeof(PerlInterpreter)); - if (!PL_curinterp) { - PERL_SET_INTERP(my_perl); -#if defined(USE_THREADS) || defined(USE_ITHREADS) - INIT_THREADS; - ALLOC_THREAD_KEY; -#endif - } - PERL_SET_THX(my_perl); + INIT_TLS_AND_INTERP; Zero(my_perl, 1, PerlInterpreter); PL_Mem = ipM; PL_MemShared = ipMS; @@ -110,14 +127,7 @@ perl_alloc(void) /* New() needs interpreter, so call malloc() instead */ my_perl = (PerlInterpreter*)PerlMem_malloc(sizeof(PerlInterpreter)); - if (!PL_curinterp) { - PERL_SET_INTERP(my_perl); -#if defined(USE_THREADS) || defined(USE_ITHREADS) - INIT_THREADS; - ALLOC_THREAD_KEY; -#endif - } - PERL_SET_THX(my_perl); + INIT_TLS_AND_INTERP; Zero(my_perl, 1, PerlInterpreter); return my_perl; } @@ -3416,7 +3426,7 @@ S_init_main_thread(pTHX) #else thr->self = pthread_self(); #endif /* SET_THREAD_SELF */ - SET_THR(thr); + PERL_SET_THX(thr); /* * These must come after the SET_THR because sv_setpvn does diff --git a/perl.h b/perl.h index 30961c5..f5dfacc 100644 --- a/perl.h +++ b/perl.h @@ -1731,14 +1731,6 @@ typedef pthread_key_t perl_key; # define PERL_GET_INTERP (PL_curinterp) #endif -#ifndef PERL_SET_CONTEXT -# define PERL_SET_CONTEXT(i) PERL_SET_INTERP(i) -#endif - -#ifndef PERL_GET_CONTEXT -# define PERL_GET_CONTEXT PERL_GET_INTERP -#endif - #if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_GET_THX) # ifdef USE_THREADS # define PERL_GET_THX ((struct perl_thread *)PERL_GET_CONTEXT) @@ -1754,14 +1746,6 @@ typedef pthread_key_t perl_key; # define PERL_SET_THX(t) PERL_SET_CONTEXT(t) #endif -#ifndef PERL_GET_THX -# define PERL_GET_THX ((void*)NULL) -#endif - -#ifndef PERL_SET_THX -# define PERL_SET_THX(t) NOOP -#endif - #ifndef SVf # ifdef CHECK_FORMAT # define SVf "p" @@ -3125,6 +3109,23 @@ typedef struct am_table_short AMTS; #define printf PerlIO_stdoutf #endif +/* if these never got defined, they need defaults */ +#ifndef PERL_SET_CONTEXT +# define PERL_SET_CONTEXT(i) PERL_SET_INTERP(i) +#endif + +#ifndef PERL_GET_CONTEXT +# define PERL_GET_CONTEXT PERL_GET_INTERP +#endif + +#ifndef PERL_GET_THX +# define PERL_GET_THX ((void*)NULL) +#endif + +#ifndef PERL_SET_THX +# define PERL_SET_THX(t) NOOP +#endif + #ifndef PERL_SCRIPT_MODE #define PERL_SCRIPT_MODE "r" #endif