1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00
Commit graph

187 commits

Author SHA1 Message Date
Andy Wingo
ab4bc85398 Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	GUILE-VERSION
	test-suite/tests/srfi-4.test
2011-07-25 18:26:37 +02:00
Ludovic Courtès
4f39f31ea5 Revert "Fix lock ordering in fat_mutex_lock' to match that of do_thread_exit'."
This reverts commit ccb80964cd, which
introduced a race condition, with a small window during which a mutex
could be held by a thread without being part of its `mutexes' list,
thereby violating the invariant tested at line 667.
2011-07-01 22:46:32 +02:00
Ludovic Courtès
97ec95b728 Type-check the OWNER argument of `lock-mutex'.
* libguile/threads.c (scm_lock_mutex_timed): Type-check OWNER.
2011-07-01 19:10:18 +02:00
Ludovic Courtès
b8441577f9 Fix `on_thread_exit' for canceled threads.
* libguile/threads.c (on_thread_exit): Clear `t->guile_mode' upon
  entry.  This fixes a bug whereby `t->base' would be incorrect for
  canceled threads, leading to a misdiagnosed VM stack overflow.
  See <http://lists.gnu.org/archive/html/bug-guile/2011-06/msg00068.html>
  for details.
  (scm_leave_guile_cleanup): Remove because it's unused.
2011-06-30 22:58:07 +02:00
Andy Wingo
8a562c697b Merge remote-tracking branch 'local-2.0/stable-2.0'
Conflicts:
	libguile/deprecated.c
	module/ice-9/psyntax-pp.scm
2011-06-30 13:47:46 +02:00
Ludovic Courtès
ccb80964cd Fix lock ordering in fat_mutex_lock' to match that of do_thread_exit'.
Original Helgrind report:

==14160== Thread #57: lock order "0x47F6B90 before 0x7C25A28" violated
==14160==    at 0x4C27730: pthread_mutex_lock (in /.../valgrind-3.6.0/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==14160==    by 0x4EFF87E: do_thread_exit (threads.c:664)
==14160==    by 0x4E87B89: c_body (continuations.c:512)
==14160==    by 0x4F16C21: vm_regular_engine (vm-i-system.c:960)
==14160==    by 0x4E90F92: scm_call_4 (eval.c:506)
==14160==    by 0x4E88372: scm_i_with_continuation_barrier (continuations.c:450)
==14160==    by 0x4E88424: scm_c_with_continuation_barrier (continuations.c:546)
==14160==    by 0x51CA3AF: GC_call_with_gc_active (pthread_support.c:1128)
==14160==    by 0x4EFF2E0: with_guile_and_parent (threads.c:206)
==14160==    by 0x51C46B4: GC_call_with_stack_base (misc.c:1505)
==14160==    by 0x4EFF447: scm_with_guile (threads.c:917)
==14160==    by 0x51C46B4: GC_call_with_stack_base (misc.c:1505)
==14160==   Required order was established by acquisition of lock at 0x47F6B90
==14160==    at 0x4C27730: pthread_mutex_lock (in /.../valgrind-3.6.0/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==14160==    by 0x4F00262: fat_mutex_lock (threads.c:1362)
==14160==    by 0x4F004DA: scm_lock_mutex_timed (threads.c:1462)
==14160==    by 0x4F16C09: vm_regular_engine (vm-i-system.c:898)
==14160==    by 0x4E90F4D: scm_call_3 (eval.c:499)
==14160==    by 0x4EFFA4C: really_launch (threads.c:975)
==14160==    by 0x4E87B89: c_body (continuations.c:512)
==14160==    by 0x4F16C21: vm_regular_engine (vm-i-system.c:960)
==14160==    by 0x4E90F92: scm_call_4 (eval.c:506)
==14160==    by 0x4E88372: scm_i_with_continuation_barrier (continuations.c:450)
==14160==    by 0x4E88424: scm_c_with_continuation_barrier (continuations.c:546)
==14160==    by 0x4EFF289: with_guile_and_parent (threads.c:874)
==14160==   followed by a later acquisition of lock at 0x7C25A28
==14160==    at 0x4C27730: pthread_mutex_lock (in /.../valgrind-3.6.0/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==14160==    by 0x4F00352: fat_mutex_lock (threads.c:1374)
==14160==    by 0x4F004DA: scm_lock_mutex_timed (threads.c:1462)
==14160==    by 0x4F16C09: vm_regular_engine (vm-i-system.c:898)
==14160==    by 0x4E90F4D: scm_call_3 (eval.c:499)
==14160==    by 0x4EFFA4C: really_launch (threads.c:975)
==14160==    by 0x4E87B89: c_body (continuations.c:512)
==14160==    by 0x4F16C21: vm_regular_engine (vm-i-system.c:960)
==14160==    by 0x4E90F92: scm_call_4 (eval.c:506)
==14160==    by 0x4E88372: scm_i_with_continuation_barrier (continuations.c:450)
==14160==    by 0x4E88424: scm_c_with_continuation_barrier (continuations.c:546)
==14160==    by 0x4EFF289: with_guile_and_parent (threads.c:874)

* libguile/threads.c (fat_mutex_lock): In the `m->level == 0' case,
  release M's lock before taking T's `admin_mutex'.
2011-06-28 15:25:22 +02:00
Andy Wingo
3b971a59b5 don't spawn the signal delivery thread in a thread-exit handler
* libguile/threads.c (do_thread_exit): Remove needless spawn of the
  signal delivery thread.
2011-06-23 11:31:10 +02:00
Andy Wingo
99cc1092a8 Merge remote-tracking branch 'local-2.0/stable-2.0' 2011-06-16 20:01:56 +02:00
Andy Wingo
32f94bf258 O_CLOEXEC usage
* libguile/objcodes.c (scm_load_objcode):
* libguile/scmsigs.c (start_signal_delivery_thread):
* libguile/threads.c (guilify_self_1): Use O_CLOEXEC.
2011-06-16 19:47:26 +02:00
Andy Wingo
0b77014f0c fix initial values of reallocated fluids
* libguile/threads.h:
* libguile/threads.c (scm_i_reset_fluid): New internal function, resets
  the binding of a fluid for all threads.  Needed for fluid GC.

* libguile/fluids.c (new_fluid): Call scm_i_reset_fluid here.
2011-06-16 19:39:58 +02:00
Mark H Weaver
9ec1573d2b Don't call scm_lock_mutex and scm_unlock_mutex via pointer of wrong type
* libguile/threads.c (lock_mutex_return_void, unlock_mutex_return_void):
  New static functions that simply call scm_lock_mutex and
  scm_unlock_mutex, respectively, but return void instead of SCM.

  (scm_dynwind_lock_mutex): Pass unlock_mutex_return_void to
  scm_dynwind_unwind_handler_with_scm, and lock_mutex_return_void to
  scm_dynwind_rewind_handler_with_scm.  Previously, we passed
  scm_unlock_mutex and scm_lock_mutex (which return SCM), but the
  scm_dynwind_* functions expect pointers to functions which return
  void.  When SCM is of type union, this changes the calling conventions
  of the functions on some platforms (e.g. GCC 4.5.2 and 4.5.3 on x86).
2011-05-22 15:45:28 -04:00
Mark H Weaver
2a3db25e28 Don't call scm_lock_mutex and scm_unlock_mutex via pointer of wrong type
* libguile/threads.c (lock_mutex_return_void, unlock_mutex_return_void):
  New static functions that simply call scm_lock_mutex and
  scm_unlock_mutex, respectively, but return void instead of SCM.

  (scm_dynwind_lock_mutex): Pass unlock_mutex_return_void to
  scm_dynwind_unwind_handler_with_scm, and lock_mutex_return_void to
  scm_dynwind_rewind_handler_with_scm.  Previously, we passed
  scm_unlock_mutex and scm_lock_mutex (which return SCM), but the
  scm_dynwind_* functions expect pointers to functions which return
  void.  When SCM is of type union, this changes the calling conventions
  of the functions on some platforms (e.g. GCC 4.5.2 and 4.5.3 on x86).
2011-05-22 15:23:27 -04:00
Andy Wingo
4765b28f70 use of EXIT_SUCCESS and EXIT_FAILURE
* libguile/threads.c (scm_init_guile):
* libguile/throw.c (scm_exit_status): Use EXIT_SUCCESS and EXIT_FAILURE
  instead of 0 and 1.
2011-05-15 15:34:16 +02:00
Andy Wingo
27c6ebcb16 rename scm_async_click() to scm_async_tick(); privatize SCM_ASYNC_TICK
* libguile/_scm.h (SCM_ASYNC_TICK, SCM_ASYNC_TICK_WITH_CODE): Make these
  definitions private.  Call the tick() function instead of click().

* libguile/__scm.h:
* libguile/async.h (scm_async_tick): Move declaration here.  Remove
  scm_async_click declaration.  Tick is the new (and old!) click, you
  see.
  (SCM_CRITICAL_SECTION_END): Call tick() instead of click().

* libguile/async.c (scm_async_tick): Remove old definition, and rename
  scm_async_click to scm_async_tick.
  (decrease_block): Adapt to click() -> tick() name change.

* libguile/deprecated.h (scm_async_click, SCM_ASYNC_TICK): Define some
  GONE macros.

* libguile/threads.c (fat_mutex_unlock): Tick() instead of click().
2011-05-15 15:34:16 +02:00
Andy Wingo
2002f1f847 refactor do_thread_exit cleanup handler invocation
* libguile/threads.c (do_thread_exit): Redo cleanup handler call so as
  not to shove a SCM into a pointer.
2011-05-13 15:33:51 +02:00
Ludovic Courtès
d20912e67d Move {total,current}-processor-count' outside of posix.c'.
* libguile/posix.c (scm_total_processor_count,
  scm_current_processor_count): Move to...
* libguile/threads.c: ... here.

* libguile/posix.h (scm_total_processor_count,
  scm_current_processor_count): Move declarations to...
* libguile/threads.h: ... here.

* test-suite/tests/posix.test ("nproc"): Move tests to...
* test-suite/tests/threads.test: ... here.
2011-04-25 22:41:58 +02:00
Ludovic Courtès
912308835d Make `scm_i_ensure_signal_delivery_thread' call in Guile mode.
* libguile/threads.c (on_thread_exit): Move
  `scm_i_ensure_signal_delivery_thread' call...
  (do_thread_exit): ... here.
2011-04-25 16:45:22 +02:00
Andy Wingo
8e76ce94a2 --disable-threads fix
* libguile/threads.c (do_thread_exit_trampoline, on_thread_exit):
  (scm_i_init_thread_for_guile): Only register and unregister threads
  with bdw-gc when we are building with threads support.  Thanks to
  Marijn for the report.
2011-04-13 12:50:36 +02:00
Kevin Fletcher
987b8160f5 fix gc_register_my_thread et al fallback impls
* libguile/threads.c (GC_register_my_thread, GC_get_stack_base): Fix
  fallback impls.
2011-03-31 22:17:50 +02:00
Michael Gran
653ccd78fa don't GC unregister null thread
GC_unregister_my_thread is only supposed to be called from
a thread other than the main thread, so, it should never be
called when the system is compiled with null threads.

* libguile/threads.c (on_thread_exit)[SCM_USE_NULL_THREADS]: don't
    call GC_unregister_my_thread
2011-03-30 09:32:42 +02:00
Michael Gran
4000d0641f check for GC_allow_register_threads
This is not present in earlier versions of BDW-GC

* configure.ac: check for GC_allow_register_threads
* libguile/threads.c (scm_i_init_thread_for_guile): Only call
  GC_allow_register_threads if it is present.
2011-03-30 09:21:09 +02:00
Andy Wingo
7f22442b2a avoid running GC when SCM_I_CURRENT_THREAD is unset
* libguile/threads.c (guilify_self_1): Prevent finalizers from running
  before SCM_I_CURRENT_THREAD is set.
  (do_thread_exit_trampoline): Leave the thread in the registered state.
  (on_thread_exit): Always unregister the thread here.
2011-03-25 15:35:20 +01:00
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
Andy Wingo
5f0d2951a0 bdw-gc 6.8 compatibility (hopefully)
* configure.ac (HAVE_GC_STACK_BASE): New check.

* libguile/threads.c (GC_UNIMPLEMENTED, GC_SUCCESS): Define if needed.
  (GC_register_my_thread, GC_unregister_my_thread)
  (GC_call_with_stack_base): Define shims if needed.
2011-03-24 20:34:31 +01:00
Andy Wingo
f60a7648d5 fix thread cleanup
* libguile/threads.h: Always declare a scm_i_thread_key, for cleanup
  purposes, in the BUILDING_LIBGUILE case.

* libguile/threads.c (scm_i_thread_key): Init with a cleanup handler, so
  any guile-specific info for a thread can be cleaned up reliably.
  (guilify_self_1): Always set the thread key.
  (do_thread_exit_trampoline, on_thread_exit): Enter guile-mode for the
  guile-mode cleanup handler, and trampoline through a
  gc_call_with_stack_base for reasons explained in the code.
  (init_thread_key, scm_i_init_thread_for_guile): Always init the key.
  (scm_i_with_guile_and_parent): No need for pthread_cancel cleanup
  handlers, as the pthread key destructor will take care of that for
  us.
  (really_launch): Remove needless pthread_exit call with incorrect
  comment.
2011-03-18 13:29:02 +01:00
Andy Wingo
cde24ce12b scm_with_guile calls GC_call_with_gc_active
* configure.ac: Check for GC_call_with_gc_active.

* libguile/threads.h (scm_i_thread): Remove "top", as it's not used.

* libguile/threads.c (with_gc_inactive, with_gc_active): Define shims to
  GC_do_blocking and GC_call_with_gc_active.
  (scm_i_init_thread_for_guile): Don't do thread base adjustment here,
  do it in scm_i_with_guile_and_parent.  The previous logic would never
  be run.
  (scm_i_with_guile_and_parent): If we enter Guile mode, leave it too.
  Take care of adjusting the thread stack base here too.  Also, call
  with_gc_active.
  (scm_without_guile): Refactor.
2011-01-22 19:55:31 +01:00
Andy Wingo
534bbcc168 more -Wundef on darwin fixes
* libguile/threads.c:
* libguile/posix.c: Change a couple #if HAVE_FOO to #ifdef HAVE_FOO to
  pacify -Wundef. Some vars are defined or not, whereas some are always
  defined to 0 or 1. The inconsistency is unfortunate.
2010-10-18 13:35:46 +02:00
Ludovic Courtès
f57fdf07d6 Fix memory leak in lock-mutex' (aka. scm_lock_mutex'.)
The memory leak is trivially reproducible with:

  (define m (make-mutex))
  (let loop () (lock-mutex m) (unlock-mutex m) (loop))

or similarly with:

  (define p (delay (+ 1 2)))
  (let loop () (force p) (loop))

since `force' acquires P's mutex.

