summaryrefslogtreecommitdiff
path: root/thread.h
diff options
context:
space:
mode:
authorMalcolm Beattie <mbeattie@sable.ox.ac.uk>1997-10-15 16:55:10 +0000
committerMalcolm Beattie <mbeattie@sable.ox.ac.uk>1997-10-15 16:55:10 +0000
commitf826a10b5944692b2da706f4a0ac5056f28e8c6d (patch)
tree6584f7f79b06c00d0ff30301a24e4ac72c19bf2e /thread.h
parent1fd28e8719b5948a213df0351e0ab4964a56a071 (diff)
downloadperl-f826a10b5944692b2da706f4a0ac5056f28e8c6d.tar.gz
Add HAVE_THREAD_INTERN for platform-dependent struct thread additions.
Fix ThrSETSTATE not to lock t->mutex itself. p4raw-id: //depot/perl@130
Diffstat (limited to 'thread.h')
-rw-r--r--thread.h30
1 files changed, 15 insertions, 15 deletions
diff --git a/thread.h b/thread.h
index 5a7d5b5b2e..2e1a03be52 100644
--- a/thread.h
+++ b/thread.h
@@ -73,8 +73,12 @@ typedef pthread_t perl_thread;
#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
+/* DETACH(t) must only be called while holding t->mutex */
+#define DETACH(t) \
+ if (pthread_detach((t)->Tself)) { \
+ MUTEX_UNLOCK(&(t)->mutex); \
+ croak("panic: DETACH"); \
+ } else 1
/* XXX Add "old" (?) POSIX draft interface too */
#ifdef OLD_PTHREADS_API
@@ -164,16 +168,13 @@ struct thread {
SV * Toursv;
HV * Tcvcache;
U32 flags;
- perl_mutex mutex;
+ perl_mutex mutex; /* For the fields others can change */
U32 tid;
struct thread *next, *prev; /* Circular linked list of threads */
-#ifdef FAKE_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 */
- I32 savemark; /* Holds MARK for thread join values */
-#endif /* FAKE_THREADS */
+#ifdef ADD_THREAD_INTERN
+ struct thread_intern i; /* Platform-dependent internals */
+#endif
};
typedef struct thread *Thread;
@@ -188,21 +189,20 @@ typedef struct thread *Thread;
#define THRf_DIE_FATAL 8
+/* ThrSTATE(t) and ThrSETSTATE(t) must only be called while holding t->mutex */
#define ThrSTATE(t) ((t)->flags)
#define ThrSETSTATE(t, s) STMT_START { \
- MUTEX_LOCK(&(t)->mutex); \
(t)->flags &= ~THRf_STATE_MASK; \
(t)->flags |= (s); \
- MUTEX_UNLOCK(&(t)->mutex); \
DEBUG_L(PerlIO_printf(PerlIO_stderr(), \
"thread %p set to state %d\n", (t), (s))); \
} STMT_END
typedef struct condpair {
- perl_mutex mutex;
- perl_cond owner_cond;
- perl_cond cond;
- Thread owner;
+ perl_mutex mutex; /* Protects all other fields */
+ perl_cond owner_cond; /* For when owner changes at all */
+ perl_cond cond; /* For cond_signal and cond_broadcast */
+ Thread owner; /* Currently owning thread */
} condpair_t;
#define MgMUTEXP(mg) (&((condpair_t *)(mg->mg_ptr))->mutex)