1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00
guile/libguile/bdw-gc.h
Andy Wingo 12c1d8616d threading / with_guile refactor to use more GC_stack_base
* libguile/init.h:
* libguile/init.c (scm_i_init_guile): Change arg to this internal
  function from SCM_STACKITEM* to void*.  Actually it's a
  struct GC_stack_base*.

* libguile/bdw-gc.h: Don't do pthread redirects, because we don't want
  to affect applications' pthread_* bindings.

* libguile/pthread-threads.h (scm_i_pthread_create)
  (scm_i_pthread_detach, scm_i_pthread_exit, scm_i_pthread_cancel)
  (scm_i_pthread_sigmask): Do pthread redirects here, in this internal
  header.

* libguile/threads.h: Remove declaration of internal
  scm_i_with_guile_and_parent.  Remove declaration of undefined
  scm_threads_init_first_thread.  Make declaration of internal
  scm_threads_prehistory actually internal, and take a void* (actually a
  struct GC_stack_base*).

* libguile/threads.c (GC_get_stack_base): Implement a shim if this
  function is unavailable, and fold in the implementations of
  get_thread_stack_base.
  (GC_call_with_stack_base): Actually implement.
  (guilify_self_1): Take a GC_stack_base* as an arg.
  (scm_i_init_thread_for_guile): Likewise, and set up libgc for
  registration of other threads.
  (scm_init_guile): Use GC_get_stack_base instead of our own guesswork.
  (with_guile_and_parent, scm_i_with_guile_and_parent): Rework to
  trampoline through a GC_call_with_stack_base.
  (scm_threads_prehistory): Pass the "base" arg on to guilify_self_1.
2011-03-25 13:01:51 +01:00

70 lines
2.2 KiB
C

#ifndef SCM_BDW_GC_H
#define SCM_BDW_GC_H
/* Copyright (C) 2006, 2008, 2009, 2011 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
* as published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
/* Correct header inclusion. */
#include "libguile/scmconfig.h"
#ifdef SCM_USE_PTHREAD_THREADS
/* When pthreads are used, let `libgc' know about it and redirect allocation
calls such as `GC_MALLOC ()' to (contention-free, faster) thread-local
allocation. */
# define GC_THREADS 1
# define GC_REDIRECT_TO_LOCAL 1
/* Don't #define pthread routines to their GC_pthread counterparts.
Instead we will be careful inside Guile to use the GC_pthread
routines. */
# define GC_NO_THREAD_REDIRECTS 1
#endif
#include <gc/gc.h>
#if (! ((defined GC_VERSION_MAJOR) && (GC_VERSION_MAJOR >= 7)))
/* This was needed with `libgc' 6.x. */
# include <gc/gc_local_alloc.h>
#endif
#if (defined GC_VERSION_MAJOR) && (GC_VERSION_MAJOR >= 7)
/* This type was provided by `libgc' 6.x. */
typedef void *GC_PTR;
#endif
/* Return true if PTR points to the heap. */
#define SCM_I_IS_POINTER_TO_THE_HEAP(ptr) \
(GC_base (ptr) != NULL)
/* Register a disappearing link for the object pointed to by OBJ such that
the pointer pointed to be LINK is cleared when OBJ is reclaimed. Do so
only if OBJ actually points to the heap. See
http://thread.gmane.org/gmane.comp.programming.garbage-collection.boehmgc/2563
for details. */
#define SCM_I_REGISTER_DISAPPEARING_LINK(link, obj) \
((SCM_I_IS_POINTER_TO_THE_HEAP (obj)) \
? GC_GENERAL_REGISTER_DISAPPEARING_LINK ((link), (obj)) \
: 0)
#endif /* SCM_BDW_GC_H */