summaryrefslogtreecommitdiff
path: root/thread.h
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 /thread.h
parentfd9459bc435247011bdd5dc44ff2358cc4d1b124 (diff)
downloadperl-1feb27209aee3921894ffc1cc08027670d4240f3.tar.gz
bring in basic threads stuff under USE_ITHREADS
p4raw-id: //depot/perl@4704
Diffstat (limited to 'thread.h')
-rw-r--r--thread.h166
1 files changed, 107 insertions, 59 deletions
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