It could also lead to premature release of a thread waiting in
`fat_mutex_lock' when a former owner's `do_thread_exit' is run.

* libguile/threads.c (fat_mutex_unlock): When `m->level' becomes 0,
  remove MUTEX from `t->mutexes'.
  (fat_mutex_lock): Update comment above the `t->mutexes' assignment.
  (do_thread_exit): Add an assertion making sure that each mutex in
  `t->mutexes' is owned by T.
2010-09-02 14:42:14 +02:00
Ludovic Courtès
d31ae2c363 Avoid calls to scm_current_thread' in fat_mutex_unlock'.
* libguile/threads.c (fat_mutex_unlock): Use `t->handle' instead of
  calling `scm_current_thread'.
2010-09-02 11:22:01 +02:00
Ludovic Courtès
bc4adf1739 Remove unneeded #include <assert.h>.
* libguile/backtrace.c, libguile/eval.c, libguile/gc.c,
  libguile/goops.c, libguile/memoize.c, libguile/threads.c,
  libguile/uniform.c, libguile/vm.c,
  test-suite/standalone/test-conversion.c,
  test-suite/standalone/test-list.c: Don't include <assert.h>.
2009-12-15 20:20:38 +01:00
Andy Wingo
f39448c5a3 remove a bunch of needless scm_permanent_object calls
* libguile/array-handle.c:
* libguile/bytevectors.c:
* libguile/deprecated.c:
* libguile/eval.c:
* libguile/feature.c:
* libguile/filesys.c:
* libguile/gc.c:
* libguile/gdbint.c:
* libguile/goops.c:
* libguile/instructions.c:
* libguile/load.c:
* libguile/modules.c:
* libguile/numbers.c:
* libguile/options.c:
* libguile/ports.c:
* libguile/scmsigs.c:
* libguile/srcprop.c:
* libguile/srfi-4.c:
* libguile/stacks.c:
* libguile/threads.c:
* libguile/vm.c: Remove calls to scm_permanent_object, as they are no
  longer needed with the BDW GC.
