cvsuser 03/12/14 04:55:28
Modified: . MANIFEST
include/parrot events.h interpreter.h thread.h tsq.h
config/gen/platform darwin.h generic.h openbsd.h
src events.c exceptions.c interpreter.c tsq.c
Added: include/parrot thr_pthread.h
Log:
event-handling-3
* move common phtread defines to new thr_pthread.h
* add defines for init and destroy of cond, mutex
* initialize and destroy a task queue
* add some event typedefs
* all non-functional yet, just a first try to prepare infrastructure
Revision Changes Path
1.514 +1 -0 parrot/MANIFEST
Index: MANIFEST
===================================================================
RCS file: /cvs/public/parrot/MANIFEST,v
retrieving revision 1.513
retrieving revision 1.514
diff -u -w -r1.513 -r1.514
--- MANIFEST 10 Dec 2003 17:18:27 -0000 1.513
+++ MANIFEST 14 Dec 2003 12:55:06 -0000 1.514
@@ -1630,6 +1630,7 @@
include/parrot/string.h [devel]include
include/parrot/string_funcs.h [devel]include
include/parrot/sub.h [devel]include
+include/parrot/thr_pthread.h [devel]include
include/parrot/thread.h [devel]include
include/parrot/trace.h [devel]include
include/parrot/tsq.h [devel]include
1.5 +31 -3 parrot/include/parrot/events.h
Index: events.h
===================================================================
RCS file: /cvs/public/parrot/include/parrot/events.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -r1.4 -r1.5
--- events.h 21 Jul 2003 18:00:42 -0000 1.4
+++ events.h 14 Dec 2003 12:55:16 -0000 1.5
@@ -1,7 +1,7 @@
/* events.h
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: events.h,v 1.4 2003/07/21 18:00:42 chromatic Exp $
+ * $Id: events.h,v 1.5 2003/12/14 12:55:16 leo Exp $
* Overview:
* This api will handle parrot events
* Data Structure and Algorithms:
@@ -13,10 +13,38 @@
#if !defined(PARROT_EVENT_H_GUARD)
#define PARROT_EVENT_H_GUARD
-#define CHECK_EVENTS(x)
-#define HANDLE_EVENTS(x)
+typedef void* (*event_func_t)(Parrot_Interp, void*);
+
+typedef enum {
+ EVENT_TYPE_NONE,
+ EVENT_TYPE_EVENT,
+ EVENT_TYPE_IO,
+ EVENT_TYPE_MSG,
+ EVENT_TYPE_ASYNC_IO,
+ EVENT_TYPE_TIMER,
+ EVENT_TYPE_CLASS_CHANGED,
+ EVENT_TYPE_SIGNAL
+} parrot_event_type_enum;
+
+typedef struct {
+ parrot_event_type_enum type;
+ Parrot_Interp interp;
+ event_func_t event_func;
+ void* data;
+ union {
+ STRING* msg; /* for testing only */
+ } u;
+} parrot_event;
+
+void Parrot_schedule_event(Parrot_Interp, parrot_event*);
+
+#define CHECK_EVENTS(i) Parrot_do_check_events(i)
+#define HANDLE_EVENTS(i) Parrot_do_handle_events(i)
void Parrot_init_signals(void);
+void Parrot_init_events(Parrot_Interp);
+void Parrot_do_check_events(Parrot_Interp);
+void Parrot_do_handle_events(Parrot_Interp);
#endif
1.106 +7 -2 parrot/include/parrot/interpreter.h
Index: interpreter.h
===================================================================
RCS file: /cvs/public/parrot/include/parrot/interpreter.h,v
retrieving revision 1.105
retrieving revision 1.106
diff -u -w -r1.105 -r1.106
--- interpreter.h 13 Dec 2003 15:01:15 -0000 1.105
+++ interpreter.h 14 Dec 2003 12:55:16 -0000 1.106
@@ -1,7 +1,7 @@
/* interpreter.h
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: interpreter.h,v 1.105 2003/12/13 15:01:15 leo Exp $
+ * $Id: interpreter.h,v 1.106 2003/12/14 12:55:16 leo Exp $
* Overview:
* The interpreter api handles running the operations
* Data Structure and Algorithms:
@@ -155,7 +155,12 @@
size_t op_count; /* The number of ops */
op_info_t *op_info_table; /* Opcode info table (name, nargs, arg types) */
- op_func_t *op_func_table;
+ op_func_t *op_func_table; /* opcode dispatch table (functios, labels,
+ or nothing (e.g. switched core), which
+ the interpreter is currently running */
+ op_func_t *evc_func_table; /* opcode dispatch for event checking */
+ op_func_t *save_func_table; /* for restoring op_func_table */
+
int n_libs; /* count of libs below */
op_lib_t **all_op_libs; /* all loaded opcode libraries */
1.7 +17 -8 parrot/include/parrot/thread.h
Index: thread.h
===================================================================
RCS file: /cvs/public/parrot/include/parrot/thread.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -w -r1.6 -r1.7
--- thread.h 13 Dec 2003 12:56:56 -0000 1.6
+++ thread.h 14 Dec 2003 12:55:16 -0000 1.7
@@ -1,7 +1,7 @@
/* thread.h
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: thread.h,v 1.6 2003/12/13 12:56:56 leo Exp $
+ * $Id: thread.h,v 1.7 2003/12/14 12:55:16 leo Exp $
* Overview:
* This is the api header for the thread primitives
* Data Structure and Algorithms:
@@ -16,14 +16,23 @@
#include "parrot/parrot.h"
#ifndef PARROT_SYNC_PRIMITIVES_DEFINED
-#define LOCK(x)
-#define UNLOCK(x)
-#define COND_WAIT(x, y)
-#define COND_SIGNAL(x)
-#define COND_BROADCAST(x)
-#define Parrot_mutex INTVAL
-#define Parrot_cond INTVAL
+# define LOCK(m)
+# define UNLOCK(m)
+# define COND_WAIT(c, m)
+# define COND_TIMED_WAIT(c, m, t)
+# define COND_SIGNAL(c)
+# define COND_BROADCAST(c)
+
+# define MUTEX_INIT(m)
+# define MUTEX_DESTROY(m)
+
+# define COND_INIT(c)
+# define COND_DESTROY(c)
+
+# define Parrot_mutex int
+# define Parrot_cond int
+
#endif
#endif
1.6 +4 -1 parrot/include/parrot/tsq.h
Index: tsq.h
===================================================================
RCS file: /cvs/public/parrot/include/parrot/tsq.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -w -r1.5 -r1.6
--- tsq.h 21 Jul 2003 18:00:42 -0000 1.5
+++ tsq.h 14 Dec 2003 12:55:16 -0000 1.6
@@ -1,7 +1,7 @@
/* tsq.h
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: tsq.h,v 1.5 2003/07/21 18:00:42 chromatic Exp $
+ * $Id: tsq.h,v 1.6 2003/12/14 12:55:16 leo Exp $
* Overview:
* Defines the thread-safe queue system
* Data Structure and Algorithms:
@@ -35,12 +35,15 @@
};
QUEUE_ENTRY *pop_entry(QUEUE *);
+PARROT_INLINE QUEUE_ENTRY *peek_entry(QUEUE *);
QUEUE_ENTRY *wait_for_entry(QUEUE *);
void push_entry(QUEUE *, QUEUE_ENTRY *);
void queue_lock(QUEUE *);
void queue_unlock(QUEUE *);
void queue_signal(QUEUE *);
void queue_wait(QUEUE *);
+QUEUE* queue_init(UINTVAL prio);
+void queue_destroy(QUEUE *);
#endif /* PARROT_TSQ_H_GUARD */
1.1 parrot/include/parrot/thr_pthread.h
Index: thr_pthread.h
===================================================================
/* thr_pthread.h
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
* $Id: thr_pthread.h,v 1.1 2003/12/14 12:55:16 leo Exp $
* Overview:
* POSIS pthread interface
* Data Structure and Algorithms:
* History:
* 2003.12.14 Initial rev by leo
* Moved common code from generic, darwin, openbsd
* to this file.
* Notes:
* References:
*/
#if !defined(PARROT_THR_PTHREAD_H_GUARD)
#define PARROT_THR_PTHREAD_H_GUARD
# include <pthread.h>
# define PARROT_SYNC_PRIMITIVES_DEFINED
# define LOCK(m) pthread_mutex_lock(&m)
# define UNLOCK(m) pthread_mutex_unlock(&m)
# define COND_WAIT(c,m) pthread_cond_wait(&c, &m)
# define COND_TIMED_WAIT(c,m,t) pthread_cond_timed_wait(&c, &m, t)
# define COND_SIGNAL(c) pthread_cond_signal(&c)
# define COND_BROADCAST(c) pthread_cond_broadcast(&c)
/*
* for now use a fast mutex w/o error checking and non recursive
*/
# define MUTEX_INIT(m) pthread_mutex_init(&m, NULL)
# define MUTEX_DESTROY(m) pthread_mutex_destroy(&m)
# define COND_INIT(c) pthread_cond_init(&c, NULL);
# define COND_DESTROY(c) pthread_cond_destroy(&c)
typedef pthread_mutex_t Parrot_mutex;
typedef pthread_cond_t Parrot_cond;
#endif
/*
* Local variables:
* c-indentation-style: bsd
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*
* vim: expandtab shiftwidth=4:
*/
1.6 +1 -9 parrot/config/gen/platform/darwin.h
Index: darwin.h
===================================================================
RCS file: /cvs/public/parrot/config/gen/platform/darwin.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -w -r1.5 -r1.6
--- darwin.h 13 Dec 2003 12:56:32 -0000 1.5
+++ darwin.h 14 Dec 2003 12:55:21 -0000 1.6
@@ -3,15 +3,7 @@
*/
#ifdef PARROT_HAS_HEADER_PTHREAD
-# include <pthread.h>
-# define PARROT_SYNC_PRIMITIVES_DEFINED
-# define LOCK(m) pthread_mutex_lock(&m)
-# define UNLOCK(m) pthread_mutex_unlock(&m)
-# define COND_WAIT(c,m) pthread_cond_wait(&c, &m)
-# define COND_SIGNAL(c) pthread_cond_signal(&c)
-# define COND_BROADCAST(c) pthread_cond_broadcast(&c)
-typedef pthread_mutex_t Parrot_mutex;
-typedef pthread_cond_t Parrot_cond;
+# include "parrot/thr_pthread.h"
#endif
1.12 +1 -9 parrot/config/gen/platform/generic.h
Index: generic.h
===================================================================
RCS file: /cvs/public/parrot/config/gen/platform/generic.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -w -r1.11 -r1.12
--- generic.h 13 Dec 2003 12:56:32 -0000 1.11
+++ generic.h 14 Dec 2003 12:55:21 -0000 1.12
@@ -48,15 +48,7 @@
#endif
#ifdef PARROT_HAS_HEADER_PTHREAD
-# include <pthread.h>
-# define PARROT_SYNC_PRIMITIVES_DEFINED
-# define LOCK(m) pthread_mutex_lock(&m)
-# define UNLOCK(m) pthread_mutex_unlock(&m)
-# define COND_WAIT(c,m) pthread_cond_wait(&c, &m)
-# define COND_SIGNAL(c) pthread_cond_signal(&c)
-# define COND_BROADCAST(c) pthread_cond_broadcast(&c)
- typedef pthread_mutex_t Parrot_mutex;
- typedef pthread_cond_t Parrot_cond;
+# include "parrot/thr_pthread.h"
#endif
#endif
1.3 +1 -9 parrot/config/gen/platform/openbsd.h
Index: openbsd.h
===================================================================
RCS file: /cvs/public/parrot/config/gen/platform/openbsd.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -w -r1.2 -r1.3
--- openbsd.h 13 Dec 2003 12:56:32 -0000 1.2
+++ openbsd.h 14 Dec 2003 12:55:21 -0000 1.3
@@ -53,15 +53,7 @@
#endif
#ifdef PARROT_HAS_HEADER_PTHREAD
-# include <pthread.h>
-# define PARROT_SYNC_PRIMITIVES_DEFINED
-# define LOCK(m) pthread_mutex_lock(&m)
-# define UNLOCK(m) pthread_mutex_unlock(&m)
-# define COND_WAIT(c,m) pthread_cond_wait(&c, &m)
-# define COND_SIGNAL(c) pthread_cond_signal(&c)
-# define COND_BROADCAST(c) pthread_cond_broadcast(&c)
- typedef pthread_mutex_t Parrot_mutex;
- typedef pthread_cond_t Parrot_cond;
+# include "parrot/thr_pthread.h"
#endif
#endif
1.7 +31 -9 parrot/src/events.c
Index: events.c
===================================================================
RCS file: /cvs/public/parrot/src/events.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -w -r1.6 -r1.7
--- events.c 23 Oct 2003 17:48:59 -0000 1.6
+++ events.c 14 Dec 2003 12:55:25 -0000 1.7
@@ -1,7 +1,7 @@
/* events.c
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: events.c,v 1.6 2003/10/23 17:48:59 robert Exp $
+ * $Id: events.c,v 1.7 2003/12/14 12:55:25 leo Exp $
* Overview:
* User-level event handling stuff
* Data Structure and Algorithms:
@@ -12,22 +12,14 @@
#include "parrot/parrot.h"
-#ifdef PARROT_HAS_HEADER_SETJMP
-/* XXX s. exceptions.c */
-void do_exception(exception_severity severity, long error);
-void Parrot_init_signals(void);
-#endif
-
static void
sig_handler(int signum)
{
switch (signum) {
default:
-#ifdef PARROT_HAS_HEADER_SETJMP
/* quick hack to test signals and exceptions
*/
do_exception(0, -signum);
-#endif
break;
}
}
@@ -39,6 +31,36 @@
* s. t/op/hacks_4.pasm
*/
/* Parrot_set_sighandler(SIGFPE, sig_handler);*/
+}
+
+/*
+ * initialize the event system
+ */
+void
+Parrot_init_events(Parrot_Interp interpreter)
+{
+ /*
+ * remember op_func_table
+ */
+ interpreter->save_func_table = interpreter->op_func_table;
+}
+
+/*
+ * insert event into task queue
+ */
+void
+Parrot_schedule_event(Parrot_Interp interpreter, parrot_event* ev)
+{
+}
+
+void
+Parrot_do_check_events(Parrot_Interp interpreter)
+{
+}
+
+void
+Parrot_do_handle_events(Parrot_Interp interpreter)
+{
}
/*
1.45 +2 -25 parrot/src/exceptions.c
Index: exceptions.c
===================================================================
RCS file: /cvs/public/parrot/src/exceptions.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -w -r1.44 -r1.45
--- exceptions.c 7 Dec 2003 11:44:14 -0000 1.44
+++ exceptions.c 14 Dec 2003 12:55:26 -0000 1.45
@@ -1,7 +1,7 @@
/* exceptions.c
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: exceptions.c,v 1.44 2003/12/07 11:44:14 leo Exp $
+ * $Id: exceptions.c,v 1.45 2003/12/14 12:55:26 leo Exp $
* Overview:
* define the internal interpreter exceptions
* Data Structure and Algorithms:
@@ -209,11 +209,7 @@
if (PObj_get_FLAGS(handler) & PObj_private0_FLAG) {
/* its a C exception handler */
Parrot_exception *jb = (Parrot_exception *) handler->cache.struct_val;
-#ifdef PARROT_HAS_HEADER_SETJMP
longjmp(jb->destination, 1);
-#else
- return NULL; /* we are lost */
-#endif
}
/* return the address of the handler */
return handler->cache.struct_val;
@@ -236,15 +232,6 @@
return handler->cache.struct_val;
}
-#ifndef PARROT_HAS_HEADER_SETJMP
-void
-rethrow_c_exception(Parrot_Interp interpreter)
-{
-}
-#endif
-
-#ifdef PARROT_HAS_HEADER_SETJMP
-/* XXX s. interpreter.c */
Parrot_exception the_exception;
/*
@@ -274,6 +261,7 @@
the_exception.msg = VTABLE_get_string_keyed_int(interpreter, exception, 0);
longjmp(the_exception.destination, 1);
}
+
static size_t
dest2offset(Parrot_Interp interpreter, opcode_t *dest)
{
@@ -343,7 +331,6 @@
the_exception.resume = NULL;
longjmp(the_exception.destination, 1);
}
-#endif
/*
* instead of internal_exception this throws a real exception
@@ -352,7 +339,6 @@
real_exception(struct Parrot_Interp *interpreter, void *ret_addr,
int exitcode, const char *format, ...)
{
-#ifdef PARROT_HAS_HEADER_SETJMP
STRING *msg;
@@ -393,15 +379,6 @@
* reenter runloop
*/
longjmp(the_exception.destination, 1);
-#else
- va_list arglist;
- UNUSED(interpreter);
- UNUSED(ret_addr);
- va_start(arglist, format);
- vfprintf(stderr, format, arglist);
- va_end(arglist);
- Parrot_exit(exitcode);
-#endif
}
/*
1.237 +1 -6 parrot/src/interpreter.c
Index: interpreter.c
===================================================================
RCS file: /cvs/public/parrot/src/interpreter.c,v
retrieving revision 1.236
retrieving revision 1.237
diff -u -w -r1.236 -r1.237
--- interpreter.c 13 Dec 2003 15:01:17 -0000 1.236
+++ interpreter.c 14 Dec 2003 12:55:27 -0000 1.237
@@ -1,7 +1,7 @@
/* interpreter.c
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: interpreter.c,v 1.236 2003/12/13 15:01:17 leo Exp $
+ * $Id: interpreter.c,v 1.237 2003/12/14 12:55:27 leo Exp $
* Overview:
* The interpreter api handles running the operations
* Data Structure and Algorithms:
@@ -619,14 +619,10 @@
* run parrot ops
* set exception handler and/or resume after exception
*/
-#ifdef PARROT_HAS_HEADER_SETJMP
-/* XXX s. exception.c */
extern Parrot_exception the_exception;
-#endif
void
runops(struct Parrot_Interp *interpreter, size_t offset)
{
-#ifdef PARROT_HAS_HEADER_SETJMP
if (setjmp(the_exception.destination)) {
/* an exception was thrown */
offset = handle_exception(interpreter);
@@ -639,7 +635,6 @@
Parrot_floatval_time() - profile->starttime;
}
}
-#endif
runops_ex(interpreter, offset);
/*
* not yet - this needs classifying of exceptions and handlers
1.8 +33 -3 parrot/src/tsq.c
Index: tsq.c
===================================================================
RCS file: /cvs/public/parrot/src/tsq.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -w -r1.7 -r1.8
--- tsq.c 13 Dec 2003 12:57:02 -0000 1.7
+++ tsq.c 14 Dec 2003 12:55:27 -0000 1.8
@@ -1,7 +1,7 @@
/* tsq.c
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: tsq.c,v 1.7 2003/12/13 12:57:02 leo Exp $
+ * $Id: tsq.c,v 1.8 2003/12/14 12:55:27 leo Exp $
* Overview:
* Thread-safe queues
* Data Structure and Algorithms:
@@ -23,11 +23,20 @@
return returnval;
}
+/*
+ * this does not locking, so the result might have changed already
+ * but the synched pop_entry checks again and returns NULL, if
+ * queue is empty
+ */
+PARROT_INLINE QUEUE_ENTRY *
+peek_entry(QUEUE *queue) {
+ return queue->head;
+}
+
/* Grab an entry off the queue with no synchronization. Internal only,
because it's darned evil and shouldn't be used outside the
module. It's in here so we don't have to duplicate pop code */
-static
-QUEUE_ENTRY *
+static QUEUE_ENTRY *
nosync_pop_entry(QUEUE *queue) {
QUEUE_ENTRY *returnval;
if (!queue->head) {
@@ -91,6 +100,27 @@
void
queue_wait(QUEUE *queue) {
COND_WAIT(queue->queue_condition, queue->queue_mutex);
+}
+
+QUEUE*
+queue_init(UINTVAL prio)
+{
+ QUEUE *queue = mem_sys_allocate(sizeof(QUEUE));
+ queue->head = queue->tail = NULL;
+ queue->max_prio = prio;
+ COND_INIT(queue->queue_condition);
+ MUTEX_INIT(queue->queue_mutex);
+ return queue;
+}
+
+void
+queue_destroy(QUEUE *queue)
+{
+ if (peek_entry(queue))
+ internal_exception(1, "Queue not emty on destroy");
+ COND_DESTROY(queue->queue_condition);
+ MUTEX_DESTROY(queue->queue_mutex);
+ mem_sys_free(queue);
}
/*