green-threads: add thread_desc initial structure
authorDaniel Kochmański <daniel@turtleware.eu>
Mon, 24 Aug 2015 16:25:42 +0000 (18:25 +0200)
committerDaniel Kochmański <daniel@turtleware.eu>
Mon, 24 Aug 2015 16:25:42 +0000 (18:25 +0200)
Signed-off-by: Daniel Kochmański <daniel@turtleware.eu>
src/c/lwp.d
src/h/lwp.h
src/h/object.h

index 4643ee1..e3e7c05 100644 (file)
 
 #include <ecl/ecl.h>
 
+thread_desc *
+make_thread_desc (cl_object thread) {
+        thread_desc *desc;
+
+        desc = (thread_desc *)malloc(sizeof(thread_desc));
+        desc->thread = thread;
+        desc->status = ECL_THREAD_SUSPENDED;
+        desc->base = NULL;
+        /* desc->env = ??; */
+        desc->slice = 0;
+        desc->input = NULL;
+        desc->lpd = NULL;
+        desc->next = NULL;
+}
+
 cl_object
 si_make_thread (cl_object fun) {
         cl_object x;
 
+        if (cl_functionp(fun) == ECL_NIL)
+                FEwrong_type_argument(@'function', fun);
+
         x = ecl_alloc_object(t_thread);
+        x->thread.entry = fun;
         x->thread.cont = ECL_NIL;
+        x->thread.data = make_thread_desc(x);
         return x;
 }
 
index dff6614..64a7988 100644 (file)
@@ -1,3 +1,4 @@
+/* -*- mode: c; c-basic-offset: 8 -*- */
 /*
     lwp.h  -- Light weight processes.
 */
 extern "C" {
 #endif
 
-  /* XXX: put lwp structures here */
+typedef struct lpd {
+        /* this is basically env (right?) – compare sources */
+} lpd;
+
+enum {
+        ECL_THREAD_RUNNING = 0,
+        ECL_THREAD_SUSPENDED,
+        ECL_THREAD_STOPPED,
+        ECL_THREAD_DEAD,
+        ECL_THREAD_WAITING,
+        ECL_THREAD_DELAYED
+};
+
+typedef struct thread_desc {
+        cl_object   thread;     /* point back to its thread */
+        cl_index    status;     /* RUNNING or STOPPED or DEAD */
+        int        *base;      /* Stack Base */
+        sigjmp_buf  env;       /* Stack Environment */
+        int         slice;      /* time out */
+        FILE      *input;      /* File pointer waiting input on */
+        lpd        *lpd;        /* lisp process descriptor */
+        struct thread_desc *next;
+} thread_desc;
 
 #ifdef __cplusplus
 }
index 5b41157..09b33a6 100644 (file)
@@ -852,6 +852,7 @@ struct ecl_dummy {
 };
 
 #ifdef ECL_LWP
+
 struct ecl_cont {
         _ECL_HDR2(resumed, timed_out);
         cl_object thread;
@@ -859,7 +860,9 @@ struct ecl_cont {
 
 struct ecl_thread {
         _ECL_HDR;
-        cl_object  cont;           /* its continuation */
+        cl_object entry;          /* entry point */
+        cl_object cont;           /* its continuation */
+        struct thread_desc *data; /* actual thread */
 };
 #endif /* ECL_LWP */