summaryrefslogtreecommitdiff
path: root/libguile/threads.c
AgeCommit message (Collapse)AuthorFilesLines
2013-07-16Merge remote-tracking branch 'origin/stable-2.0'Mark H Weaver1-2/+2
Conflicts: libguile/keywords.c libguile/vm.c
2013-06-17Fix bug in remqueue in threads.c when removing last element.Mark H Weaver1-1/+1
Reported and debugged by Andrew Gaylard <ag@computer.org>. * libguile/threads.c (remqueue): When removing the last element from a queue with more than one element, set (car q) to the previous element. * THANKS: Thank Andrew Gaylard.
2013-06-10Allow #f as timeout argument to unlock-mutex and SRFI-18 mutex-unlock!Mark H Weaver1-1/+1
Reported by Chaos Eternal <chaoseternal@shlug.org> Based on a patch by Nala Ginrut <nalaginrut@gmail.com> * libguile/threads.c (scm_unlock_mutex_timed): If 'timeout' argument is false, interpret that as no timeout. * doc/ref/api-scheduling.texi (Mutexes and Condition Variables): Update documentation.
2013-03-28Merge remote-tracking branch 'origin/stable-2.0'Mark H Weaver1-9/+25
Conflicts: configure.ac libguile/deprecated.c libguile/deprecated.h libguile/filesys.h libguile/fluids.c libguile/fports.c libguile/gc.c libguile/guile.c libguile/numbers.c libguile/objcodes.c libguile/r6rs-ports.c libguile/smob.c libguile/socket.c libguile/threads.h module/language/scheme/decompile-tree-il.scm module/language/tree-il/peval.scm test-suite/tests/syncase.test
2013-03-13allow for spurious wakeups from pthread_cond_waitAndy Wingo1-3/+9
* libguile/threads.c (scm_call_with_new_thread, scm_spawn_thread): Allow for spurious wakeups while waiting on cond variables. Should fix bug 10641.
2013-03-09don't provide scm_std_select on mingw and similar platformsAndy Wingo1-6/+16
* libguile/iselect.h: If we do not have sys/select.h, don't provide scm_std_select, SELECT_TYPE, FD_SET, FD_ZERO, FD_ISSET, or FD_CLR. Guile should not be setting these macros in public API. This is an incompatible change on mingw, but oh well. * libguile/threads.c: Rely on gnulib's select, and use that to implement scm_std_select. * libguile/deprecated.h: * libguile/deprecated.c: Only provide scm_internal_select if we have sys/select.h.
2012-11-05Merge remote-tracking branch 'origin/stable-2.0'Mark H Weaver1-4/+5
Conflicts: libguile/validate.h
2012-11-05Fix invalid assertion about mutex ownership in threads.c.Ludovic Courtès1-4/+5
* libguile/threads.c (do_thread_exit): Don't assert m->owner == t->handle since that is not the case when MUTEX was abandoned by T. Reported by Mark Weaver and others.
2012-03-08Merge remote-tracking branch 'local-2.0/stable-2.0'Andy Wingo1-0/+3
Conflicts: configure.ac libguile/finalizers.c libguile/finalizers.h libguile/gc.c libguile/gc.h libguile/inline.c libguile/inline.h libguile/ports.c libguile/smob.c libguile/smob.h module/ice-9/deprecated.scm module/ice-9/r4rs.scm
2012-03-08run finalizers asynchronously in asyncsAndy Wingo1-0/+3
* 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.
2012-03-03the dynamic stack is really a stack now, instead of a listAndy Wingo1-1/+7
* libguile/dynstack.h: * libguile/dynstack.c: New files, implementing the dynamic stack as a true stack instead of a linked list. This lowers the cost of dynwinds: frames, winders, prompts, with-fluids, and dynamic-wind. For the most part, we allocate these items directly on the stack. * libguile/dynwinds.h: * libguile/dynwinds.c: Adapt all manipulators of the wind stack to use interfaces from dynstack.c. Remove heap-allocated winder and frame object types. (scm_dowinds, scm_i_dowinds): Remove these. The first was exported, but it was not a public interface. * libguile/continuations.c: * libguile/continuations.h (scm_t_contregs): Continuation objects reference scm_t_dynstack* values now. Adapt to the new interfaces. * libguile/control.c: * libguile/control.h: There is no longer a scm_tc7_prompt kind of object that can be allocated on the heap. Instead, the prompt flags, key, and registers are pushed on the dynwind stack. (The registers are still on the heap.) Also, since the vm_cont will reference the dynwinds, make the partial continuation stub take just one extra arg, instead of storing the intwinds separately in the object table. * libguile/fluids.c: * libguile/fluids.h: No more with-fluids objects; instead, the fluids go on the dynstack. The values still have to be on the heap, though. (scm_prepare_fluids, scm_swap_fluids): New internal functions, replacing scm_i_make_with_fluids and scm_i_swap_with_fluids. * libguile/print.c: Remove prompt and with-fluids printers. * libguile/tags.h: Revert prompt and with-fluids tc7 values to what they were before they were allocated. * libguile/vm-i-system.c (partial_cont_call): Just pop the vmcont, the intwinds will not be passed as a second arg. Rewind the dynamic stack from within the VM, so that any rewinder sees valid prompt entries. (call_cc, tail_call_cc): Adapt to pass the dynstack to scm_i_vm_capture_stack. (prompt, wind, unwind, wind_fluids, unwind_fluids): Adapt to the new interfaces. * libguile/vm.h (scm_i_capture_current_stack): Rename from scm_i_vm_capture_continuation. (scm_i_vm_capture_stack): Take a dynstack as an argument. * libguile/vm.c (vm_reinstate_partial_continuation): Don't wind here, as that could result in winders seeing invalid prompts. * libguile/eval.c: * libguile/root.c: * libguile/stacks.c: * libguile/threads.c: * libguile/threads.h: * libguile/throw.c: Adapt other users of dynwinds to use the dynstack.
2012-02-24statically initialize the pthread mutex in fat mutexenAndy Wingo1-10/+4
* libguile/threads.c (make_fat_mutex): Remove smob free function. Because we use normal mutexen, we can just blit the mutex to initialize it.
2012-02-23Revert "install pthread_atfork handlers for guile's static mutexen"Andy Wingo1-3/+0
This reverts commit 6a97b1f93aace5c7c976aef51d36b3ae9cfd5630.
2012-02-17install pthread_atfork handlers for guile's static mutexenAndy Wingo1-0/+3
* libguile/async.c: * libguile/deprecation.c: * libguile/fluids.c: * libguile/gc.c: * libguile/instructions.c: * libguile/ports.c: * libguile/posix.c: * libguile/strings.c: * libguile/threads.c: Use the SCM_PTHREAD_ATFORK_LOCK_STATIC_MUTEX mechanism to lock a number of static mutexen.
2012-02-08Merge remote-tracking branch 'origin/stable-2.0'Andy Wingo1-8/+9
Conflicts: GUILE-VERSION libguile/gc-malloc.c libguile/ports.c
2012-02-02Improve the usage of variable names in C docstrings.Bake Timmons1-8/+9
* libguile/alist.c: * libguile/array-map.c: * libguile/arrays.c: * libguile/bitvectors.c: * libguile/filesys.c: * libguile/foreign.c: * libguile/generalized-arrays.c: * libguile/hashtab.c: * libguile/ioext.c: * libguile/load.c: * libguile/numbers.c: * libguile/ports.c: * libguile/posix.c: * libguile/print.c: * libguile/procprop.c: * libguile/promises.c: * libguile/simpos.c: * libguile/socket.c: * libguile/srfi-1.c: * libguile/srfi-13.c: * libguile/srfi-14.c: * libguile/stacks.c: * libguile/stime.c: * libguile/strings.c: * libguile/struct.c: * libguile/symbols.c: * libguile/threads.c: * libguile/weak-table.c: * libguile/weak-vector.c: Make the variable names in the C docstrings more consistent. Replace a few instances of @var with @code when appropriate.
2012-01-30Merge remote-tracking branch 'origin/stable-2.0'Andy Wingo1-1/+0
Conflicts: libguile/debug.h module/ice-9/psyntax-pp.scm module/ice-9/psyntax.scm module/language/tree-il/peval.scm module/language/tree-il/primitives.scm
2012-01-30Merge commit '3d51e57cfb0404db568a6adfde2a346d3fd9907e'Andy Wingo1-0/+1
Conflicts: libguile/foreign.c libguile/hashtab.c module/ice-9/psyntax-pp.scm module/language/tree-il/compile-glil.scm
2012-01-30Merge commit '9b0975f1dc41ddd10d81fb5b0965b9e9a54ef37a'Andy Wingo1-1/+3
Conflicts: libguile/foreign.c module/ice-9/psyntax-pp.scm module/ice-9/psyntax.scm
2012-01-26Revert "Universally-unique gensyms"Andy Wingo1-1/+0
This reverts commit ad432bc8317c33899efc29854550b67f3d7babf7. Not all gensyms need to be universally-unique: most of them just need to be unique within some portion of a Guile session. We'll take a different tack on this problem in the next commit.
2012-01-21Universally-unique gensymsMark H Weaver1-0/+1
* libguile/symbols.c (scm_gensym): Make the gensym counter a 128-bit thread-local, initialized to a random number upon the first call to `gensym' within a given thread. This counter is rendered as a 22 byte suffix of mostly base64 digits. * libguile/threads.h (scm_i_thread): Add a thread-local gensym_counter. * libguile/threads.c (guilify_self_1): Initialize gensym_counter to NULL.
2012-01-16Fix typo in threads.c on IA64.Ludovic Courtès1-1/+1
* libguile/threads.c (guilify_self_1)[__ia64__]: Fix typo. Reported by Bruno Haible <bruno@clisp.org>.
2012-01-12Make sure `scm_spawn_thread' returns a thread.Ludovic Courtès1-0/+2
* libguile/threads.c (scm_spawn_thread): Add an assertion that DATA.thread is a thread. This assertion is sometimes hit on x86_64-freebsd8.2.
2012-01-10Merge remote-tracking branch 'origin/stable-2.0'Andy Wingo1-1/+4
Conflicts: libguile/__scm.h libguile/array-map.c libguile/procprop.c libguile/tags.h module/ice-9/deprecated.scm module/ice-9/psyntax-pp.scm module/ice-9/psyntax.scm test-suite/standalone/test-num2integral.c test-suite/tests/regexp.test
2012-01-10Merge commit 'f78a1ccede02ccad89d6c91a6b297f1f14a30907'Andy Wingo1-0/+42
2012-01-05Placate a number of `syntax-check' verifications.Ludovic Courtès1-2/+5
- "filesystem" -> "file system" - remove doubled words - use EXIT_* macros instead of literal numbers - update `syntax-check' exclusion files
2011-12-22freebsd itanium supportAndy Wingo1-0/+15
* libguile/threads.c (scm_ia64_register_backing_store_base) (scm_ia64_ar_bsp): Provide implementation of these itanium helpers on freebsd. Thanks to Jim Pryor.
2011-12-22freebsd implementation of get_thread_stack_baseAndy Wingo1-0/+27
* configure.ac: Check for pthread_np.h and pthread_attr_get_np. Patch by Jim Pryor. * libguile/threads.c (get_thread_stack_base): Provide an implementation for FreeBSD.
2011-12-01Merge remote-tracking branch 'origin/stable-2.0'Andy Wingo1-2/+3
Conflicts: configure.ac libguile/fluids.c libguile/gc.c libguile/gc.h libguile/objcodes.c libguile/procprop.c libguile/vm.c module/ice-9/psyntax-pp.scm module/ice-9/psyntax.scm
2011-11-29collect a little in call-with-new-threadAndy Wingo1-0/+1
* libguile/threads.c (scm_call_with_new_thread): Collect a little before making a new thread. Our adjust_gc_frequency hack doesn't work well if the main allocation load is thread creation, as in https://savannah.gnu.org/bugs/?34140. This does not appreciably affect the speed of the test in that bug, but does effectively limit the image size.
2011-11-23optional default-value arg to make-fluidAndy Wingo1-2/+2
* libguile/fluids.c (grow_dynamic_state, new_fluid): Arrange for the default value in the dynamic-state vector to be SCM_UNDEFINED instead of SCM_BOOL_F. If the value in the dynamic-state is #f, default to a value attached to the fluid instead. This allows useful default values. (scm_make_fluid_with_default): New function, allows the user to specify a default value for the fluid. Defaults to #f. Bound to `make-fluid' on the Scheme side. (scm_make_unbound_fluid): Use SCM_UNDEFINED as the default in all threads. (scm_fluid_unset_x): Also unset the default value. Not sure if this is the right thing. (fluid_ref): Update to the new default-value strategy. * libguile/threads.c (scm_i_reset_fluid): Reset to SCM_UNDEFINED. * libguile/threads.h: Remove extra arg to scm_i_reset_fluid. * libguile/vm-i-system.c (fluid-ref): Update to new default-value strategy. * module/ice-9/vlist.scm (block-growth-factor): Default to 2 in all threads. Fixes http://debbugs.gnu.org/10093.
2011-11-08locking for putc, putsAndy Wingo1-7/+7
* libguile/ports.c (scm_putc, scm_puts): * libguile/ports.h (scm_putc_unlocked, scm_puts_unlocked): Separate into _unlocked and locked variants. Change all callers to use the _unlocked versions.
2011-10-24remove weak pairs, rewrite weak vectorsAndy Wingo1-7/+26
* libguile/weak-vector.c: * libguile/weak-vector.h: Renamed from weaks.[ch]. Remove weak pairs. They were not safe to access with `car' and `cdr'. Remove weak alist vectors, as we have weak tables and sets. Reimplement weak vectors, moving the implementation here. * libguile/vectors.c: * libguile/vectors.h: Remove the extra header word. Use scm_c_weak_vector_ref / scm_c_weak_vector_set_x to access weak vectors. * libguile/snarf.h: Remove the extra header word in vectors. * libguile/threads.c (do_thread_exit, fat_mutex_lock, fat_mutex_unlock): Instead of weak pairs, store thread-owned mutexes in a list of one-element weak vectors. * libguile/guardians.c (finalize_guarded): Similarly, store object guardians in a list of one-element weak vectors. * libguile/modules.c (scm_module_reverse_lookup): We no longer need to handle the case of weak references. * libguile/print.c (iprin1): Use the standard vector accessor to print vectors. * libguile.h: * libguile/Makefile.am: * libguile/gc-malloc.c: * libguile/gc.c: * libguile/goops.c: * libguile/init.c: * libguile/objprop.c: * libguile/struct.c: Update includes. * module/ice-9/weak-vector.scm: Load weak vector definitions using an extension instead of %init-weaks-builtins. * test-suite/tests/weaks.test: Use the make-...-hash-table names instead of the old alist vector names.
2011-07-25Merge remote-tracking branch 'origin/stable-2.0'Andy Wingo1-8/+10
Conflicts: GUILE-VERSION test-suite/tests/srfi-4.test
2011-07-01Revert "Fix lock ordering in `fat_mutex_lock' to match that of ↵Ludovic Courtès1-2/+3
`do_thread_exit'." This reverts commit ccb80964cd7cd112e300c34d32f67125a6d6da9a, 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-01Type-check the OWNER argument of `lock-mutex'.Ludovic Courtès1-0/+3
* libguile/threads.c (scm_lock_mutex_timed): Type-check OWNER.
2011-06-30Fix `on_thread_exit' for canceled threads.Ludovic Courtès1-6/+4
* 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-30Merge remote-tracking branch 'local-2.0/stable-2.0'Andy Wingo1-0/+3
Conflicts: libguile/deprecated.c module/ice-9/psyntax-pp.scm
2011-06-28Fix lock ordering in `fat_mutex_lock' to match that of `do_thread_exit'.Ludovic Courtès1-0/+3
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-23don't spawn the signal delivery thread in a thread-exit handlerAndy Wingo1-4/+0
* libguile/threads.c (do_thread_exit): Remove needless spawn of the signal delivery thread.
2011-06-16Merge remote-tracking branch 'local-2.0/stable-2.0'Andy Wingo1-10/+20
2011-06-16O_CLOEXEC usageAndy Wingo1-10/+2
* libguile/objcodes.c (scm_load_objcode): * libguile/scmsigs.c (start_signal_delivery_thread): * libguile/threads.c (guilify_self_1): Use O_CLOEXEC.
2011-06-16fix initial values of reallocated fluidsAndy Wingo1-0/+18
* 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-05-22Don't call scm_lock_mutex and scm_unlock_mutex via pointer of wrong typeMark H Weaver1-2/+14
* 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-22Don't call scm_lock_mutex and scm_unlock_mutex via pointer of wrong typeMark H Weaver1-2/+14
* 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-15use of EXIT_SUCCESS and EXIT_FAILUREAndy Wingo1-1/+1
* 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-15rename scm_async_click() to scm_async_tick(); privatize SCM_ASYNC_TICKAndy Wingo1-1/+1
* 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-13refactor do_thread_exit cleanup handler invocationAndy Wingo1-1/+8
* libguile/threads.c (do_thread_exit): Redo cleanup handler call so as not to shove a SCM into a pointer.
2011-04-25Move `{total,current}-processor-count' outside of `posix.c'.Ludovic Courtès1-0/+34
* 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-25Make `scm_i_ensure_signal_delivery_thread' call in Guile mode.Ludovic Courtès1-4/+4
* libguile/threads.c (on_thread_exit): Move `scm_i_ensure_signal_delivery_thread' call... (do_thread_exit): ... here.