Fixes a regression in ‘--without-threads’ builds introduced in
b8031fc965.
* libguile/finalizers.c (scm_i_is_finalizer_thread) [!SCM_USE_PTHREAD_THREADS]:
New function.
Fixes <https://bugs.gnu.org/76343>.
Fixes a bug whereby “echo '(environ)' | guile” would wrongfully trigger
the multiple-thread warning.
* libguile/finalizers.c (finalizer_thread): New variable.
(finalization_thread_proc): Set it.
(scm_i_is_finalizer_thread): New function.
(run_finalization_thread): Clear FINALIZER_THREAD.
* libguile/finalizers.h (scm_i_is_finalizer_thread): New declaration.
* libguile/threads.c (scm_all_threads): Use it.
* NEWS: Update.
Reported-by: Simon Josefsson <simon@josefsson.org>
Avoids spurious "error in finalization thread: Success" messages when
the finalization pipe gets closed.
* libguile/finalizers.c (finalization_thread_proc): Return when 'data.n'
is zero.
Partly fixes <https://bugs.gnu.org/41948>.
Reported by Mathieu Othacehe <othacehe@gnu.org>.
Previously, after 'fork', the child process could end up sharing the
finalization thread with its parent.
* libguile/finalizers.c (finalization_pipe): Initialize.
(reset_finalization_pipe): Factored out.
(start_finalization_thread): Create the pipe immediately before
launching the thread. Ensure the pipe is cleaned up if thread creation
fails. Update the finalizer callback if thread creation succeeds.
(stop_finalization_thread): Clean up the pipe after stopping the thread.
(spawn_finalizer_thread): Remove finalizer callback logic.
(scm_set_automatic_finalization_enabled): Remove pipe management.
(scm_init_finalizer_thread): Remove pipe management.
Co-authored-by: Ludovic Courtès <ludo@gnu.org>
Fixes <https://bugs.gnu.org/37757>.
Reported by Jesse Gibbons <jgibbons2357@gmail.com>.
* libguile/finalizers.c (finalization_thread_proc): Do not enter the
"switch (data.byte)" condition when data.n <= 0.
As the FSF advises, 'There is no legal significance to using the
three-character sequence “(C)”, but it does no harm.' It does take up
space though! For that reason, we remove it here from our C files.
* libguile/bytevectors.h: Include uniform.h, for use in the macros.
* libguile/extensions.h: Include libpath.h, for the
SCM_EFFECTIVE_VERSION, which is almost always used with these
routines.
* libguile/frames.h:
* libguile/instructions.h:
* libguile/intrinsics.h:
* libguile/loader.h:
* libguile/programs.h:
* libguile/vm.h: Include <libguile/__scm.h> instead of <libguile.h>.
Cuts a circular include, but also precipitates a lot of maintenance in
the .c files.
* libguile/*.c: Update C files to add needed all needed includes that
before were getting automatically pulled in by the indirect inclusion
of libguile.h.
* libguile/finalizers.c (async_gc_finalizer):
(scm_i_register_async_gc_callback): Replace "weak gc callback"
mechanism with "async gc callback" mechanism. Very similar but the
new API is designed to be called a bounded number of times, to avoid
running afoul of libgc heuristics.
* libguile/weak-list.h: New internal header.
* libguile/Makefile.am (noinst_HEADERS): Add weak-list.h.
* libguile/weak-set.c (vacuum_all_weak_sets):
(scm_c_make_weak_set, scm_init_weak_set):
* libguile/weak-table.c (vacuum_all_weak_tables):
(scm_c_make_weak_table, scm_init_weak_table): Arrange to vacuum all
weak sets from a single async GC callback, and likewise for weak
tables.
Thanks to Ludovic Courtès for tracking this bug down!
* libguile/__scm.h (SCM_TICK): Always define as scm_async_tick().
* libguile/error.c (scm_syserror, scm_syserror_msg):
* libguile/fports.c (fport_read, fport_write):
* libguile/_scm.h (SCM_SYSCALL): Replace SCM_ASYNC_TICK with
scm_async_tick ().
(SCM_ASYNC_TICK, SCM_ASYNC_TICK_WITH_CODE)
(SCM_ASYNC_TICK_WITH_GUARD_CODE): Remove internal definitions. We
inline into vm-engine.c, the only place where it matters.
* libguile/async.h:
* libguile/async.c (scm_async_tick, scm_i_setup_sleep):
(scm_i_reset_sleep, scm_system_async_mark_for_thread):
* libguile/threads.h (struct scm_thread_wake_data):
* libguile/threads.h (scm_i_thread):
* libguile/threads.c (block_self, guilify_self_1, scm_std_select):
Rewrite to use sequentially-consistent atomic references.
* libguile/atomics-internal.h (scm_atomic_set_pointer):
(scm_atomic_ref_pointer): New definitions.
* libguile/finalizers.c (queue_finalizer_async): We can allocate, so
just use scm_system_async_mark_for_thread instead of the set-cdr!
shenanigans.
* libguile/scmsigs.c (take_signal):
* libguile/gc.c (queue_after_gc_hook): Adapt to new asyncs mechanism.
Can't allocate but we're just manipulating the current thread when no
other threads are running so we should be good.
* libguile/vm-engine.c (VM_HANDLE_INTERRUPTS): Inline the async_tick
business.
* libguile/finalizers.h:
* libguile/finalizers.c (run_finalizers_async_thunk)
(finalization_thread_proc): Call the new scm_run_finalizers helper.
(scm_i_finalizer_pre_fork): Only spawn the thread if automatic
finalization is enabled.
(scm_set_automatic_finalization_enabled, scm_run_finalizers): New
functions.
(scm_init_finalizers, scm_init_finalizer_thread): Only set a finalizer
notifier if automatic finalization is enabled.
* doc/ref/libguile-smobs.texi (Garbage Collecting Smobs): Add discussion
of concurrency.
* doc/ref/api-smobs.texi (Smobs): Document new functions.
Fixes <http://bugs.gnu.org/14469>.
Reported by Panicz Maciej Godek <godek.maciek@gmail.com>.
* libguile/finalizers.c (finalization_thread_is_running): New variable.
(start_finalization_thread): Use it to determine whether
FINALIZATION_THREAD is up and running.
(stop_finalization_thread): Likewise.
* libguile/finalizers.h:
* libguile/finalizers.c (scm_i_register_weak_gc_callback): New internal
helper, from weak-set.c.
Relative to the previous weak-set.c version, prefer the
finalizer-based implementation. Fix bug regarding confusion between
scm_before_gc_c_hook and scm_after_gc_hook. Fix bug regarding
referencing weak values outside of the alloc lock.
* libguile/weak-set.c (GC_move_disappearing_link): New stub.
GC_move_disappearing_link is only available in libgc 7.3.
(move_weak_entry): Use the new stub instead of ifdeffery.
(resize_set): Now that we run finalizers from a separate thread or
async, we can keep the lock while reallocating the set vector.
(do_vacuum_weak_set): For the same reason, always lock the set.
Remove implementation of scm_c_register_weak_gc_callback in preference
of the new copy in finalizers.c.
(scm_c_make_weak_set): Use the new scm_i_register_weak_gc_callback.
* libguile/finalizers.c: New excitement! We'll be running finalizers
asynchronously, from asyncs. This will make it safer to allocate
while holding a mutex.
(GC_set_finalizer_notifier): Add back-compat shim.
* libguile/init.c (scm_i_init_guile): Init the async finalizer mechanism
during boot.
* libguile/gc.c (scm_storage_prehistory): Tell libgc we'll be finalizing
on demand.
(scm_gc): Explicitly run finalizers here.
* libguile/threads.c (guilify_self_2): Run finalizers here if
queue_finalizer_async happened to run during guilify_self_1.
* configure.ac: Add check for GC_set_finalizer_notifier.
* libguile/finalizers.c: New excitement! We'll be running finalizers in
threads, if that's available. If it's not available, during early
boot, we can run finalizers in asyncs. This will make it safer to
allocate while holding a mutex.
* libguile/posix.c (scm_fork): Shut down the finalizer thread before
forking.
* libguile/init.c (scm_i_init_guile): Init the async finalizer mechanism
during boot and, if available, initialialize the finalizer thread at
the very end.
* libguile/gc.c (scm_storage_prehistory): Tell libgc we'll be finalizing
on demand.
(scm_gc): Explicitly run finalizers here. If you're calling this
function, you probably want synchronous GC.