cvsuser 03/12/28 12:17:43
Modified: include/parrot thr_pthread.h thread.h
src thread.c
Log:
parrot-threads-16
* implement cleanup push and pop handlers
* hope these weird macros are ok - I hate them
Revision Changes Path
1.6 +6 -1 parrot/include/parrot/thr_pthread.h
Index: thr_pthread.h
===================================================================
RCS file: /cvs/public/parrot/include/parrot/thr_pthread.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -w -r1.5 -r1.6
--- thr_pthread.h 18 Dec 2003 14:51:21 -0000 1.5
+++ thr_pthread.h 28 Dec 2003 20:17:15 -0000 1.6
@@ -1,7 +1,7 @@
/* thr_pthread.h
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: thr_pthread.h,v 1.5 2003/12/18 14:51:21 leo Exp $
+ * $Id: thr_pthread.h,v 1.6 2003/12/28 20:17:15 leo Exp $
* Overview:
* POSIS pthread interface
* Data Structure and Algorithms:
@@ -52,9 +52,14 @@
# define JOIN(t, ret) pthread_join(t, &ret)
# define DETACH(t) pthread_detach(t)
+# define CLEANUP_PUSH(f, a) pthread_cleanup_push(f, a)
+# define CLEANUP_POP(a) pthread_cleanup_pop(a)
+
typedef pthread_mutex_t Parrot_mutex;
typedef pthread_cond_t Parrot_cond;
typedef pthread_t Parrot_thread;
+
+typedef void (*Cleanup_Handler)(void *);
#endif
1.17 +6 -1 parrot/include/parrot/thread.h
Index: thread.h
===================================================================
RCS file: /cvs/public/parrot/include/parrot/thread.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -w -r1.16 -r1.17
--- thread.h 28 Dec 2003 14:07:07 -0000 1.16
+++ thread.h 28 Dec 2003 20:17:15 -0000 1.17
@@ -1,7 +1,7 @@
/* thread.h
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: thread.h,v 1.16 2003/12/28 14:07:07 leo Exp $
+ * $Id: thread.h,v 1.17 2003/12/28 20:17:15 leo Exp $
* Overview:
* This is the api header for the thread primitives
* Data Structure and Algorithms:
@@ -36,9 +36,14 @@
# define JOIN(t, ret)
# define DETACH(t)
+# define CLEANUP_PUSH(f, a)
+# define CLEANUP_POP(a)
+
# define Parrot_mutex int
# define Parrot_cond int
# define Parrot_thread int
+
+typedef void (*Cleanup_Handler)(void *);
# ifndef _STRUCT_TIMESPEC
# define _STRUCT_TIMESPEC
1.12 +20 -3 parrot/src/thread.c
Index: thread.c
===================================================================
RCS file: /cvs/public/parrot/src/thread.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -w -r1.11 -r1.12
--- thread.c 28 Dec 2003 14:07:11 -0000 1.11
+++ thread.c 28 Dec 2003 20:17:43 -0000 1.12
@@ -1,7 +1,7 @@
/* thread.c
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: thread.c,v 1.11 2003/12/28 14:07:11 leo Exp $
+ * $Id: thread.c,v 1.12 2003/12/28 20:17:43 leo Exp $
* Overview:
* Thread handling stuff
* Data Structure and Algorithms:
@@ -200,6 +200,13 @@
return interpreter_array[tid];
}
+
+static void
+mutex_unlock(void *arg)
+{
+ UNLOCK(*(Parrot_mutex*) arg);
+}
+
/*
* join (wait for) a joinable thread
*/
@@ -217,7 +224,17 @@
interpreter->thread_data->state |= THREAD_STATE_JOINED;
UNLOCK(interpreter_array_mutex);
JOIN(interpreter->thread_data->thread, retval);
- LOCK(interpreter_array_mutex);
+ /*
+ * we need to push a cleanup handler here: if cloning
+ * of the retval fails (e.g. it's a NULLPMC) this lock
+ * isn't released until eternity or someone hits ^C
+ *
+ * TODO This is needed for all places holding a lock for
+ * non-trivial tasks
+ * -leo
+ */
+ CLEANUP_PUSH(mutex_unlock, &interpreter_array_mutex);
+
if (retval) {
/* clone the PMC into caller */
PMC *parent_ret = VTABLE_clone(parent, (PMC*)retval);
@@ -225,7 +242,7 @@
}
interpreter_array[tid] = NULL;
Parrot_really_destroy(0, interpreter);
- UNLOCK(interpreter_array_mutex);
+ CLEANUP_POP(1);
return retval;
}
/*