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

8493 commits

Author SHA1 Message Date
Andy Wingo
f1f68fffb1 Recursively locking a SRFI-18 mutex blocks
* 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.
2016-11-05 10:30:54 +01:00
Andy Wingo
f1b7eaaa1a Remove fat mutex abandoned mutex error
* libguile/threads.c (fat_mutex_lock): Remove abandoned mutex error, as
  SRFI-18 is responsible for this.
* test-suite/tests/threads.test: Update test.
2016-11-05 10:30:49 +01:00
Andy Wingo
a3d0a7da4d Remove thread held pthread_mutex field
* 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.
2016-11-05 00:22:15 +01:00
Andy Wingo
857aa581a2 Remove thread-local weak mutex set
* libguile/threads.h (scm_i_thread):
* libguile/threads.c (guilify_self_1, do_thread_exit, fat_mutex_lock):
  Remove thread-local weak mutex set.
2016-11-05 00:20:39 +01:00
Andy Wingo
ecfa0b50ce Remove lock-mutex owner facility
* libguile/threads.c (scm_lock_mutex_timed): Deprecate "owner"
  argument.
  (fat_mutex_lock): Remove owner argument.
  (fat_mutex_unlock): Don't pass owner to scm_lock_mutex_timed.
* test-suite/tests/threads.test: Remove tests of mutex-owner.
2016-11-04 23:32:26 +01:00
Andy Wingo
0f5a59b215 try-mutex in terms of mutex-lock
* libguile/threads.c (scm_try_mutex): Just call scm_lock_mutex_timed
  with a zero timeout.
* module/ice-9/threads.scm (try-mutex): Likewise.
2016-11-02 21:29:30 +01:00
Andy Wingo
fcc6a7ba20 Deprecate critical sections
* NEWS: Deprecate critical sections.
* doc/ref/api-scheduling.texi (Critical Sections): Remove.
* libguile/async.c:
* libguile/async.h:
* libguile/deprecated.c:
* libguile/deprecated.h:
* libguile/threads.c:
* libguile/threads.h: Deprecate critical section API.
2016-11-01 23:48:42 +01:00
Andy Wingo
4b78b001d8 Threads no longer track critical section level
* libguile/threads.h (scm_i_thread):
* libguile/threads.c (guilify_self_1): Remove critical_section_level
  member of scm_i_thread.
* libguile/async.c (scm_critical_section_end)
  (scm_critical_section_start): Remove bookkeeping.
2016-11-01 23:33:47 +01:00
Andy Wingo
8fc9450619 Remove call/cc assertion about critical sections
* libguile/continuations.c (scm_dynthrow): Remove assertion about
  critical section level; it's just a mutex anyway.
2016-11-01 23:32:41 +01:00
Andy Wingo
65268ff37a Remove last critical section use
* 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.
2016-11-01 23:32:41 +01:00
Andy Wingo
2e2396d28c Mutex in dynamic linker
* libguile/dynl.c (scm_dynamic_link, scm_dynamic_unlink)
  (scm_dynamic_pointer): Use a mutex to provide thread-safety.
2016-11-01 23:13:17 +01:00
Andy Wingo
399379bf25 Remove critical section in scm_debug_options
* 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!.
2016-11-01 23:07:56 +01:00
Andy Wingo
42882bbf42 Mutex instead of critical section in gc.c
* libguile/gc.c (scm_gc_protect_object, scm_gc_unprotect_object): Use a
  mutex instead of a critical section.  Remove dead code.
2016-11-01 22:57:54 +01:00
Andy Wingo
e7e7a719ba Mutex instead of critical section in GOOPS
* libguile/goops.c (scm_sys_modify_instance)
  (scm_sys_modify_class): Use a mutex instead of a critical section.
2016-11-01 22:52:12 +01:00
Andy Wingo
b410667e64 Simplify critical section implementation
* libguile/async.h (SCM_CRITICAL_SECTION_START)
  (SCM_CRITICAL_SECTION_END): Define in just one way.
* libguile/async.c (critical_section_mutex): New static variable.
  (scm_critical_section_start, scm_critical_section_end): Inline
  internal body of critical section gates.
  (scm_init_async): Init critical_section_mutex.
* libguile/threads.c (scm_threads_prehistory): Don't declare critical
  section mutex here.
2016-11-01 22:48:19 +01:00
Andy Wingo
c88d0cc402 Mutex instead of critical sectoin in symbol->keyword
* libguile/keywords.c (scm_symbol_to_keyword): Use a mutex in a dynwind
  instead of a critical section.