2009-12-05 11:32:50 +01:00
Andy Wingo
14aa25e410 remove debug frames
* libguile/debug.h (scm_t_debug_frame): Remove this type, as it was
  internal to the old evaluator.
  (SCM_EVALFRAME, SCM_APPLYFRAME, SCM_VOIDFRAME, SCM_MACROEXPF)
  (SCM_TAILREC, SCM_TRACED_FRAME, SCM_ARGS_READY, SCM_DOVERFLOW)
  (SCM_MAX_FRAME_SIZE, SCM_FRAMETYPE)
  (SCM_EVALFRAMEP, SCM_APPLYFRAMEP, SCM_VOIDFRAMEP, SCM_MACROEXPFP)
  (SCM_TAILRECP, SCM_TRACED_FRAME_P, SCM_ARGS_READY_P, SCM_OVERFLOWP)
  (SCM_SET_MACROEXP, SCM_SET_TAILREC, SCM_SET_TRACED_FRAME)
  (SCM_SET_ARGSREADY, SCM_SET_OVERFLOW)
  (SCM_CLEAR_MACROEXP, SCM_CLEAR_TRACED_FRAME, SCM_CLEAR_ARGSREADY):
  Remove macro accessors to scm_t_debug_frame.
  (SCM_DEBUGOBJP, SCM_DEBUGOBJ_FRAME, SCM_SET_DEBUGOBJ_FRAME):
  (scm_debug_object_p, scm_make_debugobj): Remove debugobj accessors.
  (scm_i_unmemoize_expr): Remove unused declaration.

