summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>1999-12-23 08:54:27 +0000
committerGurusamy Sarathy <gsar@cpan.org>1999-12-23 08:54:27 +0000
commit1feb27209aee3921894ffc1cc08027670d4240f3 (patch)
tree6b79a2ca2620a7e287d9d18cc5d660a977984bb5
parentfd9459bc435247011bdd5dc44ff2358cc4d1b124 (diff)
downloadperl-1feb27209aee3921894ffc1cc08027670d4240f3.tar.gz
bring in basic threads stuff under USE_ITHREADS
p4raw-id: //depot/perl@4704
-rw-r--r--makedef.pl6
-rw-r--r--op.c4
-rw-r--r--perl.c3
-rw-r--r--perl.h12
-rw-r--r--perlvars.h2
-rw-r--r--pp_sys.c4
-rw-r--r--thread.h166
-rw-r--r--util.c6
8 files changed, 128 insertions, 75 deletions
diff --git a/makedef.pl b/makedef.pl
index 1d585a2e31..eb599c9ae5 100644
--- a/makedef.pl
+++ b/makedef.pl
@@ -338,6 +338,11 @@ if ($define{'MYMALLOC'}) {
Perl_realloc
Perl_calloc
)];
+ if ($define{'USE_THREADS'} || $define{'USE_ITHREADS'}) {
+ emit_symbols [qw(
+ PL_malloc_mutex
+ )];
+ }
}
else {
skip_symbols [qw(
@@ -357,7 +362,6 @@ unless ($define{'USE_THREADS'}) {
PL_sv_mutex
PL_strtab_mutex
PL_svref_mutex
- PL_malloc_mutex
PL_cred_mutex
PL_eval_mutex
PL_eval_cond
diff --git a/op.c b/op.c
index e69630a0d7..d796ede318 100644
--- a/op.c
+++ b/op.c
@@ -4133,9 +4133,9 @@ CV *
Perl_cv_clone(pTHX_ CV *proto)
{
CV *cv;
- MUTEX_LOCK(&PL_cred_mutex); /* XXX create separate mutex */
+ LOCK_CRED_MUTEX; /* XXX create separate mutex */
cv = cv_clone2(proto, CvOUTSIDE(proto));
- MUTEX_UNLOCK(&PL_cred_mutex); /* XXX create separate mutex */
+ UNLOCK_CRED_MUTEX; /* XXX create separate mutex */
return cv;
}
diff --git a/perl.c b/perl.c
index a2351223ee..864a569fd9 100644
--- a/perl.c
+++ b/perl.c
@@ -119,9 +119,8 @@ perl_construct(pTHXx)
/* Init the real globals (and main thread)? */
if (!PL_linestr) {
-#ifdef USE_THREADS
-
INIT_THREADS;
+#ifdef USE_THREADS
#ifdef ALLOC_THREAD_KEY
ALLOC_THREAD_KEY;
#else
diff --git a/perl.h b/perl.h
index 8a6505e56b..fb5409dd0e 100644
--- a/perl.h
+++ b/perl.h
@@ -383,7 +383,8 @@ register struct op *Perl_op asm(stringify(OP_IN_REGISTER));
/* HP-UX 10.X CMA (Common Multithreaded Architecure) insists that
pthread.h must be included before all other header files.
*/
-#if defined(USE_THREADS) && defined(PTHREAD_H_FIRST) && defined(I_PTHREAD)
+#if (defined(USE_THREADS) || defined(USE_ITHREADS)) \
+ && defined(PTHREAD_H_FIRST) && defined(I_PTHREAD)
# include <pthread.h>
#endif
@@ -1502,11 +1503,12 @@ typedef struct ptr_tbl PTR_TBL_t;
* May make sense to have threads after "*ish.h" anyway
*/
-#ifdef USE_THREADS
+#if defined(USE_THREADS) || defined(USE_ITHREADS)
+# if defined(USE_THREADS)
/* pending resolution of licensing issues, we avoid the erstwhile
* atomic.h everywhere */
# define EMULATE_ATOMIC_REFCOUNTS
-
+# endif
# ifdef FAKE_THREADS
# include "fakethr.h"
# else
@@ -1537,10 +1539,10 @@ typedef pthread_key_t perl_key;
# endif /* OS2 */
# endif /* WIN32 */
# endif /* FAKE_THREADS */
-#endif /* USE_THREADS */
+#endif /* USE_THREADS || USE_ITHREADS */
#ifdef WIN32
-#include "win32.h"
+# include "win32.h"
#endif
#ifdef VMS
diff --git a/perlvars.h b/perlvars.h
index 85ff7515bd..55769d55ca 100644
--- a/perlvars.h
+++ b/perlvars.h
@@ -31,6 +31,6 @@ PERLVARIC(Gpatleave, char *, "\\.^$@dDwWsSbB+*?|()-nrtfeaxc0123456789[{]}")
/* XXX does anyone even use this? */
PERLVARI(Gdo_undump, bool, FALSE) /* -u or dump seen? */
-#if defined(MYMALLOC) && defined(USE_THREADS)
+#if defined(MYMALLOC) && (defined(USE_THREADS) || defined(USE_ITHREADS))
PERLVAR(Gmalloc_mutex, perl_mutex) /* Mutex for malloc */
#endif
diff --git a/pp_sys.c b/pp_sys.c
index d853f6c26b..96ba78bbdc 100644
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -247,7 +247,7 @@ S_emulate_eaccess(pTHX_ const char* path, Mode_t mode)
Gid_t egid = getegid();
int res;
- MUTEX_LOCK(&PL_cred_mutex);
+ LOCK_CRED_MUTEX;
#if !defined(HAS_SETREUID) && !defined(HAS_SETRESUID)
Perl_croak(aTHX_ "switching effective uid is not implemented");
#else
@@ -293,7 +293,7 @@ S_emulate_eaccess(pTHX_ const char* path, Mode_t mode)
#endif
#endif
Perl_croak(aTHX_ "leaving effective gid failed");
- MUTEX_UNLOCK(&PL_cred_mutex);
+ UNLOCK_CRED_MUTEX;
return res;
}
diff --git a/thread.h b/thread.h
index 1e2a220ff9..87828aba9e 100644
--- a/thread.h
+++ b/thread.h
@@ -1,4 +1,4 @@
-#ifdef USE_THREADS
+#if defined(USE_THREADS) || defined(USE_ITHREADS)
#ifdef WIN32
# include <win32thread.h>
@@ -236,10 +236,19 @@ struct perl_thread *getTHR (void);
} STMT_END
#endif /* SET_THR */
-#ifndef THR
-#define THR ((struct perl_thread *) pthread_getspecific(PL_thr_key))
+#ifndef INIT_THREADS
+# ifdef NEED_PTHREAD_INIT
+# define INIT_THREADS pthread_init()
+# endif
#endif
+#ifndef THREAD_RET_TYPE
+# define THREAD_RET_TYPE void *
+# define THREAD_RET_CAST(p) ((void *)(p))
+#endif /* THREAD_RET */
+
+#if defined(USE_THREADS)
+
/*
* dTHR is performance-critical. Here, we only do the pthread_get_specific
* if there may be more than one thread in existence, otherwise we get thr
@@ -249,21 +258,18 @@ struct perl_thread *getTHR (void);
*
* The use of PL_threadnum should be safe here.
*/
-#ifndef dTHR
-# define dTHR \
- struct perl_thread *thr = PL_threadnum? THR : (struct perl_thread*)SvPVX(PL_thrsv)
-#endif /* dTHR */
+# if !defined(dTHR)
+# define dTHR \
+ struct perl_thread *thr = PL_threadnum ? THR : (struct perl_thread*)SvPVX(PL_thrsv)
+# endif /* dTHR */
-#ifndef INIT_THREADS
-# ifdef NEED_PTHREAD_INIT
-# define INIT_THREADS pthread_init()
-# else
-# define INIT_THREADS NOOP
+# if !defined(THR)
+# define THR ((struct perl_thread *) pthread_getspecific(PL_thr_key))
# endif
-#endif
+
/* Accessor for per-thread SVs */
-#define THREADSV(i) (thr->threadsvp[i])
+# define THREADSV(i) (thr->threadsvp[i])
/*
* LOCK_SV_MUTEX and UNLOCK_SV_MUTEX are performance-critical. Here, we
@@ -272,31 +278,12 @@ struct perl_thread *getTHR (void);
* remove the "if (threadnum) ..." test.
* XXX do NOT use C<if (PL_threadnum) ...> -- it sets up race conditions!
*/
-#define LOCK_SV_MUTEX \
- STMT_START { \
- MUTEX_LOCK(&PL_sv_mutex); \
- } STMT_END
-
-#define UNLOCK_SV_MUTEX \
- STMT_START { \
- MUTEX_UNLOCK(&PL_sv_mutex); \
- } STMT_END
-
-/* Likewise for strtab_mutex */
-#define LOCK_STRTAB_MUTEX \
- STMT_START { \
- MUTEX_LOCK(&PL_strtab_mutex); \
- } STMT_END
-
-#define UNLOCK_STRTAB_MUTEX \
- STMT_START { \
- MUTEX_UNLOCK(&PL_strtab_mutex); \
- } STMT_END
-
-#ifndef THREAD_RET_TYPE
-# define THREAD_RET_TYPE void *
-# define THREAD_RET_CAST(p) ((void *)(p))
-#endif /* THREAD_RET */
+# define LOCK_SV_MUTEX MUTEX_LOCK(&PL_sv_mutex)
+# define UNLOCK_SV_MUTEX MUTEX_UNLOCK(&PL_sv_mutex)
+# define LOCK_STRTAB_MUTEX MUTEX_LOCK(&PL_strtab_mutex)
+# define UNLOCK_STRTAB_MUTEX MUTEX_UNLOCK(&PL_strtab_mutex)
+# define LOCK_CRED_MUTEX MUTEX_LOCK(&PL_cred_mutex)
+# define UNLOCK_CRED_MUTEX MUTEX_UNLOCK(&PL_cred_mutex)
/* Values and macros for thr->flags */
@@ -330,24 +317,85 @@ typedef struct condpair {
#define MgCONDP(mg) (&((condpair_t *)(mg->mg_ptr))->cond)
#define MgOWNER(mg) ((condpair_t *)(mg->mg_ptr))->owner
-#else
-/* USE_THREADS is not defined */
-#define MUTEX_LOCK(m)
-#define MUTEX_LOCK_NOCONTEXT(m)
-#define MUTEX_UNLOCK(m)
-#define MUTEX_UNLOCK_NOCONTEXT(m)
-#define MUTEX_INIT(m)
-#define MUTEX_DESTROY(m)
-#define COND_INIT(c)
-#define COND_SIGNAL(c)
-#define COND_BROADCAST(c)
-#define COND_WAIT(c, m)
-#define COND_DESTROY(c)
-#define LOCK_SV_MUTEX
-#define UNLOCK_SV_MUTEX
-#define LOCK_STRTAB_MUTEX
-#define UNLOCK_STRTAB_MUTEX
-
-#define THR
-#define dTHR dNOOP
#endif /* USE_THREADS */
+#endif /* USE_THREADS || USE_ITHREADS */
+
+#ifndef MUTEX_LOCK
+# define MUTEX_LOCK(m)
+#endif
+
+#ifndef MUTEX_LOCK_NOCONTEXT
+# define MUTEX_LOCK_NOCONTEXT(m)
+#endif
+
+#ifndef MUTEX_UNLOCK
+# define MUTEX_UNLOCK(m)
+#endif
+
+#ifndef MUTEX_UNLOCK_NOCONTEXT
+# define MUTEX_UNLOCK_NOCONTEXT(m)
+#endif
+
+#ifndef MUTEX_INIT
+# define MUTEX_INIT(m)
+#endif
+
+#ifndef MUTEX_DESTROY
+# define MUTEX_DESTROY(m)
+#endif
+
+#ifndef COND_INIT
+# define COND_INIT(c)
+#endif
+
+#ifndef COND_SIGNAL
+# define COND_SIGNAL(c)
+#endif
+
+#ifndef COND_BROADCAST
+# define COND_BROADCAST(c)
+#endif
+
+#ifndef COND_WAIT
+# define COND_WAIT(c, m)
+#endif
+
+#ifndef COND_DESTROY
+# define COND_DESTROY(c)
+#endif
+
+#ifndef LOCK_SV_MUTEX
+# define LOCK_SV_MUTEX
+#endif
+
+#ifndef UNLOCK_SV_MUTEX
+# define UNLOCK_SV_MUTEX
+#endif
+
+#ifndef LOCK_STRTAB_MUTEX
+# define LOCK_STRTAB_MUTEX
+#endif
+
+#ifndef UNLOCK_STRTAB_MUTEX
+# define UNLOCK_STRTAB_MUTEX
+#endif
+
+#ifndef LOCK_CRED_MUTEX
+# define LOCK_CRED_MUTEX
+#endif
+
+#ifndef UNLOCK_CRED_MUTEX
+# define UNLOCK_CRED_MUTEX
+#endif
+
+#ifndef THR
+# define THR
+#endif
+
+#ifndef dTHR
+# define dTHR dNOOP
+#endif
+
+#ifndef INIT_THREADS
+# define INIT_THREADS NOOP
+#endif
diff --git a/util.c b/util.c
index 5eb647188a..416a437dfd 100644
--- a/util.c
+++ b/util.c
@@ -3339,11 +3339,11 @@ Perl_condpair_magic(pTHX_ SV *sv)
COND_INIT(&cp->owner_cond);
COND_INIT(&cp->cond);
cp->owner = 0;
- MUTEX_LOCK(&PL_cred_mutex); /* XXX need separate mutex? */
+ LOCK_CRED_MUTEX; /* XXX need separate mutex? */
mg = mg_find(sv, 'm');
if (mg) {
/* someone else beat us to initialising it */
- MUTEX_UNLOCK(&PL_cred_mutex); /* XXX need separate mutex? */
+ UNLOCK_CRED_MUTEX; /* XXX need separate mutex? */
MUTEX_DESTROY(&cp->mutex);
COND_DESTROY(&cp->owner_cond);
COND_DESTROY(&cp->cond);
@@ -3354,7 +3354,7 @@ Perl_condpair_magic(pTHX_ SV *sv)
mg = SvMAGIC(sv);
mg->mg_ptr = (char *)cp;
mg->mg_len = sizeof(cp);
- MUTEX_UNLOCK(&PL_cred_mutex); /* XXX need separate mutex? */
+ UNLOCK_CRED_MUTEX; /* XXX need separate mutex? */
DEBUG_S(WITH_THR(PerlIO_printf(Perl_debug_log,
"%p: condpair_magic %p\n", thr, sv));)
}