2016-11-01 22:40:38 +01:00
Andy Wingo
cfab7e3bf3 Mutexes instead of critical sections in stime.c
* 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.
2016-11-01 22:33:30 +01:00
Andy Wingo
c77ccc58fb Remove unused internal definitions
* libguile/async.h (scm_i_pthread_mutex_lock_block_asyncs)
  (scm_i_pthread_mutex_unlock_unblock_asyncs): Remove unused internal
  definitions.
2016-11-01 22:10:12 +01:00
Andy Wingo
445837754e regexec comment fix
* libguile/regex-posix.c (SCM_DEFINE): Remove comment about
  threadsafety, given that regexec does appear to be threadsafe.
2016-11-01 21:55:16 +01:00
Andy Wingo
465466ce4d sigaction critical section refactor.
* libguile/scmsigs.c (scm_sigaction_for_thread): Use critical section
  dynwinds instead of SCM_CRITICAL_SECTION_START.
2016-11-01 21:40:34 +01:00
Andy Wingo
0a663877ac threads: Use a mutex instead of a critical section.
* libguile/threads.c: Replace uses of critical sections with a dedicated
  mutex.
2016-11-01 21:26:42 +01:00
Andy Wingo
eeeee3297b Remove thread cleanup facility
* NEWS: Add entry.
* doc/ref/api-scheduling.texi (Threads): Remove thread-cleanup docs.
* libguile/threads.c (guilify_self_1, do_thread_exit):
  (scm_set_thread_cleanup_x, scm_thread_cleanup): Remove these.
* libguile/threads.h (scm_i_thread): Remove cleanup_handler.
* module/ice-9/threads.scm:
* module/ice-9/deprecated.scm (thread-cleanup, set-thread-cleanup!):
  Remove.
* test-suite/tests/threads.test: Adapt to test cancel-thread return
  values and not test thread-cleanup procs.
2016-10-31 22:37:46 +01:00
Andy Wingo
a04739b31a cancel-thread via asyncs, not pthread_cancel
* 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.
2016-10-27 21:22:28 +02:00
Andy Wingo
c957ec7ab0 Use atomics for async interrupts
* 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.
2016-10-26 22:50:26 +02:00
Andy Wingo
f3bfe29235 Move call-with-new-thread to Scheme
* libguile/threads.c (scm_call_with_new_thread): Trampoline to Scheme.
  (launch_data, really_launch, scm_sys_call_with_new_thread): Simplify.
  (scm_init_ice_9_threads): Capture call-with-new-thread variable.
* module/ice-9/threads.scm (call-with-new-thread): Add implementation in
  Scheme.  Should allow for easier cancel-thread via prompt abort.
2016-10-26 22:50:26 +02:00
Andy Wingo
d74e0fed0d Move thread bindings to (ice-9 threads)
* libguile/init.c (scm_i_init_guile): Don't call scm_init_thread_procs.
* libguile/threads.c (scm_init_ice_9_threads): Rename from
  scm_init_thread_procs, make static.
  (scm_init_threads): Register scm_init_thread_procs extension.
* libguile/threads.h (scm_init_thread_procs): Remove decl.
* module/ice-9/boot-9.scm: Load (ice-9 threads), so that related side
  effects occur early.
* module/ice-9/deprecated.scm (define-deprecated): Fix to allow
  deprecated bindings to appear in operator position.  Export deprecated
  bindings.
  (define-deprecated/threads, define-deprecated/threads*): Trampoline
  thread bindings to (ice-9 threads).
* module/ice-9/futures.scm: Use ice-9 threads.
* module/ice-9/threads.scm: Load scm_init_ice_9_threads extension.
  Reorder definitions and imports so that the module circularity
  with (ice-9 futures) continues to work.
* module/language/cps/intmap.scm:
* module/language/cps/intset.scm:
* module/language/tree-il/primitives.scm: Use (ice-9 threads).
* module/language/cps/reify-primitives.scm: Reify current-thread
  in (ice-9 threads) module.
* module/srfi/srfi-18.scm: Use ice-9 threads with a module prefix, and
  adapt all users.  Use proper keywords in module definition form.