* libguile/debug.c (scm_debug_options): No more max limit on frame
  sizes.
  (scm_start_stack): Just call out to scm_vm_call_with_new_stack.
  (scm_debug_object_p, scm_make_debugobj, scm_init_debug): No more
  debugobj smob type.

* libguile/deprecated.h:
* libguile/deprecated.c (scm_i_deprecated_last_debug_frame)
  (scm_last_debug_frame): Remove deprecated debug-frame bits.

* libguile/stacks.c (scm_make_stack): Rework this function and its
  dependents to only walk VM frames.
  (scm_stack_id): Call out to the holder of the VM frame in question,
  which should be a VM or a VM continuation, for the stack ID. Currently
  this bit is stubbed out.
  (scm_last_stack_frame): Removed. It seems this is mainly useful for a
  debugger, and we need to rewrite the debugger to work on the Scheme
  level.

* test-suite/tests/continuations.test ("continuations"): Remove test for
  last-stack-frame.

* libguile/continuations.h (struct scm_t_contregs):
* libguile/continuations.c (scm_make_continuation):
  (copy_stack_and_call, scm_i_with_continuation_barrier): No need to
  save and restore debug frames.

* libguile/threads.h (scm_i_thread): Don't track debug frames.
  (scm_i_last_debug_frame, scm_i_set_last_debug_frame): Remove macro
  accessors.

