summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorMalcolm Beattie <mbeattie@sable.ox.ac.uk>1998-02-02 15:51:39 +0000
committerMalcolm Beattie <mbeattie@sable.ox.ac.uk>1998-02-02 15:51:39 +0000
commit940cb80d04d066d4fedfc4486ab57e435ee74514 (patch)
tree29bcb5cc4d0e30eb584990d09b0ee5b2ad73cc49 /ext
parent5330fa38cab061dceb2210e65e8eccfafbebc694 (diff)
downloadperl-940cb80d04d066d4fedfc4486ab57e435ee74514.tar.gz
Introduced thr->threadsvp and THREADSV() for faster per-thread
variables. Moved threadnum to a per-interpreter variable and made dTHR and lock/unlock of sv_mutex bypass the get/lock unless more than one thread may be running. Minor tweaks to Thread.xs. p4raw-id: //depot/perl@453
Diffstat (limited to 'ext')
-rw-r--r--ext/Thread/Thread.xs32
1 files changed, 11 insertions, 21 deletions
diff --git a/ext/Thread/Thread.xs b/ext/Thread/Thread.xs
index c5adcb3eb7..3b49dbecb2 100644
--- a/ext/Thread/Thread.xs
+++ b/ext/Thread/Thread.xs
@@ -12,7 +12,6 @@
#endif
#include <fcntl.h>
-static U32 threadnum = 0;
static int sig_pipe[2];
#ifndef THREAD_RET_TYPE
@@ -208,6 +207,8 @@ newthread (SV *startsv, AV *initargs, char *classname)
SV *sv;
int err;
#ifndef THREAD_CREATE
+ static pthread_attr_t attr;
+ static int attr_inited = 0;
sigset_t fullmask, oldmask;
#endif
@@ -233,33 +234,22 @@ newthread (SV *startsv, AV *initargs, char *classname)
sigfillset(&fullmask);
if (sigprocmask(SIG_SETMASK, &fullmask, &oldmask) == -1)
croak("panic: sigprocmask");
-#ifdef PTHREADS_CREATED_JOINABLE
- err = pthread_create(&thr->self, pthread_attr_default,
- threadstart, (void*) thr);
-#else
- {
- pthread_attr_t attr;
-
+ err = 0;
+ if (!attr_inited) {
+ attr_inited = 1;
err = pthread_attr_init(&attr);
- if (err == 0) {
-#ifdef PTHREAD_CREATE_UNDETACHED
- err = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_UNDETACHED);
-#else
- croak("panic: pthread_attr_setdetachstate");
-#endif
- if (err == 0)
- err = pthread_create(&thr->self, &attr,
- threadstart, (void*) thr);
- }
- pthread_attr_destroy(&attr);
+ if (err == 0)
+ err = pthread_attr_setdetachstate(&attr, ATTR_JOINABLE);
}
-#endif
+ if (err == 0)
+ err = pthread_create(&thr->self, &attr, threadstart, (void*) thr);
/* Go */
MUTEX_UNLOCK(&thr->mutex);
#endif
if (err) {
DEBUG_L(PerlIO_printf(PerlIO_stderr(),
- "%p: create of %p failed %d\n", savethread, thr, err));
+ "%p: create of %p failed %d\n",
+ savethread, thr, err));
/* Thread creation failed--clean up */
SvREFCNT_dec(thr->cvcache);
remove_thread(thr);