* test-suite/tests/filesys.test (test-suite):
* test-suite/tests/fluids.test (test-suite):
* test-suite/tests/srfi-18.test: Use ice-9 threads.
* NEWS: Add entry.
* doc/ref/api-scheduling.texi (Threads): Update.
* doc/ref/posix.texi (Processes): Move current-processor-count and
  total-processor-count docs to Threads.
2016-10-23 22:29:44 +02:00
Andy Wingo
59f09d185b Deprecate user asyncs
* 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".
2016-10-17 21:58:08 +02:00
Andy Wingo
56d8d9a257 Deprecate arbiters
* libguile/arbiters.c:
* libguile/arbiters.h:
* test-suite/tests/arbiters.test: Delete files.
* libguile/deprecated.c:
* libguile/deprecated.h: Move arbiters code here.
* doc/ref/api-scheduling.texi: Remove section on arbiters.
* libguile.h:
* libguile/Makefile.am:
* libguile/init.c:
* module/oop/goops.scm:
* test-suite/Makefile.am: Remove mention of arbiters.
* NEWS: Update.
2016-10-17 21:29:05 +02:00
Andy Wingo
f9620e01c3 Fix compile warning in posix.c
* libguile/posix.c (scm_system_star): Fix SIG_IGN usage to not emit a
  warning.  Still broken on Windows64 and similar systems though!
2016-09-14 11:50:35 +02:00
Andy Wingo
32f309d5ce Compiler support for atomics
* 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.
2016-09-06 12:18:35 +02:00
Andy Wingo
3425290a7b Add atomic boxes
* doc/ref/api-scheduling.texi (Atomics): New manual section.
* libguile.h: Include atomic.h.
* libguile/Makefile.am (libguile_@GUILE_EFFECTIVE_VERSION@_la_SOURCES):
  (DOT_X_FILES, DOT_DOC_FILES, modinclude_HEADERS): Add atomic.
* libguile/atomic.c:
* libguile/atomic.h: New files.
* libguile/atomics-internal.h (scm_atomic_set_scm, scm_atomic_ref_scm)
  (scm_atomic_swap_scm, scm_atomic_compare_and_swap_scm): New
  facilities.
* libguile/goops.c (class_atomic_box, scm_sys_goops_early_init): Add
  support for <atomic-box>.  Remove duplicate <keyword> fetch.
* libguile/init.c (scm_i_init_guile): Call scm_register_atomic_box.
* libguile/print.c (iprin1): Add atomic box case.
* libguile/tags.h (scm_tc7_atomic_box): New tag.
* libguile/validate.h (SCM_VALIDATE_ATOMIC_BOX): New macro.
* module/Makefile.am (SOURCES): Add ice-9/atomic.scm.
* module/ice-9/atomic.scm: New file.
* module/oop/goops.scm (<atomic-box>): New var.
2016-09-06 11:16:53 +02:00
Andy Wingo
7cdaf0e27b Reorder tc7 type codes
* libguile/tags.h: Reorder type codes so that they are in numeric order
  in the header file; no type code value is changed.
2016-09-06 09:29:51 +02:00
Andy Wingo
1bed032249 Tweak value of tc7-smob.
* 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.
2016-09-06 09:21:49 +02:00
Andy Wingo
10423dbdaa Convert tc7 values to hex in tags.h and elsewhere
* libguile/tags.h:
* module/system/base/types.scm:
* module/system/vm/assembler.scm: Convert tc7 values to hex.  No change
  otherwise.
2016-09-06 09:19:52 +02:00
Andy Wingo
2dbb0e212d GOOPS caches created vtables
* libguile/goops.c (scm_i_define_class_for_vtable): Cache created
  vtables.  Fixes #24286.
* test-suite/tests/goops.test ("classes for built-in types"): Add
  tests.
2016-09-02 09:43:42 +02:00
Andy Wingo
49d77b1243 Add unboxed logxor on u64 values
* libguile/vm-engine.c (ulogxor): New instruction.
* module/language/cps/effects-analysis.scm (ulogxor):
* module/language/cps/slot-allocation.scm (compute-var-representations):
* module/language/cps/types.scm (ulogxor):
* module/system/vm/assembler.scm (emit-ulogxor): Add support for new
  instruction.