* libguile/threads.c (guilify_self_1): Don't track debug frames.

* libguile/throw.c: No need to track debug frames in a jmpbuf.

* libguile/vm-engine.c (vm_engine, VM_PUSH_DEBUG_FRAMES): Don't push
  debug frames.

* libguile/vm.h:
* libguile/vm.c (scm_vm_call_with_new_stack): New function. Currently
  stubbed out though.
2009-12-03 11:03:39 +01:00
Ludovic Courtès
56a3dcd431 Remove references to undefined macros.
The intent is to allow compilation with `-Wundef', which in turn should
make it easier to catch erroneous uses of nonexistent macros.

* libguile/__scm.h: Don't assume `BUILDING_LIBGUILE' is defined.

* libguile/conv-uinteger.i.c (SCM_TO_TYPE_PROTO): Remove unneeded CPP
  conditional on `TYPE_MIN == 0'.

* libguile/fports.c: Check for the definition of `HAVE_CHSIZE' and
  `HAVE_FTRUNCATE', not for their value.

* libguile/ports.c: Likewise.

* libguile/numbers.c (guile_ieee_init): Likewise with `HAVE_DINFINITY'
  and `HAVE_DQNAN'.

* test-suite/standalone/test-conversion.c (ieee_init): Likewise.

* libguile/strings.c: Likewise with `SCM_STRING_LENGTH_HISTOGRAM'.

