guile-commits
[Top][All Lists]
Advanced

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

[Guile-commits] GNU Guile branch, master, updated. release_1-9-3-62-g705


From: Ludovic Courtès
Subject: [Guile-commits] GNU Guile branch, master, updated. release_1-9-3-62-g705edb9
Date: Fri, 09 Oct 2009 12:23:19 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Guile".

http://git.savannah.gnu.org/cgit/guile.git/commit/?id=705edb959b3093cb1cbe1390110d96ee833b63fc

The branch, master has been updated
       via  705edb959b3093cb1cbe1390110d96ee833b63fc (commit)
       via  46935a1fac58e50276f7e7e49e5fa6bab53c0848 (commit)
       via  b8ec9daba60ceb14b443d3a44ab5043edcb474df (commit)
      from  98241dc53fc66ec86c01b9eeea426def2f787cec (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 705edb959b3093cb1cbe1390110d96ee833b63fc
Author: Ludovic Courtès <address@hidden>
Date:   Fri Oct 2 16:32:34 2009 +0200

    Use TLS when available for `SCM_I_CURRENT_THREAD'.
    
    * acinclude.m4 (GUILE_THREAD_LOCAL_STORAGE): New macro.
    
    * configure.ac: Use it.
    
    * libguile/__scm.h (SCM_THREAD_LOCAL): New macro.
    
    * libguile/gen-scmconfig.c (main): Define `SCM_HAVE_THREAD_STORAGE_CLASS'.
    
    * libguile/gen-scmconfig.h.in (SCM_I_GSC_HAVE_THREAD_STORAGE_CLASS):
      New.
    
    * libguile/threads.c
      (scm_i_current_thread)[SCM_HAVE_THREAD_STORAGE_CLASS]: New.
      (SET_CURRENT_THREAD): New macro.
      (guilify_self_1, on_thread_exit, init_thread_key): Use it.
    
    * libguile/threads.h
      (scm_i_current_thread)[SCM_HAVE_THREAD_STORAGE_CLASS]: New
      declaration.
      (SCM_I_CURRENT_THREAD)[SCM_HAVE_THREAD_STORAGE_CLASS]: New macro.
      (init_thread_key_once, init_thread_key): Conditionalize on
      `!defined SCM_HAVE_THREAD_STORAGE_CLASS'.
      (scm_i_init_thread_for_guile): Update accordingly.

commit 46935a1fac58e50276f7e7e49e5fa6bab53c0848
Author: Ludovic Courtès <address@hidden>
Date:   Fri Oct 2 15:28:29 2009 +0200

    Arrange so that `SCM_I_CURRENT_THREAD' is not accessed outside of libguile.
    
    * libguile/__scm.h (scm_async_tick): New declaration.
      (SCM_ASYNC_TICK)[!BUILDING_LIBGUILE]: Use `scm_async_tick ()'.
    
    * libguile/async.c (scm_critical_section_start,
      scm_critical_section_end, scm_async_tick): New functions.
    
    * libguile/async.h (scm_i_critical_section_mutex): Made internal.
      (scm_critical_section_start, scm_critical_section_end): New
      declarations.
      (SCM_CRITICAL_SECTION_START,
      SCM_CRITICAL_SECTION_END)[!BUILDING_LIBGUILE]: Use the same-named
      function (lower-case).
    
    * libguile/stackchk.h (SCM_STACK_OVERFLOW_P): Conditionalize on
      `BUILDING_LIBGUILE'.
    
    * libguile/threads.h (SCM_I_CURRENT_THREAD, scm_i_dynwinds,
      scm_i_set_dynwinds, scm_i_last_debug_frame,
      scm_i_set_last_debug_frame): Conditionalize on `BUILDING_LIBGUILE'.

commit b8ec9daba60ceb14b443d3a44ab5043edcb474df
Author: Ludovic Courtès <address@hidden>
Date:   Fri Oct 2 15:02:52 2009 +0200

    Deprecate `scm_mask_ints'.
    
    * libguile/async.h (scm_mask_ints): Remove.
    
    * libguile/deprecated.c (scm_i_mask_ints): New.
    
    * libguile/deprecated.h (scm_mask_ints): New macro.
      (scm_i_mask_ints): New declaration.

-----------------------------------------------------------------------

Summary of changes:
 acinclude.m4                |   20 ++++++++++++++++++++
 configure.ac                |    2 ++
 libguile/__scm.h            |   31 ++++++++++++++++++++++++++-----
 libguile/async.c            |   23 +++++++++++++++++++++++
 libguile/async.h            |   38 +++++++++++++++++++++++---------------
 libguile/deprecated.c       |    8 ++++++++
 libguile/deprecated.h       |    6 ++++++
 libguile/gen-scmconfig.c    |    7 +++++++
 libguile/gen-scmconfig.h.in |    1 +
 libguile/stackchk.h         |    6 +++---
 libguile/threads.c          |   34 ++++++++++++++++++++++++++++++----
 libguile/threads.h          |   32 +++++++++++++++++++++++---------
 12 files changed, 172 insertions(+), 36 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index 1b836cc..ed537d0 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -335,6 +335,26 @@ AC_DEFUN([GUILE_GNU_LD_RELRO], [
   AC_SUBST([GNU_LD_FLAGS])
 ])
 
+dnl GUILE_THREAD_LOCAL_STORAGE
+dnl
+dnl Check for compiler thread-local storage (TLS) support.
+AC_DEFUN([GUILE_THREAD_LOCAL_STORAGE], [
+  AC_CACHE_CHECK([whether the `__thread' storage class is available],
+    [ac_cv_have_thread_storage_class],
+    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([__thread int tls_integer;],
+                         [tls_integer = 123;])],
+       [ac_cv_have_thread_storage_class="yes"],
+       [ac_cv_have_thread_storage_class="no"])])
+
+  if test "x$ac_cv_have_thread_storage_class" = "xyes"; then
+     SCM_I_GSC_HAVE_THREAD_STORAGE_CLASS=1
+  else
+     SCM_I_GSC_HAVE_THREAD_STORAGE_CLASS=0
+  fi
+
+  AC_SUBST([SCM_I_GSC_HAVE_THREAD_STORAGE_CLASS])
+])
+
 dnl GUILE_READLINE
 dnl
 dnl Check all the things needed by `guile-readline', the Readline
diff --git a/configure.ac b/configure.ac
index 8c791ca..d011311 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1380,6 +1380,8 @@ AC_DEFINE(PTHREAD_ATTR_GETSTACK_WORKS, [1], [Define when 
pthread_att_get_stack w
 CFLAGS="$old_CFLAGS"
 AC_MSG_RESULT($works)
 
+GUILE_THREAD_LOCAL_STORAGE
+
 fi # with_threads=pthreads
 
 
diff --git a/libguile/__scm.h b/libguile/__scm.h
index a1f3b34..55f9f49 100644
--- a/libguile/__scm.h
+++ b/libguile/__scm.h
@@ -492,11 +492,24 @@ typedef long SCM_STACKITEM;
 #define SCM_STACK_PTR(ptr) ((SCM_STACKITEM *) (void *) (ptr))
 
 
-#define SCM_ASYNC_TICK /*fixme* should change names */ \
-do { \
-  if (SCM_I_CURRENT_THREAD->pending_asyncs) \
-    scm_async_click (); \
-} while (0)
+SCM_API void scm_async_tick (void);
+
+#ifdef BUILDING_LIBGUILE
+
+/* FIXME: should change names */
+# define SCM_ASYNC_TICK                                        \
+    do                                                 \
+      {                                                        \
+       if (SCM_I_CURRENT_THREAD->pending_asyncs)       \
+         scm_async_click ();                           \
+      }                                                        \
+    while (0)
+
+#else /* !BUILDING_LIBGUILE */
+
+# define SCM_ASYNC_TICK  (scm_async_tick ())
+
+#endif /* !BUILDING_LIBGUILE */
 
 
 /* Anthony Green writes:
@@ -666,6 +679,14 @@ SCM_API SCM scm_apply_generic (SCM gf, SCM args);
 #define SCM_C_INLINE_KEYWORD
 #endif
 
+/* Handling thread-local storage (TLS).  */
+
+#ifdef SCM_HAVE_THREAD_STORAGE_CLASS
+# define SCM_THREAD_LOCAL __thread
+#else
+# define SCM_THREAD_LOCAL
+#endif
+
 #endif  /* SCM___SCM_H */
 
 /*
diff --git a/libguile/async.c b/libguile/async.c
index 948aefa..664264f 100644
--- a/libguile/async.c
+++ b/libguile/async.c
@@ -472,6 +472,29 @@ scm_dynwind_unblock_asyncs ()
   scm_dynwind_unwind_handler (increase_block, t, SCM_F_WIND_EXPLICITLY);
 }
 
+
+/* These are function variants of the same-named macros (uppercase) for use
+   outside of libguile.  This is so that `SCM_I_CURRENT_THREAD', which may
+   reside in TLS, is not accessed from outside of libguile.  It thus allows
+   libguile to be built with the "local-dynamic" TLS model.  */
+
+void
+scm_critical_section_start (void)
+{
+  SCM_CRITICAL_SECTION_START;
+}
+
+void
+scm_critical_section_end (void)
+{
+  SCM_CRITICAL_SECTION_END;
+}
+
+void
+scm_async_tick (void)
+{
+  SCM_ASYNC_TICK;
+}
 
 
 
diff --git a/libguile/async.h b/libguile/async.h
index ba6c77c..ceb2b96 100644
--- a/libguile/async.h
+++ b/libguile/async.h
@@ -29,10 +29,6 @@
 
 
 
-#define scm_mask_ints (SCM_I_CURRENT_THREAD->block_asyncs != 0)
-
-
-
 SCM_API void scm_async_click (void);
 SCM_API void scm_switch (void);
 SCM_API SCM scm_async (SCM thunk);
@@ -61,22 +57,34 @@ void scm_dynwind_unblock_asyncs (void);
 */
 
 /* Defined in threads.c. */
-extern scm_i_pthread_mutex_t scm_i_critical_section_mutex;
+SCM_INTERNAL scm_i_pthread_mutex_t scm_i_critical_section_mutex;
+
+SCM_API void scm_critical_section_start (void);
+SCM_API void scm_critical_section_end (void);
 
-#define SCM_CRITICAL_SECTION_START \
-  do { \
-    scm_i_pthread_mutex_lock (&scm_i_critical_section_mutex);\
-    SCM_I_CURRENT_THREAD->block_asyncs++; \
-    SCM_I_CURRENT_THREAD->critical_section_level++; \
+#ifdef BUILDING_LIBGUILE
+
+# define SCM_CRITICAL_SECTION_START                            \
+  do {                                                         \
+    scm_i_pthread_mutex_lock (&scm_i_critical_section_mutex);  \
+    SCM_I_CURRENT_THREAD->block_asyncs++;                      \
+    SCM_I_CURRENT_THREAD->critical_section_level++;            \
   } while (0)
-#define SCM_CRITICAL_SECTION_END \
-  do { \
-    SCM_I_CURRENT_THREAD->critical_section_level--; \
-    SCM_I_CURRENT_THREAD->block_asyncs--; \
+# define SCM_CRITICAL_SECTION_END                              \
+  do {                                                         \
+    SCM_I_CURRENT_THREAD->critical_section_level--;            \
+    SCM_I_CURRENT_THREAD->block_asyncs--;                      \
     scm_i_pthread_mutex_unlock (&scm_i_critical_section_mutex); \
-    scm_async_click ();        \
+    scm_async_click ();                                                \
   } while (0)
 
+#else /* !BUILDING_LIBGUILE */
+
+# define SCM_CRITICAL_SECTION_START  scm_critical_section_start ()
+# define SCM_CRITICAL_SECTION_END    scm_critical_section_end ()
+
+#endif /* !BUILDING_LIBGUILE */
+
 SCM_INTERNAL void scm_init_async (void);
 
 #if (SCM_ENABLE_DEPRECATED == 1)
diff --git a/libguile/deprecated.c b/libguile/deprecated.c
index a8aebee..df7ba4d 100644
--- a/libguile/deprecated.c
+++ b/libguile/deprecated.c
@@ -1467,6 +1467,14 @@ scm_i_defer_ints_etc ()
      "Use a mutex instead if appropriate.");
 }
 
+int
+scm_i_mask_ints (void)
+{
+  scm_c_issue_deprecation_warning ("`scm_mask_ints' is deprecated.");
+  return (SCM_I_CURRENT_THREAD->block_asyncs != 0);
+}
+
+
 SCM
 scm_guard (SCM guardian, SCM obj, int throw_p)
 {
diff --git a/libguile/deprecated.h b/libguile/deprecated.h
index 93738f1..ed1a105 100644
--- a/libguile/deprecated.h
+++ b/libguile/deprecated.h
@@ -576,6 +576,12 @@ SCM_DEPRECATED void scm_i_defer_ints_etc (void);
 #define SCM_REDEFER_INTS scm_i_defer_ints_etc ()
 #define SCM_REALLOW_INTS scm_i_defer_ints_etc ()
 
+/* In the old days (pre-1.8), this macro was sometimes used as an lvalue as
+   in "scm_mask_ints = 1" to block async execution.  It no longer works.  */
+#define scm_mask_ints (scm_i_mask_ints ())
+
+SCM_DEPRECATED int scm_i_mask_ints (void);
+
 /* Deprecated since they are unnecessary and had not been documented.
  */
 SCM_DEPRECATED SCM scm_guard (SCM guardian, SCM obj, int throw_p);
diff --git a/libguile/gen-scmconfig.c b/libguile/gen-scmconfig.c
index 0e897ca..bc0c2df 100644
--- a/libguile/gen-scmconfig.c
+++ b/libguile/gen-scmconfig.c
@@ -404,6 +404,13 @@ main (int argc, char *argv[])
   pf ("typedef long int scm_t_off;\n");
 #endif
 
+  pf ("/* Define to 1 if the compiler supports the "
+      "`__thread' storage class.  */\n");
+  if (SCM_I_GSC_HAVE_THREAD_STORAGE_CLASS)
+    pf ("#define SCM_HAVE_THREAD_STORAGE_CLASS\n");
+  else
+    pf ("/* #undef SCM_HAVE_THREAD_STORAGE_CLASS */\n");
+
 #if USE_DLL_IMPORT
   pf ("\n");
   pf ("/* Define some additional CPP macros on Win32 platforms. */\n");
diff --git a/libguile/gen-scmconfig.h.in b/libguile/gen-scmconfig.h.in
index 1be95af..770e081 100644
--- a/libguile/gen-scmconfig.h.in
+++ b/libguile/gen-scmconfig.h.in
@@ -30,6 +30,7 @@
 #define SCM_I_GSC_USE_NULL_THREADS @SCM_I_GSC_USE_NULL_THREADS@
 #define SCM_I_GSC_NEED_BRACES_ON_PTHREAD_ONCE_INIT 
@SCM_I_GSC_NEED_BRACES_ON_PTHREAD_ONCE_INIT@
 #define SCM_I_GSC_NEED_BRACES_ON_PTHREAD_MUTEX_INITIALIZER 
@SCM_I_GSC_NEED_BRACES_ON_PTHREAD_MUTEX_INITIALIZER@
+#define SCM_I_GSC_HAVE_THREAD_STORAGE_CLASS 
@SCM_I_GSC_HAVE_THREAD_STORAGE_CLASS@
 #define SCM_I_GSC_HAVE_STRUCT_DIRENT64 @SCM_I_GSC_HAVE_STRUCT_DIRENT64@
 
 /*
diff --git a/libguile/stackchk.h b/libguile/stackchk.h
index 6aa0fec..ed14906 100644
--- a/libguile/stackchk.h
+++ b/libguile/stackchk.h
@@ -3,7 +3,7 @@
 #ifndef SCM_STACKCHK_H
 #define SCM_STACKCHK_H
 
-/* Copyright (C) 1995,1996,1998,2000, 2003, 2006, 2008 Free Software 
Foundation, Inc.
+/* Copyright (C) 1995,1996,1998,2000, 2003, 2006, 2008, 2009 Free Software 
Foundation, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
@@ -34,7 +34,7 @@
  */
 #define SCM_STACK_CHECKING_P SCM_STACK_LIMIT
 
-#ifdef STACK_CHECKING
+#if defined BUILDING_LIBGUILE && defined STACK_CHECKING
 # if SCM_STACK_GROWS_UP
 #  define SCM_STACK_OVERFLOW_P(s)\
    (SCM_STACK_PTR (s) \
@@ -52,7 +52,7 @@
     }
 #else
 # define SCM_CHECK_STACK /**/
-#endif /* STACK_CHECKING */
+#endif
 
 SCM_API int scm_stack_checking_enabled_p;
 
diff --git a/libguile/threads.c b/libguile/threads.c
index 901695c..851cf90 100644
--- a/libguile/threads.c
+++ b/libguile/threads.c
@@ -290,8 +290,27 @@ unblock_from_queue (SCM queue)
 /* Getting into and out of guile mode.
  */
 
+#ifdef SCM_HAVE_THREAD_STORAGE_CLASS
+
+/* When thread-local storage (TLS) is available, a pointer to the
+   current-thread object is kept in TLS.  Note that storing the thread-object
+   itself in TLS (rather than a pointer to some malloc'd memory) is not
+   possible since thread objects may live longer than the actual thread they
+   represent.  */
+SCM_THREAD_LOCAL scm_i_thread *scm_i_current_thread = NULL;
+
+# define SET_CURRENT_THREAD(_t)  scm_i_current_thread = (_t)
+
+#else /* !SCM_HAVE_THREAD_STORAGE_CLASS */
+
+/* Key used to retrieve the current thread with `pthread_getspecific ()'.  */
 scm_i_pthread_key_t scm_i_thread_key;
 
+# define SET_CURRENT_THREAD(_t)                                \
+  scm_i_pthread_setspecific (scm_i_thread_key, (_t))
+
+#endif /* !SCM_HAVE_THREAD_STORAGE_CLASS */
+
 
 static scm_i_pthread_mutex_t thread_admin_mutex = 
SCM_I_PTHREAD_MUTEX_INITIALIZER;
 static scm_i_thread *all_threads = NULL;
@@ -357,7 +376,7 @@ guilify_self_1 (SCM_STACKITEM *base)
   t->exited = 0;
   t->guile_mode = 0;
 
-  scm_i_pthread_setspecific (scm_i_thread_key, t);
+  SET_CURRENT_THREAD (t);
 
   scm_i_pthread_mutex_lock (&thread_admin_mutex);
   t->next_thread = all_threads;
@@ -475,7 +494,7 @@ on_thread_exit (void *v)
       t->held_mutex = NULL;
     }
 
-  scm_i_pthread_setspecific (scm_i_thread_key, v);
+  SET_CURRENT_THREAD (v);
 
   /* Ensure the signal handling thread has been launched, because we might be
      shutting it down.  */
@@ -514,9 +533,11 @@ on_thread_exit (void *v)
 
   scm_i_pthread_mutex_unlock (&thread_admin_mutex);
 
-  scm_i_pthread_setspecific (scm_i_thread_key, NULL);
+  SET_CURRENT_THREAD (NULL);
 }
 
+#ifndef SCM_HAVE_THREAD_STORAGE_CLASS
+
 static scm_i_pthread_once_t init_thread_key_once = SCM_I_PTHREAD_ONCE_INIT;
 
 static void
@@ -525,6 +546,8 @@ init_thread_key (void)
   scm_i_pthread_key_create (&scm_i_thread_key, NULL);
 }
 
+#endif
+
 /* Perform any initializations necessary to bring the current thread
    into guile mode, initializing Guile itself, if necessary.
 
@@ -542,9 +565,12 @@ scm_i_init_thread_for_guile (SCM_STACKITEM *base, SCM 
parent)
 {
   scm_i_thread *t;
 
+#ifndef SCM_HAVE_THREAD_STORAGE_CLASS
   scm_i_pthread_once (&init_thread_key_once, init_thread_key);
+#endif
 
-  if ((t = SCM_I_CURRENT_THREAD) == NULL)
+  t = SCM_I_CURRENT_THREAD;
+  if (t == NULL)
     {
       /* This thread has not been guilified yet.
        */
diff --git a/libguile/threads.h b/libguile/threads.h
index 842f0d9..5afe45f 100644
--- a/libguile/threads.h
+++ b/libguile/threads.h
@@ -3,7 +3,7 @@
 #ifndef SCM_THREADS_H
 #define SCM_THREADS_H
 
-/* Copyright (C) 1996,1997,1998,2000,2001, 2002, 2003, 2004, 2006, 2007, 2008 
Free Software Foundation, Inc.
+/* Copyright (C) 1996,1997,1998,2000,2001, 2002, 2003, 2004, 2006, 2007, 2008, 
2009 Free Software Foundation, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
@@ -192,15 +192,29 @@ SCM_API SCM scm_thread_exited_p (SCM thread);
 
 SCM_API void scm_dynwind_critical_section (SCM mutex);
 
-#define SCM_I_CURRENT_THREAD \
-  ((scm_i_thread *) scm_i_pthread_getspecific (scm_i_thread_key))
-SCM_API scm_i_pthread_key_t scm_i_thread_key;
+#ifdef BUILDING_LIBGUILE
+
+# ifdef SCM_HAVE_THREAD_STORAGE_CLASS
+
+SCM_INTERNAL SCM_THREAD_LOCAL scm_i_thread *scm_i_current_thread;
+#  define SCM_I_CURRENT_THREAD (scm_i_current_thread)
+
+# else /* !SCM_HAVE_THREAD_STORAGE_CLASS */
+
+SCM_INTERNAL scm_i_pthread_key_t scm_i_thread_key;
+#  define SCM_I_CURRENT_THREAD                                         \
+    ((scm_i_thread *) scm_i_pthread_getspecific (scm_i_thread_key))
+
+# endif /* !SCM_HAVE_THREAD_STORAGE_CLASS */
+
+# define scm_i_dynwinds()         (SCM_I_CURRENT_THREAD->dynwinds)
+# define scm_i_set_dynwinds(w)    (SCM_I_CURRENT_THREAD->dynwinds = (w))
+# define scm_i_last_debug_frame() (SCM_I_CURRENT_THREAD->last_debug_frame)
+# define scm_i_set_last_debug_frame(f) \
+                                  (SCM_I_CURRENT_THREAD->last_debug_frame = 
(f))
+
+#endif /* BUILDING_LIBGUILE */
 
-#define scm_i_dynwinds()         (SCM_I_CURRENT_THREAD->dynwinds)
-#define scm_i_set_dynwinds(w)    (SCM_I_CURRENT_THREAD->dynwinds = (w))
-#define scm_i_last_debug_frame() (SCM_I_CURRENT_THREAD->last_debug_frame)
-#define scm_i_set_last_debug_frame(f) \
-                                 (SCM_I_CURRENT_THREAD->last_debug_frame = (f))
 
 SCM_INTERNAL scm_i_pthread_mutex_t scm_i_misc_mutex;
 


hooks/post-receive
-- 
GNU Guile




reply via email to

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