patch for oskit threads
Patrick Tullmann
tullmann at cs.utah.edu
Thu Mar 9 16:40:45 PST 2000
The attached patch cleans up several nits and fixes a bug in the OSKit
threading library. (Querying the stack state of newborn or dead
threads isn't a good idea).
Here's a changelog:
* kaffe/kaffevm/systems/oskit-pthreads/pjthread.c: Check for
newborn/dead thread before getting stack state. Initialize
cookie for main thread correctly. Misc. cleanup.
* kaffe/kaffevm/systems/oskit-pthreads/signal.c: remove some
bogus asserts().
-Pat
----- ----- ---- --- --- -- - - - - -
Pat Tullmann tullmann at cs.utah.edu
It said "Windows 95 or better" so FreeBSD should run on it.
Index: kaffe/kaffevm/systems/oskit-pthreads/pjthread.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/systems/oskit-pthreads/pjthread.c,v
retrieving revision 1.8
diff -u -r1.8 pjthread.c
--- kaffe/kaffevm/systems/oskit-pthreads/pjthread.c 1999/10/16 22:51:31 1.8
+++ kaffe/kaffevm/systems/oskit-pthreads/pjthread.c 2000/03/10 00:37:41
@@ -1,5 +1,6 @@
/*
- * Copyright (c) 1998, 1999 The University of Utah. All rights reserved.
+ * Copyright (c) 1998-2000 The University of Utah.
+ * All rights reserved.
*
* See the file "license.terms" for information on usage and redistribution
* of this file.
@@ -27,8 +28,8 @@
#define THREAD_RUNNING 1
#define THREAD_DYING 2
#define THREAD_DEAD 3
-#define THREAD_STOPPED 4
-#define THREAD_CONTINUE 5
+#define THREAD_STOPPED 4 /* XXX only used in status dump! */
+#define THREAD_CONTINUE 5 /* XXX only used in status dump! */
#define THREAD_FLAG_DONTSTOP 1
@@ -80,7 +81,7 @@
static void
catch_death(void)
{
- jthread_t tid = pthread_getspecific(jthread_key);
+ jthread_t tid = GET_JTHREAD();
if (!(tid->flags & THREAD_FLAG_DONTSTOP)) {
onstop();
@@ -161,8 +162,18 @@
{
struct pthread_state ps;
- if (oskit_pthread_getstate(jtid->native_thread, &ps))
- panic("jthread_extract_stack: tid(%d)", jtid->native_thread);
+ /*
+ * Newborn/dead threads don't have a useful stack, and may not
+ * have a native_thread.
+ */
+ if ((jtid->status == THREAD_NEWBORN)
+ || (jtid->status == THREAD_DEAD))
+ return 0;
+
+ if (oskit_pthread_getstate(jtid->native_thread, &ps)) {
+ panic("jthread_extract_stack: oskit_pthread_getstate failed for jtid(%p)\n",
+ jtid);
+ }
#if defined(STACK_GROWS_UP)
#error FIXME
@@ -212,6 +223,7 @@
return rc;
}
+
/*
* See if there is enough room on the stack.
*/
@@ -220,10 +232,11 @@
{
struct pthread_state ps;
int room;
+ pthread_t tid = pthread_self();
- if (oskit_pthread_getstate(pthread_self(), &ps))
+ if (oskit_pthread_getstate(tid, &ps))
panic("jthread_stackcheck: oskit_pthread_getstate(%d)",
- pthread_self());
+ (int)tid);
#if defined(STACK_GROWS_UP)
# error FIXME
@@ -233,7 +246,7 @@
DBG(JTHREAD,
dprintf("stackcheck(%d) need=%d base=%p size=%d sp=%p room=%d\n",
- pthread_self(),
+ (int)pthread_self(),
need, ps.stackbase, ps.stacksize, ps.stackptr, room);
)
return (room >= need);
@@ -397,6 +410,10 @@
assert(jtid->status == THREAD_RUNNING);
jtid->jlThread = jlThread;
+
+ /* Main thread should not yet have a jlThread associated with it. */
+ assert(pthread_getspecific(cookie_key) == NULL);
+ pthread_setspecific(cookie_key, jlThread);
/* XXX what to do with mainThreadStackSize?? */
@@ -420,7 +437,7 @@
void
jthread_disable_stop(void)
{
- jthread_t tid = pthread_getspecific(jthread_key);
+ jthread_t tid = GET_JTHREAD();
tid->flags |= THREAD_FLAG_DONTSTOP;
}
@@ -431,7 +448,7 @@
void
jthread_enable_stop(void)
{
- jthread_t tid = pthread_getspecific(jthread_key);
+ jthread_t tid = GET_JTHREAD();
tid->flags &= ~THREAD_FLAG_DONTSTOP;
if (tid->status == THREAD_DYING) {
@@ -659,7 +676,8 @@
mark_thread_dead(void)
{
jthread_t currentJThread = GET_JTHREAD();
- assert (currentJThread->status != THREAD_DEAD);
+ assert(currentJThread);
+ assert(currentJThread->status != THREAD_DEAD);
currentJThread->status = THREAD_DEAD;
remove_thread(currentJThread);
@@ -672,21 +690,18 @@
void
jthread_exit(void)
{
- jthread_t currentJThread = GET_JTHREAD();
-
DBG(JTHREAD,
- dprintf("jthread_exit called by %d\n", currentJThread->native_thread);
+ dprintf("jthread_exit called by %d\n", GET_JTHREAD()->native_thread);
)
mark_thread_dead();
-#ifndef newer_than_990722
- /* The main thread must be explicitly detached before
- * exitting. Since its mutex is unitialized, detach will work,
- * but the idle thread will crash trying to clean up.
- */
+
+ /* XXX disconnect the native thread object */
+ GET_JTHREAD()->native_thread = -1;
+
pthread_detach(pthread_self());
-#endif
pthread_exit(0);
+
while (1)
assert(!"This better not return.");
}
Index: kaffe/kaffevm/systems/oskit-pthreads/signal.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/systems/oskit-pthreads/signal.c,v
retrieving revision 1.4
diff -u -r1.4 signal.c
--- kaffe/kaffevm/systems/oskit-pthreads/signal.c 1999/10/16 22:51:31 1.4
+++ kaffe/kaffevm/systems/oskit-pthreads/signal.c 2000/03/10 00:37:41
@@ -118,7 +118,6 @@
/* These threads are internal to pthreads and shouldn't blow up like this. */
assert(pthread_self() != 0);
- // assert(pthread_self() != 1);
/* don't catch the signal if debugging exceptions */
if (DBGEXPR(EXCEPTION, false, true)) {
@@ -139,7 +138,6 @@
/* These threads are internal to pthreads and shouldn't blow up like this. */
assert(pthread_self() != 0);
- assert(pthread_self() != 1);
/* don't catch the signal if debugging exceptions */
if (DBGEXPR(EXCEPTION, false, true)) {
More information about the kaffe
mailing list