guile-commits
[Top][All Lists]
Advanced

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

[Guile-commits] 03/03: Slim thread cleanup


From: Andy Wingo
Subject: [Guile-commits] 03/03: Slim thread cleanup
Date: Mon, 14 Nov 2016 21:02:39 +0000 (UTC)

wingo pushed a commit to branch master
in repository guile.

commit fcb43488b39db6c2ad15c2dc7f7b53aa492021b4
Author: Andy Wingo <address@hidden>
Date:   Mon Nov 14 21:57:46 2016 +0100

    Slim thread cleanup
    
    * libguile/threads.c (on_thread_exit): Clean up the cleanup.  We no
      longer need to re-enter Guile mode, and some of the comments were
      incorrect.
---
 libguile/threads.c |   47 ++++-------------------------------------------
 1 file changed, 4 insertions(+), 43 deletions(-)

diff --git a/libguile/threads.c b/libguile/threads.c
index 2798be7..4b6d43c 100644
--- a/libguile/threads.c
+++ b/libguile/threads.c
@@ -499,55 +499,18 @@ guilify_self_2 (SCM parent)
 
 
 
-/* Perform thread tear-down, in guile mode.
- */
-static void *
-do_thread_exit (void *v)
-{
-  scm_i_thread *t = (scm_i_thread *) v;
-
-  scm_i_scm_pthread_mutex_lock (&t->admin_mutex);
-  t->exited = 1;
-  close (t->sleep_pipe[0]);
-  close (t->sleep_pipe[1]);
-  scm_i_pthread_mutex_unlock (&t->admin_mutex);
-
-  return NULL;
-}
-
-static void *
-do_thread_exit_trampoline (struct GC_stack_base *sb, void *v)
-{
-  /* Won't hurt if we are already registered.  */
-#if SCM_USE_PTHREAD_THREADS
-  GC_register_my_thread (sb);
-#endif
-
-  return scm_with_guile (do_thread_exit, v);
-}
-
 static void
 on_thread_exit (void *v)
 {
   /* This handler is executed in non-guile mode.  */
   scm_i_thread *t = (scm_i_thread *) v, **tp;
 
-  /* If we were canceled, we were unable to clear `t->guile_mode', so do
-     it here.  */
-  t->guile_mode = 0;
-
-  /* Reinstate the current thread for purposes of scm_with_guile
-     guile-mode cleanup handlers.  Only really needed in the non-TLS
-     case but it doesn't hurt to be consistent.  */
-  scm_i_pthread_setspecific (scm_i_thread_key, t);
+  t->exited = 1;
 
-  /* Scheme-level thread finalizers and other cleanup needs to happen in
-     guile mode.  */
-  GC_call_with_stack_base (do_thread_exit_trampoline, t);
+  close (t->sleep_pipe[0]);
+  close (t->sleep_pipe[1]);
+  t->sleep_pipe[0] = t->sleep_pipe[1] = -1;
 
-  /* Removing ourself from the list of all threads needs to happen in
-     non-guile mode since all SCM values on our stack become
-     unprotected once we are no longer in the list.  */
   scm_i_pthread_mutex_lock (&thread_admin_mutex);
   for (tp = &all_threads; *tp; tp = &(*tp)->next_thread)
     if (*tp == t)
@@ -570,8 +533,6 @@ on_thread_exit (void *v)
 
   scm_i_pthread_mutex_unlock (&thread_admin_mutex);
 
-  scm_i_pthread_setspecific (scm_i_thread_key, NULL);
-
   if (t->vp)
     {
       scm_i_vm_free_stack (t->vp);



reply via email to

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