diff options
author | Malcolm Beattie <mbeattie@sable.ox.ac.uk> | 1997-10-10 17:22:46 +0000 |
---|---|---|
committer | Malcolm Beattie <mbeattie@sable.ox.ac.uk> | 1997-10-10 17:22:46 +0000 |
commit | 33f46ff65e5d2230d8bd00503ede2b051af73672 (patch) | |
tree | 816b88f644f5c65e5ca4a4a9dc8846b0b9d11097 /thread.h | |
parent | 3de9ffa12981946cc7fab5bddd19f506a1979bf4 (diff) | |
download | perl-33f46ff65e5d2230d8bd00503ede2b051af73672.tar.gz |
Rewrite thread destruction system using linked list of threads.
Still not completely done. Add methods self, equal, flags, list
to Thread.xs. Add Thread_MAGIC_SIGNATURE check to typemap.
p4raw-id: //depot/perl@120
Diffstat (limited to 'thread.h')
-rw-r--r-- | thread.h | 42 |
1 files changed, 26 insertions, 16 deletions
@@ -38,7 +38,6 @@ typedef struct thread *perl_thread; SCHEDULE(); \ } STMT_END #define COND_DESTROY(c) - #else /* POSIXish threads */ typedef pthread_t perl_thread; @@ -70,6 +69,10 @@ typedef pthread_t perl_thread; if (pthread_cond_wait((c), (m))) croak("panic: COND_WAIT"); else 1 #define COND_DESTROY(c) \ if (pthread_cond_destroy((c))) croak("panic: COND_DESTROY"); else 1 + +#define DETACH(t) \ + if (pthread_detach((t)->Tself)) croak("panic: DETACH"); else 1 + /* XXX Add "old" (?) POSIX draft interface too */ #ifdef OLD_PTHREADS_API struct thread *getTHR _((void)); @@ -80,20 +83,27 @@ struct thread *getTHR _((void)); #define dTHR struct thread *thr = THR #endif /* FAKE_THREADS */ -struct thread { - perl_thread Tself; - SV * Toursv; +#ifndef INIT_THREADS +# ifdef NEED_PTHREAD_INIT +# define INIT_THREADS pthread_init() +# else +# define INIT_THREADS NOOP +# endif +#endif +struct thread { /* The fields that used to be global */ - SV ** Tstack_base; + /* Important ones in the first cache line (if alignment is done right) */ SV ** Tstack_sp; - SV ** Tstack_max; - #ifdef OP_IN_REGISTER OP * Topsave; #else OP * Top; #endif + SV ** Tcurpad; + SV ** Tstack_base; + + SV ** Tstack_max; I32 * Tscopestack; I32 Tscopestack_ix; @@ -111,8 +121,6 @@ struct thread { I32 * Tmarkstack_ptr; I32 * Tmarkstack_max; - SV ** Tcurpad; - SV * TSv; XPV * TXpv; struct stat Tstatbuf; @@ -149,12 +157,15 @@ struct thread { /* XXX Sort stuff, firstgv, secongv and so on? */ + perl_thread Tself; + SV * Toursv; perl_mutex *Tthreadstart_mutexp; HV * Tcvcache; - U32 Tthrflags; + U32 flags; + U32 tid; + struct thread *next, *prev; /* Circular linked list of threads */ #ifdef FAKE_THREADS - perl_thread next, prev; /* Linked list of all threads */ perl_thread next_run, prev_run; /* Linked list of runnable threads */ perl_cond wait_queue; /* Wait queue that we are waiting on */ IV private; /* Holds data across time slices */ @@ -164,7 +175,7 @@ struct thread { typedef struct thread *Thread; -/* Values and macros for thrflags */ +/* Values and macros for thr->flags */ #define THRf_STATE_MASK 3 #define THRf_NORMAL 0 #define THRf_DETACHED 1 @@ -173,10 +184,10 @@ typedef struct thread *Thread; #define THRf_DIE_FATAL 4 -#define ThrSTATE(t) (t->Tthrflags & THRf_STATE_MASK) +#define ThrSTATE(t) (t->flags & THRf_STATE_MASK) #define ThrSETSTATE(t, s) STMT_START { \ - (t)->Tthrflags &= ~THRf_STATE_MASK; \ - (t)->Tthrflags |= (s); \ + (t)->flags &= ~THRf_STATE_MASK; \ + (t)->flags |= (s); \ DEBUG_L(fprintf(stderr, "thread 0x%lx set to state %d\n", \ (unsigned long)(t), (s))); \ } STMT_END @@ -291,5 +302,4 @@ typedef struct condpair { #define threadstart_mutexp (thr->Tthreadstart_mutexp) #define cvcache (thr->Tcvcache) -#define thrflags (thr->Tthrflags) #endif /* USE_THREADS */ |