cvsuser 03/12/22 07:32:02
Modified: classes parrotinterpreter.pmc
include/parrot interpreter.h
src interpreter.c thread.c
Log:
parrot-threads-12
* destroy threaded interpreters when their thread function ends
Revision Changes Path
1.19 +18 -9 parrot/classes/parrotinterpreter.pmc
Index: parrotinterpreter.pmc
===================================================================
RCS file: /cvs/public/parrot/classes/parrotinterpreter.pmc,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -w -r1.18 -r1.19
--- parrotinterpreter.pmc 21 Dec 2003 10:15:08 -0000 1.18
+++ parrotinterpreter.pmc 22 Dec 2003 15:31:58 -0000 1.19
@@ -1,7 +1,7 @@
/* parrotinterpreter.pmc
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: parrotinterpreter.pmc,v 1.18 2003/12/21 10:15:08 leo Exp $
+ * $Id: parrotinterpreter.pmc,v 1.19 2003/12/22 15:31:58 leo Exp $
* Overview:
* These are the vtable functions for the ParrotInterpreter base class
* Data Structure and Algorithms:
@@ -107,6 +107,21 @@
void Parrot_PerlHash_class_init(Parrot_Interp, int);
void Parrot_PerlUndef_class_init(Parrot_Interp, int);
+static void
+create_interp(PMC *self, Parrot_Interp parent)
+{
+ Interp_flags flag = 0;
+ Parrot_Interp new_interp;
+
+ if (self->vtable->base_type == enum_class_ParrotThread)
+ flag = PARROT_IS_THREAD;
+
+ new_interp = make_interpreter(parent, flag);
+ PMC_data(self) = new_interp;
+ VTABLE_set_pmc_keyed_int(new_interp, new_interp->iglobals,
+ (INTVAL) IGLOBALS_INTERPRETER, self);
+}
+
pmclass ParrotInterpreter need_ext {
void class_init () {
@@ -141,10 +156,7 @@
* so we check, if the interpreter is already setup
*/
if (!PMC_data(SELF)) {
- Parrot_Interp new_interp = make_interpreter(INTERP, 0);
- PMC_data(SELF) = new_interp;
- VTABLE_set_pmc_keyed_int(new_interp, new_interp->iglobals,
- (INTVAL) IGLOBALS_INTERPRETER, SELF);
+ create_interp(SELF, INTERP);
}
SELF->cache.struct_val = NULL;
}
@@ -153,10 +165,7 @@
Parrot_Interp p = PMC_data(parent);
if (!PMC_data(SELF)) {
- Parrot_Interp new_interp = make_interpreter(p, 0);
- PMC_data(SELF) = new_interp;
- VTABLE_set_pmc_keyed_int(new_interp, new_interp->iglobals,
- (INTVAL) IGLOBALS_INTERPRETER, SELF);
+ create_interp(SELF, p);
}
SELF->cache.struct_val = NULL;
}
1.110 +3 -2 parrot/include/parrot/interpreter.h
Index: interpreter.h
===================================================================
RCS file: /cvs/public/parrot/include/parrot/interpreter.h,v
retrieving revision 1.109
retrieving revision 1.110
diff -u -w -r1.109 -r1.110
--- interpreter.h 18 Dec 2003 12:20:34 -0000 1.109
+++ interpreter.h 22 Dec 2003 15:32:00 -0000 1.110
@@ -1,7 +1,7 @@
/* interpreter.h
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: interpreter.h,v 1.109 2003/12/18 12:20:34 leo Exp $
+ * $Id: interpreter.h,v 1.110 2003/12/22 15:32:00 leo Exp $
* Overview:
* The interpreter api handles running the operations
* Data Structure and Algorithms:
@@ -25,7 +25,8 @@
PARROT_PROFILE_FLAG = 0x08, /* We're gathering profile information */
PARROT_GC_DEBUG_FLAG = 0x10, /* We're debugging memory management */
PARROT_EXTERN_CODE_FLAG = 0x100, /* reusing anothers interps code */
- PARROT_DESTROY_FLAG = 0x200 /* the last interpreter shall cleanup */
+ PARROT_DESTROY_FLAG = 0x200, /* the last interpreter shall cleanup */
+ PARROT_IS_THREAD = 0x400 /* true if interpreter is a thread */
} Parrot_Interp_flag;
/* &end_gen */
1.246 +8 -2 parrot/src/interpreter.c
Index: interpreter.c
===================================================================
RCS file: /cvs/public/parrot/src/interpreter.c,v
retrieving revision 1.245
retrieving revision 1.246
diff -u -w -r1.245 -r1.246
--- interpreter.c 21 Dec 2003 10:15:19 -0000 1.245
+++ interpreter.c 22 Dec 2003 15:32:02 -0000 1.246
@@ -1,7 +1,7 @@
/* interpreter.c
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: interpreter.c,v 1.245 2003/12/21 10:15:19 leo Exp $
+ * $Id: interpreter.c,v 1.246 2003/12/22 15:32:02 leo Exp $
* Overview:
* The interpreter api handles running the operations
* Data Structure and Algorithms:
@@ -1022,6 +1022,12 @@
Parrot_init_events(interpreter);
#ifdef ATEXIT_DESTROY
+ /*
+ * if this is not a threaded interpreter, push the interpreter
+ * destruction.
+ * Threaded interpreters are destructed when the thread ends
+ */
+ if (!Interp_flags_TEST(interpreter, PARROT_IS_THREAD))
Parrot_on_exit(Parrot_really_destroy, (void*)interpreter);
#endif
1.8 +7 -6 parrot/src/thread.c
Index: thread.c
===================================================================
RCS file: /cvs/public/parrot/src/thread.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -w -r1.7 -r1.8
--- thread.c 19 Dec 2003 16:42:39 -0000 1.7
+++ thread.c 22 Dec 2003 15:32:02 -0000 1.8
@@ -1,7 +1,7 @@
/* thread.c
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: thread.c,v 1.7 2003/12/19 16:42:39 leo Exp $
+ * $Id: thread.c,v 1.8 2003/12/22 15:32:02 leo Exp $
* Overview:
* Thread handling stuff
* Data Structure and Algorithms:
@@ -19,6 +19,7 @@
#include <assert.h>
+void Parrot_really_destroy(int exit_code, void *interpreter);
/*
* the actual thread function
*/
@@ -39,11 +40,12 @@
tid = interpreter->thread_data->tid;
if (interpreter != interpreter_array[tid]) {
UNLOCK(interpreter_array_mutex);
- internal_exception(1, "thread finished: interpreter mismatch");
+ PANIC("thread finished: interpreter mismatch");
}
if ((interpreter->thread_data->state & THREAD_STATE_DETACHED) ||
(interpreter->thread_data->state & THREAD_STATE_JOINED)) {
interpreter_array[tid] = NULL;
+ Parrot_really_destroy(0, interpreter);
}
UNLOCK(interpreter_array_mutex);
@@ -192,28 +194,27 @@
{
size_t i;
- LOCK(interpreter_array_mutex);
/*
* if no threads where started - fine
*/
if (!n_interpreters) {
- UNLOCK(interpreter_array_mutex);
return;
}
/*
* only the first interpreter waits for other threads
*/
if (interpreter != interpreter_array[0]) {
- UNLOCK(interpreter_array_mutex);
return;
}
+ LOCK(interpreter_array_mutex);
for (i = 1; i < n_interpreters; ++i) {
Parrot_Interp thread_interp = interpreter_array[i];
if (thread_interp == NULL)
continue;
if (thread_interp->thread_data->state == THREAD_STATE_JOINABLE ||
- thread_interp->thread_data->state == THREAD_STATE_FINISHED) {
+ (thread_interp->thread_data->state & THREAD_STATE_FINISHED)) {
+
void *retval;
thread_interp->thread_data->state |= THREAD_STATE_JOINED;
UNLOCK(interpreter_array_mutex);