* libguile/strings.h: Likewise.

* libguile/tags.h: Likewise with `HAVE_INTTYPES_H' and `HAVE_STDINT_H'.

* libguile/threads.c: Likewise with `HAVE_PTHREAD_GET_STACKADDR_NP'.

* libguile/vm-engine.c (VM_NAME): Likewise with `VM_CHECK_IP'.

* libguile/gen-scmconfig.c (main): Use "#ifdef HAVE_", not "#if HAVE_".

* libguile/socket.c (scm_setsockopt): Likewise.
2009-11-17 23:42:22 +01:00
Ludovic Courtès
7f991c7d32 Fix C99-style declarations after statements.
* libguile/eval.i.c (ceval): Move declarations before statements.

* libguile/read.c (scm_read_extended_symbol): Likewise.

* libguile/struct.c (scm_make_struct_layout): Likewise.

* libguile/threads.c (fat_mutex_unlock): Likewise.

* libguile/vm-i-system.c (br_if_nargs_ne, br_if_nargs_lt): Likewise.

* libguile/vm.c (make_vm): Likewise.
2009-11-17 23:13:58 +01:00
Ludovic Courtès
3d1af79fec Adjust to match changes in libgc's CVS (pre-7.2).
In libgc CVS the `GC_do_blocking ()' declaration is now public but it
uses a slightly different signature for its first argument.

* configure.ac: Check for `GC_fn_type'.

* libguile/threads.c (GC_fn_type)[HAVE_GC_DO_BLOCKING &&
  !HAVE_GC_FN_TYPE]: New typedef.
  (scm_without_guile): Explicitly cast `without_guile_trampoline' to
  `GC_fn_type'.  This is because the upstream definition currently
  looks like `typedef void * (extern *GC_fn_type)(void *);', which
  isn't compatible.
2009-10-09 14:42:07 +02:00
Ludovic Courtès
705edb959b 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.
2009-10-09 14:10:05 +02:00
Neil Jerram
87f30eda98 Fix spurious `throw from within critical section' errors
The crux of this problem was that the thread doing a throw, and so
checking scm_i_critical_section_level, was different from the thread
that was in a critical section.

