guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 06/26: Inline struct scm_vm into struct scm_i_thread


From: Andy Wingo
Subject: [Guile-commits] 06/26: Inline struct scm_vm into struct scm_i_thread
Date: Tue, 26 Jun 2018 11:26:09 -0400 (EDT)

wingo pushed a commit to branch master
in repository guile.

commit 2480761bde7d55ef05cc11eb49902ede84c70a0a
Author: Andy Wingo <address@hidden>
Date:   Sun Jun 24 08:59:42 2018 +0200

    Inline struct scm_vm into struct scm_i_thread
    
    * libguile/threads.h (scm_i_thread): Inline struct scm_vm into struct
      scm_i_thread, as these exist in a one-to-one relationship.
    * libguile/threads.c (guilify_self_1, thread_mark, on_thread_exit):
    * libguile/control.c (scm_suspendable_continuation_p):
    * libguile/vm.c (init_vm, thread_vm): Adapt users.
---
 libguile/control.c |  2 +-
 libguile/threads.c | 21 +++++----------------
 libguile/threads.h |  3 ++-
 libguile/vm.c      | 17 +++++------------
 4 files changed, 13 insertions(+), 30 deletions(-)

diff --git a/libguile/control.c b/libguile/control.c
index bd12fb6..e472b48 100644
--- a/libguile/control.c
+++ b/libguile/control.c
@@ -223,7 +223,7 @@ scm_suspendable_continuation_p (SCM tag)
 
   if (scm_dynstack_find_prompt (&thread->dynstack, tag, &flags,
                                 NULL, NULL, NULL, &registers))
-    return scm_from_bool (registers == thread->vp->resumable_prompt_cookie);
+    return scm_from_bool (registers == thread->vm.resumable_prompt_cookie);
 
   return SCM_BOOL_F;
 }
diff --git a/libguile/threads.c b/libguile/threads.c
index a8aa0da..2a31878 100644
--- a/libguile/threads.c
+++ b/libguile/threads.c
@@ -114,8 +114,8 @@ thread_mark (GC_word *addr, struct GC_ms_entry 
*mark_stack_ptr,
         }
     }
 
-  if (t->vp)
-    mark_stack_ptr = scm_i_vm_mark_stack (t->vp, mark_stack_ptr,
+  if (t->vm.stack_bottom)
+    mark_stack_ptr = scm_i_vm_mark_stack (&t->vm, mark_stack_ptr,
                                           mark_stack_limit);
 
   return mark_stack_ptr;
@@ -380,23 +380,17 @@ guilify_self_1 (struct GC_stack_base *base, int 
needs_unregister)
      cause GC to run, and GC could cause finalizers, which could invoke
      Scheme functions, which need the current thread to be set.  */
 
+  memset (&t, 0, sizeof (t));
+
   t.pthread = scm_i_pthread_self ();
   t.handle = SCM_BOOL_F;
   t.result = SCM_BOOL_F;
-  t.freelists = NULL;
-  t.pointerless_freelists = NULL;
-  t.dynamic_state = NULL;
-  t.dynstack.base = NULL;
-  t.dynstack.top = NULL;
-  t.dynstack.limit = NULL;
   t.pending_asyncs = SCM_EOL;
   t.block_asyncs = 1;
   t.base = base->mem_base;
   t.continuation_root = SCM_EOL;
   t.continuation_base = t.base;
   scm_i_pthread_cond_init (&t.sleep_cond, NULL);
-  t.wake = NULL;
-  t.vp = NULL;
 
   if (pipe2 (t.sleep_pipe, O_CLOEXEC) != 0)
     /* FIXME: Error conditions during the initialization phase are handled
@@ -514,12 +508,7 @@ on_thread_exit (void *v)
   t->dynstack.base = NULL;
   t->dynstack.top = NULL;
   t->dynstack.limit = NULL;
-  {
-    struct scm_vm *vp = t->vp;
-    t->vp = NULL;
-    if (vp)
-      scm_i_vm_free_stack (vp);
-  }
+  scm_i_vm_free_stack (&t->vm);
 
 #ifdef SCM_HAVE_THREAD_STORAGE_CLASS
   scm_i_current_thread = NULL;
diff --git a/libguile/threads.h b/libguile/threads.h
index 151c27b..6cbab2a 100644
--- a/libguile/threads.h
+++ b/libguile/threads.h
@@ -30,6 +30,7 @@
 #include "libguile/iselect.h"
 #include "libguile/smob.h"
 #include "libguile/continuations.h"
+#include "libguile/vm.h"
 
 #if SCM_USE_PTHREAD_THREADS
 #include "libguile/pthread-threads.h"
@@ -102,7 +103,7 @@ typedef struct scm_i_thread {
   SCM_STACKITEM *continuation_base;
 
   /* For keeping track of the stack and registers. */
-  struct scm_vm *vp;
+  struct scm_vm vm;
   SCM_STACKITEM *base;
   jmp_buf regs;
 } scm_i_thread;
diff --git a/libguile/vm.c b/libguile/vm.c
index 434b3b5..cc0f58c 100644
--- a/libguile/vm.c
+++ b/libguile/vm.c
@@ -826,14 +826,10 @@ expand_stack (union scm_vm_stack_element *old_bottom, 
size_t old_size,
 }
 #undef FUNC_NAME
 
-static struct scm_vm *
-make_vm (void)
-#define FUNC_NAME "make_vm"
+static void
+init_vm (struct scm_vm *vp)
 {
   int i;
-  struct scm_vm *vp;
-
-  vp = scm_gc_malloc (sizeof (struct scm_vm), "vm");
 
   vp->stack_size = page_size / sizeof (union scm_vm_stack_element);
   vp->stack_bottom = allocate_stack (vp->stack_size);
@@ -854,10 +850,7 @@ make_vm (void)
   vp->trace_level = 0;
   for (i = 0; i < SCM_VM_NUM_HOOKS; i++)
     vp->hooks[i] = SCM_BOOL_F;
-
-  return vp;
 }
-#undef FUNC_NAME
 
 static void
 return_unused_stack_to_os (struct scm_vm *vp)
@@ -1158,10 +1151,10 @@ vm_expand_stack (struct scm_vm *vp, union 
scm_vm_stack_element *new_sp)
 static struct scm_vm *
 thread_vm (scm_i_thread *t)
 {
-  if (SCM_UNLIKELY (!t->vp))
-    t->vp = make_vm ();
+  if (SCM_UNLIKELY (!t->vm.stack_bottom))
+    init_vm (&t->vm);
 
-  return t->vp;
+  return &t->vm;
 }
 
 struct scm_vm *



reply via email to

[Prev in Thread] Current Thread [Next in Thread]