* doc/ref/vm.texi (Unboxed Integer Arithmetic): Document ulogxor.
2016-09-01 10:53:59 +02:00
Andy Wingo
b733ca461c GC of non-blocking port does not block
* 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.
2016-08-31 19:31:12 +02:00
Andy Wingo
b8a53b98b3 Only ptob->close() after read/write finish
* libguile/Makefile.am (noinst_HEADERS): Add atomics-internal.h.
* libguile/atomics-internal.h: New file.
* libguile/ports-internal.h (refcount): New member.
* libguile/ports.c (release_port, scm_dynwind_acquire_port): New
  facility for acquiring a port within a dynwind.
  (scm_port_poll, scm_i_read_bytes, scm_setvbuf, scm_end_input)
  (scm_i_write_bytes, scm_char_ready_p, scm_seek)
  (scm_truncate_file, trampoline_to_c_read)
  (trampoline_to_c_write): Acquire port.
  (scm_c_make_port_with_encoding): Init refcount to 1.
  (scm_close_port): Release port.
* doc/ref/api-io.texi (I/O Extensions): Add documentation
2016-08-31 19:10:35 +02:00
Andy Wingo
f46cb25a17 Set rw_random correctly for all custom binary port types
* 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.
2016-08-31 15:42:51 +02:00
Andy Wingo
eeb23e776a Avoid flushing buffers for ftell
* 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.
2016-08-31 15:39:01 +02:00
Andy Wingo
ad4fe88ffb Move system* to posix.c, impl on open-process
* 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.
2016-08-31 10:42:21 +02:00
Andy Wingo
2fa2e50a0f Add file descriptor finalizers
* doc/ref/posix.texi (Ports and File Descriptors): Document new
  interfaces.
* libguile/filesys.c (scm_close, scm_close_fdes)
* libguile/fports.c (fport_close):
* libguile/ioext.c (scm_primitive_move_to_fdes): Call
  scm_run_fdes_finalizers.
* module/ice-9/fdes-finalizers.scm:
* test-suite/tests/fdes-finalizers.test:
* libguile/fdes-finalizers.h:
* libguile/fdes-finalizers.c: New files.
* module/Makefile.am:
* test-suite/Makefile.am:
* libguile/Makefile.am:
* libguile.h:
* libguile/init.c: Wire up new files.
2016-08-30 23:35:10 +02:00
Andy Wingo
ebb8cb7206 Remove SCM_I_MAX_PORT_TYPE_COUNT
* libguile/ports.h (SCM_I_MAX_PORT_TYPE_COUNT): Remove unused CPP
  definition.
2016-08-28 14:46:32 +02:00
Andy Wingo
af360e5ce5 Tweak to conversion strategy access
* 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.
2016-08-25 16:16:39 +02:00
David Kastrup
469970d4b3 Let assv/assoc shortcircuit to assq where feasible
* libguile/alist.c (scm_sloppy_assv, scm_sloppy_assoc):
  (scm_assv, scm_assoc): Shortcircuit to scm_assq where feasible.
2016-08-07 22:52:20 +02:00
Andy Wingo
1a1c3bbe59 Implement R6RS custom binary input/output ports
* NEWS: Add new feature.
* doc/ref/r6rs.texi (rnrs io ports):
* doc/ref/api-io.texi (Custom Ports): Document new procedure.
* libguile/r6rs-ports.h:
* libguile/r6rs-ports.c (make_custom_binary_input_output_port)
  (scm_make_custom_binary_input_output_port)
  (custom_binary_input_output_port_random_access_p)
  (initialize_custom_binary_input_output_ports)
  (scm_init_r6rs_ports): Implement custom binary input/output ports.
* module/rnrs/io/ports.scm (rnrs):
* module/ice-9/binary-ports.scm (ice-9): Export
  make-custom-binary-input/output-port.
2016-08-04 22:29:51 +02:00
Eli Zaretskii
d2684fe898 Avoid compilation warnings about alloca in read.c
* libguile/read.c: Include alloca.h.
2016-07-25 11:51:40 +02:00
Andy Wingo
401214313b Fix --without-threads against threaded BDW-GC
* libguile/gc.c (scm_storage_prehistory): Prevent BDW-GC from spawning
  marker threads if Guile was built without threading support.
2016-07-25 11:51:30 +02:00
Andy Wingo
ca2d00ad65 Reimplement null-threads as inline functions
* 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.
2016-07-25 11:50:17 +02:00
Andy Wingo
315acd5ee0 Use non-deprecated HAVE_STRUCT_TM_TM_ZONE
* libguile/stime.c: Change uses of the deprecated HAVE_TM_ZONE to the
  new HAVE_STRUCT_TM_TM_ZONE.
2016-07-25 11:50:05 +02:00