* libguile/async.h (scm_i_critical_section_level): Removed, replaced
  by per-thread critical_section_level.
  (SCM_CRITICAL_SECTION_START, SCM_CRITICAL_SECTION_END): Use
  per-thread critical_section_level.

* libguile/continuations.c (scm_dynthrow): Check per-thread
  critical_section_level.

* libguile/threads.c (guilify_self_1): Init per-thread
  critical_section_level.
  (scm_i_critical_section_level): Removed.

* libguile/threads.h (scm_i_thread): New critical_section_level field.

* libguile/throw.c (scm_ithrow): Check per-thread critical_section_level.
2009-09-30 21:44:02 +01:00
Ludovic Courtès
a0faf7ddf9 Fix bug #27450 ("Fat mutexes not GC'd until their owner dies").
* libguile/threads.c (do_thread_exit): Deal with `t->mutexes' being a
  weak list.
  (fat_mutex_lock): Use weak-car pairs when building up `t->mutexes'.

* test-suite/tests/threads.test ("mutex-ownership")["mutex with owner
  not retained (bug #27450)"]: New test.
2009-09-15 23:05:24 +02:00
Ludovic Courtès
c058db8a5d Use GC-robust queues/lists in `threads.c'.
* libguile/threads.c (remqueue, dequeue, on_thread_exit): Initialize the
  "next" link of the item returned/removed.
2009-09-15 00:39:04 +02:00
Ludovic Courtès
706846f667 Remove explicit thread/condvar/mutex finalization.
* libguile/threads.c (fat_mutex_free): Remove explicit `scm_gc_free ()'
  call.
  (fat_cond_free, thread_free): Remove.
  (scm_threads_prehistory): Adjust accordingly.
2009-09-15 00:00:18 +02:00
Ludovic Courtès
1c44468d77 Rename "boehm-gc.h" to "bdw-gc.h"; add to the distribution.
* libguile/Makefile.am (modinclude_HEADERS): Add `bdw-gc.h'.

* libguile/bdw-gc.h: Rename from "boehm-gc.h"; users updated.  Update to
  LGPLv3+.
2009-09-14 00:42:25 +02:00
Ludovic Courtès
b8e18ac25d Remove unused IA64 macro.
* libguile/threads.c (SCM_MARK_BACKING_STORE): Remove.
2009-09-14 00:42:25 +02:00
Ludovic Courtès
45f15cac1f Remove scm_enter_guile ()' and scm_leave_guile ()'.
* libguile/threads.c (scm_t_guile_ticket): Remove type.
  (resume, scm_enter_guile, suspend, scm_leave_guile): Remove.
  (scm_i_init_thread_for_guile): Set `t->top' to NULL, which has the
  same effect as calling `scm_enter_guile ()'.
  (scm_leave_guile_cleanup, scm_i_with_guile_and_parent): Remove
  `scm_leave_guile ()' call.
2009-09-11 00:05:49 +02:00
Ludovic Courtès
4cf72f0ba6 Remove unnecessary uses of `scm_{leave,enter}_guile ()'.
* libguile/threads.c (scm_pthread_cond_wait,
  scm_pthread_cond_timedwait): Remove `scm_{leave,enter}_guile ()'
  calls.
2009-09-10 00:21:08 +02:00
Ludovic Courtès
7af531508c Merge branch 'master' into boehm-demers-weiser-gc
Conflicts:
	libguile/Makefile.am
	libguile/bytevectors.c
	libguile/gc-card.c
	libguile/gc-mark.c
	libguile/programs.c
	libguile/srcprop.c
	libguile/srfi-14.c
	libguile/symbols.c
	libguile/threads.c
	libguile/unif.c
	libguile/vm.c
2009-08-28 19:16:46 +02:00
Ken Raeburn
71a5964c11 Don't leave and reenter guile mode if mutex is available
On Aug 5, 2009, at 10:06, Ken Raeburn wrote:
> (1) In scm_pthread_mutex_lock, we leave and re-enter guile mode so
> that we don't block the thread while in guile mode.  But we could
> use pthread_mutex_trylock first, and avoid the costs scm_leave_guile
> seems to incur on the Mac.  If we can't acquire the lock, it should
> return immediately, and then we can do the expensive, blocking
> version.  A quick, hack version of this changed my run time for
> A(3,8) from 17.5s to 14.5s, saving about 17%; sigaltstack and
> sigprocmask are still in the picture, because they're called from
> scm_catch_with_pre_unwind_handler.  I'll work up a nicer patch
> later.

Ah, we already had scm_i_pthread_mutex_trylock lying around; that made
things easy.
A second timing test with A(3,9) and this version of the patch (based
on 1.9.1) shows the same improvement.

* libguile/threads.c (scm_pthread_mutex_lock): Try the mutex before
  leaving and reentering guile mode.
2009-08-26 23:36:19 +01:00
Neil Jerram
a4dbe1ac3d Avoid clash with system setjmp/longjmp on IA64
Problem was that if an application includes both libguile.h and the
system's setjmp.h, and is compiled on IA64, it gets compile errors
because of jmp_buf, setjmp and longjmp being multiply defined.

* libguile/__scm.h (__ia64__): Define scm_i_jmp_buf, SCM_I_SETJMP and
  SCM_I_LONGJMP instead of jmp_buf, setjmp and longjmp.

  (all other platforms): Map scm_i_jmp_buf, SCM_I_SETJMP and
  SCM_I_LONGJMP to jmp_buf, setjmp and longjmp.

* libguile/continuations.c (scm_make_continuation): Use `SCM_I_SETJMP'
  instead of `setjmp'.
  (copy_stack_and_call): Use `SCM_I_LONJMP' instead of `longjmp'.
  (scm_ia64_longjmp): Use type `scm_i_jmp_buf' instead of `jmp_buf'.

* libguile/continuations.h (scm_t_contregs): Use type `scm_i_jmp_buf'
  instead of `jmp_buf'.

* libguile/threads.c (suspend): Use `SCM_I_SETJMP' instead of
  `setjmp'.

* libguile/threads.h (scm_i_thread): Use type `scm_i_jmp_buf' instead
  of `jmp_buf'.

* libguile/throw.c (JBJMPBUF, make_jmpbuf, jmp_buf_and_retval): Use
  type `scm_i_jmp_buf' instead of `jmp_buf'.
  (scm_c_catch): Use `SCM_I_SETJMP' instead of `setjmp'.
  (scm_ithrow): Use `SCM_I_LONGJMP' instead of `longjmp'.
2009-08-21 23:29:08 +01:00
Ludovic Courtès
3c13664ebe Reinstate missing IA64 helper functions.
* libguile/threads.c (scm_ia64_register_backing_store_base,
  scm_ia64_ar_bsp): New, formerly in `gc.c', which was removed in the
  BDW-GC branch.
2009-08-19 00:06:14 +02:00
Ludovic Courtès
fbb857a472 Merge branch 'master' into boehm-demers-weiser-gc
Conflicts:
	lib/Makefile.am
	libguile/Makefile.am
	libguile/frames.c
	libguile/gc-card.c
	libguile/gc-freelist.c
	libguile/gc-mark.c
	libguile/gc-segment.c
	libguile/gc_os_dep.c
	libguile/load.c
	libguile/macros.c
	libguile/objcodes.c
	libguile/programs.c
	libguile/strings.c
	libguile/vm.c
	m4/gnulib-cache.m4
	m4/gnulib-comp.m4
	m4/inline.m4
2009-08-18 00:06:45 +02:00
Neil Jerram
53befeb700 Change Guile license to LGPLv3+
(Not quite finished, the following will be done tomorrow.
   module/srfi/*.scm
   module/rnrs/*.scm
   module/scripts/*.scm
   testsuite/*.scm
   guile-readline/*
)
2009-06-17 00:22:09 +01:00