* libguile/threads.c (fat_mutex_lock): allow-external-unlock mutexes
can't be recursive, but a recursive lock attempt can be unblocked by
an external thread, so these mutexes shouldn't throw an error on
recursive lock attempts.
* test-suite/tests/srfi-18.test: Add tests.
* libguile/threads.h (scm_i_thread):
* libguile/threads.c (guilify_self_1, on_thread_exit)
(scm_pthread_cond_wait, scm_pthread_cond_timedwait): The thread-local
held_mutex field is no longer needed, now that we cancel threads via
interrupts instead of pthread_cancel.
* libguile/scmsigs.c (signal_handler_lock): New variable.
(scm_sigaction_for_thread): Block asyncs and use a mutex instead of
using scm_dynwind_critical_section.
* libguile/debug.c (scm_debug_options): Remove critical section. There
is no memory corruption hazard and racing callers to debug options
won't produce sensible results anyway; or anyway they will be the same
as racing vector-set!.
* libguile/stime.c (scm_current_time): No need for a critical section
around time().
(tz_lock): New mutex.
(scm_localtime): Use tz_lock in a dynwind. Fixes bug in which
critical section was never left on error.
(scm_gmtime, scm_mktime, scm_strftime, scm_strptime): Use a normal
mutex instead of a critical section.
* module/ice-9/threads.scm (cancel-tag): New variable.
(cancel-thread): New Scheme function.
(call-with-new-thread): Install a prompt around the thread.
* libguile/threads.h (scm_i_thread): Remove cancelled member.
* libguile/threads.c (scm_cancel_thread): Call out to Scheme. Always
available, and works on the current thread too.
(scm_set_thread_cleanup_x, scm_thread_cleanup): Adapt.
(scm_init_ice_9_threads): Capture cancel-thread var.
* doc/ref/api-scheduling.texi (Threads): Update.
* NEWS: Update.
* 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/async.c:
* libguile/async.h:
* libguile/deprecated.c:
* libguile/deprecated.h (scm_async, scm_async_mark, scm_run_asyncs):
Deprecate these functions, which comprise the "users asyncs" facility.
* module/oop/goops.scm: Adapt to <async> deprecation.
* doc/ref/api-scheduling.texi:
* doc/ref/libguile-concepts.texi:
* doc/ref/libguile-foreign-objects.texi:
* doc/ref/posix.texi: Remove documentation on user asyncs, and replace
references to "system asyncs" to be just "asyncs".
* doc/ref/vm.texi (Inlined Atomic Instructions): New section.
* libguile/vm-engine.c (VM_VALIDATE_ATOMIC_BOX, make-atomic-box)
(atomic-box-ref, atomic-box-set!, atomic-box-swap!)
(atomic-box-compare-and-swap!): New instructions.
* libguile/vm.c: Include atomic and atomics-internal.h.
(vm_error_not_a_atomic_box): New function.
* module/ice-9/atomic.scm: Register primitives with the compiler.
* module/language/cps/compile-bytecode.scm (compile-function): Add
support for atomic ops.
* module/language/cps/effects-analysis.scm: Add comment about why no
effects analysis needed.
* module/language/cps/reify-primitives.scm (primitive-module): Add case
for (ice-9 atomic).
* module/language/tree-il/primitives.scm (*effect-free-primitives*):
(*effect+exception-free-primitives*): Add atomic-box?.
* module/system/vm/assembler.scm: Add new instructions.
* test-suite/tests/atomic.test: Test with compilation and
interpretation.
* libguile/tags.h (scm_tc7_smob):
* module/system/base/types.scm (%tc7-smob): Tweak this value, just to
prove that it can be done. Remove scary comment.
* libguile/ports.h (SCM_F_PORT_FINALIZING)
(SCM_PORT_FINALIZING_P, SCM_SET_PORT_FINALIZING): New private
definitions.
* libguile/ports.c (finalize_port): Set the port-finalizing flag.
(scm_i_write_bytes): If the port is finalizing but output returned
EWOULDBLOCK, warn and discard the output.
* libguile/r6rs-ports.c (custom_binary_port_random_access_p): Rename
from custom_binary_input_output_port_type, and use for all custom
binary port types.
* libguile/ports.c (scm_seek): Avoid flushing buffers for an ftell.
Also allows non-random-access ports to ftell() if they have a seek
implementation, as is the case for custom binary ports with a
get-position function but no set-position function.
* test-suite/tests/ports.test: Adapt expectations, reverting changes
made in April by me in b77fb752dd.
* libguile/simpos.c: Trim includes.
(scm_system_star): Move to posix.c.
* libguile/simpos.h (scm_system_star): Remove.
* libguile/posix.h (scm_system_star): Add.
* libguile/posix.c (scm_system_star): Move here and implement in terms
of open-process. This lets system* work on Windows. Inspired by a
patch by Eli Zaretskii.
(start_child): Exit with 127 if the command isn't found.
* libguile/strings.c (scm_from_port_stringn, scm_to_port_stringn):
Access the conversion_strategy directly to make sure these functions
can run while the port is flushing on close. Fixes web-http.test to
allow the closed flag to be atomically cleared on a port before
flushing.
* libguile/null-threads.h: Reimplement null-threads stubs for pthread
data types, initializers, and functions in terms of types and inline
functions instead of CPP macros. Fixes unused-value warnings, and
tightens things up in general.
(scm_i_pthread_cleanup_push, scm_i_pthread_cleanup_pop): Remove these,
as they were unused and incorrect -- they would never run the cleanup
handler even if 1 was passed to pop.