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

8421 commits

Author SHA1 Message Date
Daniel Llorens
31e9f8b974 Speed up for multi-arg cases of scm_ramap functions
This patch results in a 20%-40% speedup in the > 1 argument cases of
the following microbenchmarks:

(define A (make-shared-array #0(1) (const '()) #e1e7))
; 1, 2, 3 arguments.
(define a 0) ,time (array-for-each (lambda (b) (set! a (+ a b))) A)
(define a 0) ,time (array-for-each (lambda (b c) (set! a (+ a b c))) A A)
(define a 0) ,time (array-for-each (lambda (b c d) (set! a (+ a b c d))) A A A)

(define A (make-shared-array (make-array 1) (const '()) #e1e7))
(define B (make-shared-array #0(1) (const '()) #e1e7))
; 1, 2, 3 arguments.
,time (array-map! A + B)
,time (array-map! A + B B)
,time (array-map! A + B B B)

* libguile/array-map.c (scm_ramap): Note on cproc arguments.

  (rafill): Assume that dst's lbnd is 0.

  (racp): Assume that src's lbnd is 0.

  (ramap): Assume that ra0's lbnd is 0. When there're more than two
  arguments, compute the array handles before the loop. Allocate the arg
  list once and reuse it in the loop.

  (rafe): Do as in ramap(), when there's more than one argument.

  (AREF, ASET): Remove.
2016-11-23 11:49:35 +01:00
Daniel Llorens
fa40c288ca Support typed arrays in some sort functions
* libguile/sort.c (sort!, sort, restricted-vector-sort!, sorted?):
  Support arrays of rank 1, whatever the type.

* libguile/quicksort.i.c: Fix accessors to handle typed arrays.

* test-suite/tests/sort.test: Test also with typed arrays.
2016-11-23 11:49:35 +01:00
Daniel Llorens
09850ffc27 Remove deprecated array functions
* libguile/array-map.c (scm_array_fill_int, scm_array_fill_int,
    scm_ra_eqp, scm_ra_lessp scm_ra_leqp, scm_ra_grp, scm_ra_greqp,
    scm_ra_sum, scm_ra_difference, scm_ra_product, scm_ra_divide,
    scm_array_identity): Remove deprecated functions.

* libguile/array-map.h: Remove declaration of deprecated functions.

* libguile/generalized-vectors.h, libguile/generalized-vectors.c
  (scm_is_generalized_vector, scm_c_generalized_vector_length,
  scm_c_generalized_vector_ref, scm_c_generalized_vector_set_x): These
  functions were deprecated in 2.0.9. Remove.

* doc/ref/api-compound.texi: Remove uniform-array-read!,
  uniform-array-write from the manual. These procedures where removed in
  fc7bd367ab (2011-05-12).
2016-11-23 11:49:35 +01:00
Daniel Llorens
85ac9cce0a Reuse SCM_BYTEVECTOR_TYPED_LENGTH in scm_array_get_handle
* libguile/bytevectors.h (SCM_BYTEVECTOR_TYPE_SIZE,
  SCM_BYTEVECTOR_TYPED_LENGTH): Moved from libguile/bytevectors.c.

* libguile/array-handle.c (scm_array_get_handle): Reuse
  SCM_BYTEVECTOR_TYPED_LENGTH.
2016-11-23 11:49:35 +01:00
Daniel Llorens
4e766795b2 Avoid unneeded internal use of array handles
* libguile/arrays.c (scm_shared_array_root): Adopt uniform check order.

  (scm_shared_array_offset, scm_shared_array_increments): Use the array
  fields directly just as scm_shared_array_root does.

  (scm_c_array_rank): Moved from libguile/generalized-arrays.c. Don't
  use array handles, but follow the same type check sequence as the
  other array functions (shared-array-root, etc).

  (scm_array_rank): Moved from libguile/generalized-arrays.h.

* libguile/arrays.h: Move prototypes here.

* test-suite/tests/arrays.test: Tests for shared-array-offset,
  shared-array-increments.
2016-11-23 11:49:35 +01:00
Andy Wingo
dc2a560264 Deprecate dynamic roots
* libguile/root.h:
* libguile/root.c: Remove these files.
* libguile/deprecated.h:
* libguile/deprecated.c (scm_internal_cwdr, scm_call_with_dynamic_root)
  (scm_dynamic_root, scm_apply_with_dynamic_root): Deprecate.

Remove all root.h usage, which was vestigial.

* module/ice-9/serialize.scm: Use (current-thread) instead
  of (dynamic-root).
2016-11-21 23:09:21 +01:00
Andy Wingo
08584310ee Inline interrupts
* libguile/async.c:
* libguile/async.h (scm_i_async_push, scm_i_async_pop): Make internally
  available.
* libguile/vm-engine.c (vm_engine): Invoke interrupts inline.  Add
  return-from-interrupt instruction.
* libguile/vm.c (vm_handle_interrupt_code): New "builtin".
2016-11-19 13:32:45 +01:00
Andy Wingo
4ae4988931 Refactor async handling to be FIFO
* libguile/async.c (scm_i_async_push, scm_i_async_pop): New helpers.
  (scm_async_tick, scm_system_async_mark_for_thread): Use the new
  helpers.
2016-11-18 22:15:28 +01:00
Andy Wingo
705e3a83c8 Remove SCM_DEBUG_CELL_ACCESSES==1
Since the move to BDW-GC this option has not been useful.

* libguile/__scm.h (SCM_DEBUG_CELL_ACCESSES): Remove default
  definition.
* libguile/gc.h: Add comment about cells.
  (SCM_VALIDATE_CELL): Remove.  I did a search on the internet and I
  found no external users.
  (SCM_CELL_WORD, SCM_CELL_OBJECT, SCM_SET_CELL_WORD)
  (SCM_SET_CELL_OBJECT, SCM_CELL_OBJECT_LOC): Remove SCM_VALIDATE_CELL
  uses.
* libguile/gc.c (scm_debug_cell_accesses_p)
  (scm_expensive_debug_cell_accesses_p)
  (scm_debug_cells_gc_interval, scm_i_expensive_validation_check)
  (scm_assert_cell_valid): Remove bindings only available when
  SCM_DEBUG_CELL_ACCESSES was 1.
* libguile/list.c (scm_list_n): Remove SCM_VALIDATE_CELL usage.
2016-11-18 21:18:23 +01:00
Andy Wingo
4985ef13e6 Explicit interrupt handling in VM
* libguile/foreign.c (CODE, get_foreign_stub_code): Add explicit
  handle-interrupts and return-values calls, as foreign-call will fall
  through.
* libguile/gsubr.c (A, B, C, AB, AC, BC, ABC, SUBR_STUB_CODE)
  (scm_i_primitive_call_ip): Same.
* libguile/vm-engine.c (VM_HANDLE_INTERRUPTS): Inline into
  handle-interrupts.
  (RETURN_ONE_VALUE, RETURN_VALUE_LIST): Inline into callers, and fall
  through instead of returning.
  (BR_BINARY, BR_UNARY, BR_ARITHMETIC, BR_U64_ARITHMETIC): Remove
  conditional VM_HANDLE_INTERRUPTS, as the compiler already inserted the
  handle-interrupts calls if needed.
  (vm_engine): Remove VM_HANDLE_INTERRUPTS invocations except in the
  handle-interrupts instruction.
2016-11-17 22:13:53 +01:00
Andy Wingo
ca74e3fae5 Add handle-interrupts inst and compiler pass
* libguile/vm-engine.c (vm_engine): Remove initial VM_HANDLE_INTERRUPTS
  call; surely our caller already handled interrupts.  Add
  handle-interrupts opcode.
* am/bootstrap.am (SOURCES):
* module/Makefile.am (SOURCES): Add handle-interrupts.scm.
* module/system/vm/assembler.scm (system):
* module/language/cps/compile-bytecode.scm (compile-function):
  (lower-cps): Add handle-interrupts support.
* module/language/cps/handle-interrupts.scm: New file.
2016-11-16 22:55:45 +01:00
Andy Wingo
fcb43488b3 Slim thread cleanup
* libguile/threads.c (on_thread_exit): Clean up the cleanup.  We no
  longer need to re-enter Guile mode, and some of the comments were
  incorrect.
2016-11-14 21:57:46 +01:00
Andy Wingo
a521440029 join-thread in Scheme
* module/ice-9/threads.scm (join-thread): Implement in Scheme.
  (call-with-new-thread): Arrange to record values in a weak table and
  signal the join cond.
  (with-mutex): Move up definition; call-with-new-thread needs it.  (How
  was this working before?)
* libguile/threads.c (guilify_self_1, guilify_self_2, do_thread_exit):
  Remove join queue management.
* libguile/threads.c (scm_join_thread, scm_join_thread_timed): Call out
  to Scheme.
  (scm_init_ice_9_threads): Capture join-thread var.
2016-11-14 21:50:41 +01:00
Andy Wingo
e447258c3f scm_spawn_thread uses call-with-new-thread
* libguile/throw.h (scm_i_make_catch_body_closure)
  (scm_i_make_catch_handler_closure): Add scm_i_ prefix and make
  available for internal use.
* libguile/throw.c: Adapt.
* libguile/threads.c (scm_spawn_thread): Rewrite in terms of
  scm_call_with_new_thread.
2016-11-14 21:25:53 +01:00
Andy Wingo
3f23688f39 Fix crasher in scm_system_async_mark_for_thread
* libguile/async.c (scm_system_async_mark_for_thread): Only signal the
  cond if there is a wait mutex.
2016-11-13 22:17:40 +01:00
Andy Wingo
9ac2c9942b More comments in threads.c
* libguile/threads.c (struct scm_mutex): Better comments.
2016-11-13 15:56:21 +01:00
Andy Wingo
e0f17417e6 Optimize lock-mutex
* libguile/threads.c (lock_mutex, scm_timed_lock_mutex): As with
  unlock_mutex before, optimize by specializing to the mutex kind.
  Also, avoid lock thrashing after a return from block_self.
2016-11-13 15:56:21 +01:00
Andy Wingo
950e728e7a Improve mutexes / condition variable implementation
* libguile/threads.c (scm_timed_lock_mutex): Use "level" field only for
  recursive mutexes.
  (unlock_mutex, scm_unlock_mutex): Factor implementation back out of
  scm_unlock_mutex (doh?), but in such a way that can specialize against
  mutex type.
  (scm_mutex_level): Only look at level for recursive mutexes.
  (scm_mutex_locked_p): Look at owner field, not level field.
  (timed_wait, scm_timed_wait_condition_variable): Factor implementation
  out, as above with unlock-mutex.  Specialize relocking of the Guile
  mutex.
2016-11-13 15:56:21 +01:00
Andy Wingo
6bb51193df Refactor GC implications of thread sleep
* libguile/async.c (struct scm_thread_wake_data): Move definition here.
  (scm_i_setup_sleep): Remove "sleep_object".  Caller now responsible
  for scm_remember_upto_here_1 as appropriate.
  (scm_system_async_mark_for_thread): Remove scm_remember_upto_here_1
  call.
* libguile/async.h (scm_i_setup_sleep): Adapt prototype.
* libguile/threads.h (struct scm_thread_wake_data): Remove definition.
* libguile/threads.c (block_self): Remove sleep_object argument.
  (scm_join_thread_timed, scm_timed_lock_mutex)
  (scm_timed_wait_condition_variable, scm_std_select): Adapt.
2016-11-13 15:56:21 +01:00
Andy Wingo
1ed9dea34a Unlocked mutexes don't have owners
* libguile/threads.c (scm_unlock_mutex)
  (scm_timed_wait_condition_variable): Unlocked mutexes should never
  have owners.
2016-11-13 15:56:21 +01:00
Andy Wingo
4110e7bbb1 Put mutex kind in SMOB flags
* libguile/threads.c (struct scm_mutex, SCM_MUTEX_KIND, scm_make_mutex)
  (scm_timed_lock_mutex, scm_unlock_mutex)
  (scm_timed_wait_condition_variable): Mutex kind in SMOB flags.
2016-11-13 15:56:21 +01:00
Andy Wingo
7fd10d21c0 Rename Guile's internal mutexes and condvars
* libguile/threads.c: Rename fat_mutex to struct scm_mutex, and likewise
  for scm_cond.
2016-11-13 15:56:21 +01:00
Andy Wingo
e7c658a611 Internal threads refactor
* libguile/threads.c: Inline "fat mutexes" and "fat conds" into their
  users.  These are just Guile mutexes and Guile condition variables.
2016-11-13 15:56:21 +01:00
Andy Wingo
03ffd726df scm_timed_lock_mutex replaces scm_lock_mutex_timed
* libguile/deprecated.h:
* libguile/deprecated.c (scm_lock_mutex_timed): Deprecate.
* libguile/threads.h:
* libguile/threads.c (scm_timed_lock_mutex): New function.
  (scm_join_thread): Fix formatting.
  (scm_lock_mutex): Fix formatting and update to scm_timed_lock_mutex
  change.
  (scm_try_mutex): Update to scm_timed_lock_mutex.
2016-11-05 19:39:12 +01:00
Andy Wingo
fc4df456a1 Separate fat mutex unlock and wait operations
* libguile/threads.c (fat_mutex_unlock, fat_mutex_wait): Separate wait
  from unlock.
  (scm_unlock_mutex, scm_timed_wait_condition_variable): Adapt.
2016-11-05 11:51:02 +01:00
Andy Wingo
56dd476af7 Back to simple unlock-mutex
* libguile/threads.c (scm_unlock_mutex): Bind to unlock-mutex.
* libguile/threads.h: Remove scm_unlock_mutex_timed.
* libguile/deprecated.h: Add scm_unlock_mutex_timed.
* libguile/deprecated.c (scm_unlock_mutex_timed): Deprecate.
* test-suite/tests/threads.test: Update unlock-mutex tests to use
  wait-condition-variable if they would wait on a cond.
2016-11-05 11:50:31 +01:00
Andy Wingo
7682461241 Replace scm_make_mutex_with_flags
* libguile/threads.c (enum fat_mutex_kind): New data type, replacing
  separate flags.
  (struct fat_mutex): Adapt.
  (make_fat_mutex): Fat mutexes can only be one of three kinds, not one
  of 4 kinds.  (Recursive unowned mutexes are not a thing.)
  (scm_make_mutex): Adapt.
  (scm_make_mutex_with_kind): New function, replacing
  scm_make_mutex_with_flags.  Still bound to make-mutex.
  (scm_make_recursive_mutex): Adapt.
  (fat_mutex_lock, fat_mutex_unlock): Adapt.
* libguile/threads.h (scm_make_mutex_with_kind): New decl.
* libguile/deprecated.h:
* libguile/deprecated.c (scm_make_mutex_with_flags): Deprecate.
2016-11-05 11:16:46 +01:00
Andy Wingo
c0916134ac Remove unchecked-unlock facility from Guile mutexes
* libguile/threads.c (fat_mutex): Remove unchecked_unlock member.
  (make_fat_mutex): Adapt.
  (scm_make_mutex_with_flags): Remove unchecked-unlock flag.
  (scm_make_recursive_mutex): Likewise.
  (fat_mutex_unlock): Remove unchecked-unlock case.
* test-suite/tests/threads.test: Remove unchecked-unlock test.
2016-11-05 10:30:54 +01:00
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