Commit graph

55 commits

Author SHA1 Message Date
Paul Eggert
a815e5f195 Remove interpreter’s byte stack
This improves performance overall on my benchmark on x86-64,
since the interpreted program-counter resides in a machine
register rather than in RAM.
* etc/DEBUG, src/.gdbinit: Remove xbytecode GDB command, as there
is no longer a byte stack to decode.
* src/bytecode.c (struct byte_stack, byte_stack_list)
(relocate_byte_stack): Remove.  All uses removed.
(FETCH): Simplify now that pc is now local (typically, in a
register) and no longer needs to be relocated.
(CHECK_RANGE): Remove.  All uses now done inline, in a different way.
(BYTE_CODE_QUIT): Remove; now done by op_relative_branch.
(exec_byte_code): Allocate a copy of the function’s bytecode,
so that there is no problem if GC moves it.
* src/lisp.h (struct handler): Remove byte_stack member.
All uses removed.
* src/thread.c (unmark_threads): Remove.  All uses removed.
* src/thread.h (struct thread_state): Remove m_byte_stack_list member.
All uses removed.  m_stack_bottom is now the first non-Lisp field.
2016-12-23 21:46:53 -08:00
Paul Eggert
e2767bd010 Use max_align_t instead of void *
* src/thread.c (run_thread): Don’t assume void * is aligned enough.
2016-12-23 18:29:13 -08:00
Eli Zaretskii
c4e38581d3 Avoid aborts due to unaligned byte stack of threads
* src/thread.c (run_thread): Make sure the pointers to thread byte
stack are properly aligned.  (Bug#25247)
2016-12-23 10:24:30 +02:00
Paul Eggert
73349822cb ; Spelling fixes 2016-12-22 10:14:11 -08:00
Eli Zaretskii
5fcc777ff3 Fix last change with thread marking under GC_CHECK_MARKED_OBJECTS
* src/thread.c (primary_thread_p): New function.
* src/alloc.c (mark_object): Use 'primary_thread_p' to bypass tests
meant for thread objects allocated dynamically.
* src/thread.h (primary_thread_p): Add prototype.
2016-12-22 18:13:16 +02:00
Eli Zaretskii
fe3188b1ce Fix crashes upon C-g on Posix TTY frames
* src/thread.h (struct thread_state): New member not_holding_lock.
(maybe_reacquire_global_lock): Add prototype.
* src/thread.c: Include syssignal.h.
(maybe_reacquire_global_lock): New function.
(really_call_select): Set the not_holding_lock member of the
thread state before releasing the lock, and rest it after
re-acquiring the lock when the select function returns.  Block
SIGINT while doing this to make sure we are not interrupted on TTY
frames.
* src/sysdep.c (block_interrupt_signal, restore_signal_mask): New
functions.
* src/syssignal.h (block_interrupt_signal, restore_signal_mask):
Add prototypes.
* src/keyboard.c (read_char) [THREADS_ENABLED]: Call
maybe_reacquire_global_lock.  (Bug#25178)
2016-12-19 19:11:16 +02:00
Eli Zaretskii
825f4dd42f Avoid crashing if a new thread is signaled right away
* src/thread.c (post_acquire_global_lock): Don't raise the pending
signal if the thread's handlers were not yet set up, as that will
cause Emacs to exit with a fatal error.  This can happen if a
thread is signaled as soon as make-thread returns, before the new
thread had an opportunity to acquire the global lock, set up the
handlers, and call the thread function.

* test/src/thread-tests.el (thread-signal-early): New test.
2016-12-12 19:08:21 +02:00
Eli Zaretskii
a416e1d6c1 Fix point motion in cloned buffers
* src/thread.c (post_acquire_global_lock): Call
set_buffer_internal_2 instead of tricking set_buffer_internal_1
into resetting the current buffer even if it didn't change.  This
avoids bug#25165, caused by failing to record the modified values
of point and mark, because current_buffer was set to NULL.  Also,
don't bother re-setting the buffer if there was no thread switch,
as that just wastes cycles.
* src/buffer.c (set_buffer_internal_2): New function, with most of
the body of set_buffer_internal_1, but without the test for B
being identical to the current buffer.
(set_buffer_internal_1): Call set_buffer_internal_2 if B is not
identical to the current buffer.
* src/buffer.h (set_buffer_internal_2): Add prototype.

* test/src/thread-tests.el (thread-sticky-point): New test.
2016-12-12 18:03:40 +02:00
Glenn Morris
25a52ca6b2 ; Fix copyright years in new files 2016-12-10 10:19:06 -08:00
Eli Zaretskii
828b4560cd Fix error messages in thread.c
* src/thread.c (lisp_mutex_unlock, Fcondition_wait)
(Fcondition_notify, Fthread_join): Fix error messages.
2016-12-10 11:42:48 +02:00
Eli Zaretskii
c364d62f89 Improve doc strings in thread.c
* src/thread.c (Fmake_condition_variable, Fcondition_wait)
(Fcondition_notify, Fcondition_mutex, Fcondition_name, Fmake_thread)
(Fthread_join, Fall_threads): Doc fixes.
2016-12-10 11:31:11 +02:00
Eli Zaretskii
e4df093e60 Fix building with check-lisp-object-type
* src/thread.c (mark_one_thread): Use NILP to compare with
m_saved_last_thing_searched, which is a Lisp object.  Reported by
Andreas Politz <politza@hochschule-trier.de>.
2016-12-10 11:06:23 +02:00
Eli Zaretskii
54f52a1390 Fix compilation warnings
* src/thread.c (Fmake_thread): Call emacs_abort, to avoid
compilation warning.
2016-12-08 20:47:27 +02:00
Eli Zaretskii
66a5abb102 Fix compilation problems. 2016-12-05 22:50:44 +02:00
Eli Zaretskii
de4624c99e Merge branch 'concurrency'
Conflicts (resolved):
	configure.ac
	src/Makefile.in
	src/alloc.c
	src/bytecode.c
	src/emacs.c
	src/eval.c
	src/lisp.h
	src/process.c
	src/regex.c
	src/regex.h
2016-12-04 19:59:17 +02:00
Ken Raeburn
39372e1a10 merge from trunk 2015-11-01 01:42:21 -04:00
Tom Tromey
77936017af change condition-variablep to condition-variable-p 2013-10-17 21:32:26 -06:00
Eli Zaretskii
bed10876db Fix crashes when unbind_for_thread_switch signals an error.
src/eval.c (unbind_for_thread_switch): Accept a 'struct
 thread_state *' argument and use specpdl_ptr and specpdl of that
 thread.  Fixes crashes if find_symbol_value signals an error.
 src/thread.c (post_acquire_global_lock): Update current_thread
 before calling unbind_for_thread_switch.  Pass the previous thread
 to unbind_for_thread_switch.
2013-09-01 18:43:43 +03:00
Tom Tromey
8c46d17826 rename thread-blocker to thread--blocker 2013-08-27 12:57:18 -06:00
Tom Tromey
6a64a7118d make thread_check_current_buffer return bool 2013-08-27 12:29:56 -06:00
Tom Tromey
c160274456 use record_unwind_protect_void, avoid warning 2013-08-26 08:53:26 -06:00
Tom Tromey
2ee7755c8d implement --enable-threads and a thread-less mode 2013-08-26 08:46:30 -06:00
Tom Tromey
e6f63071a3 Use thread_alive_p in a couple more spots 2013-07-11 17:27:28 -06:00
Tom Tromey
65ddc9fdcd fix xfree bug in run_thread
this fixes run_thread to account for the dummy slot
in specpdl
2013-07-07 14:30:31 -06:00
Tom Tromey
6dacdad5fc merge from trunk
this merges frmo trunk and fixes various build issues.
this needed a few ugly tweaks.
this hangs in "make check" now
2013-07-06 23:18:58 -06:00
Tom Tromey
32ca162e99 call init_primary_thread from init_threads 2013-07-06 14:26:36 -06:00
Tom Tromey
9db4b98e13 avoid current_thread sometimes
this tweaks thread.c to use 'self' instead of current_thread
in a couple spots.  this is clearer and more robust
2013-07-04 20:00:54 -06:00
Tom Tromey
2efa60a37d unlink thread later
unlink thread from global list later
also remove some unnecessary destruction code
2013-07-03 22:00:43 -06:00
Tom Tromey
39d7c9d51b introduce thread_alive_p macro
This introduces the thread_alive_p macro and changes
thread-alive-p to use it.  This is a minor cleanup.
It also changes all-threads to ignore dead threads.
2013-07-03 16:20:07 -06:00
Tom Tromey
c60685a8c4 Don't call unbind_for_thread_switch in run_thread
This removes the call to unbind_for_thread_switch from run_thread.
This isn't necessary because acquire_global_lock does it properly.
2013-07-03 13:42:31 -06:00
Tom Tromey
313dfb6277 fix a few latent issues in the thread patch
* we called unbind_for_thread_switch unconditionally, but this
  is wrong if the previous thread exited
* likewise, exiting a thread should clear current_thread
* redundant assignment in run_thread
* clean up init_threads - no need to re-init the primary thread

This patch still sometimes causes weird hangs in "make check".
However, I think that is a kernel bug, since Emacs enters the zombie
state but its parent process hangs in wait.  This shouldn't happen.
2013-06-06 13:18:05 -06:00
Tom Tromey
68359abba9 merge from trunk; clean up some issues 2013-06-03 12:25:05 -06:00
Tom Tromey
cbcba8ce7f don't let kill-buffer kill a buffer if it is current in any thread 2013-03-18 08:48:53 -06:00
Tom Tromey
587dd92ea0 cannot thread-join the current thread 2012-08-27 10:12:29 -06:00
Tom Tromey
68608de203 pass the thread name to the OS if possible
use prctl to pass the thread name to the OS, if possible
2012-08-20 12:17:36 -06:00
Tom Tromey
b94de89342 another docstring fixlet 2012-08-19 03:38:30 -06:00
Tom Tromey
266c1c2fd9 minor docstring fixup 2012-08-19 03:36:50 -06:00
Tom Tromey
1fb339bccd add condition-mutex and condition-name 2012-08-19 03:31:57 -06:00
Tom Tromey
9dad5e59e3 ensure name of a thread is a string 2012-08-19 03:26:42 -06:00
Tom Tromey
3cbf5b1d3b ensure name of a mutex is a string 2012-08-19 03:26:09 -06:00
Tom Tromey
977c4aa65f use NILP 2012-08-19 03:25:06 -06:00
Tom Tromey
5651640d57 condition variables
This implements condition variables for elisp.
This needs more tests.
2012-08-19 03:23:03 -06:00
Tom Tromey
b3c78ffa31 refactor systhread.h
This refactors systhread.h to move the notion of a "lisp mutex"
into thread.c.  This lets us make make the global lock and
post_acquire_global_lock static.
2012-08-18 19:59:47 -06:00
Tom Tromey
f52cfea0dc write docstrings for the thread functions 2012-08-17 07:51:19 -06:00
Tom Tromey
abb9e9d865 declare unbind_for_thread_switch and rebind_for_thread_switch in lisp.h 2012-08-17 07:16:16 -06:00
Tom Tromey
6c0d5ae507 process changes
This changes wait_reading_process_output to handle threads better.  It
introduces a wrapper for select that releases the global lock, and it
ensures that only a single thread can select a given file descriptor
at a time.

This also adds the thread-locking feature to processes.  By default a
process can only have its output accepted by the thread that created
it.  This can be changed using set-process-thread.  (If the thread
exits, the process is again available for waiting by any thread.)

Note that thread-signal will not currently interrupt a thread blocked
on select.  I'll fix this later.
2012-08-15 13:19:24 -06:00
Tom Tromey
dbb33d4e99 This adds thread-blocker, a function to examine what a thread is
blocked on.  I thought this would be another nice debugging addition.
2012-08-15 13:16:33 -06:00
Tom Tromey
8d3566c6a0 This adds names to mutexes. This seemed like a nice debugging
extension.
2012-08-15 13:14:14 -06:00
Tom Tromey
51100bb8d3 This supplies the mutex implementation for Emacs Lisp.
A lisp mutex is implemented using a condition variable, so that we can
interrupt a mutex-lock operation by calling thread-signal on the
blocking thread.  I did things this way because pthread_mutex_lock
can't readily be interrupted.
2012-08-15 13:11:22 -06:00
Tom Tromey
1dcacbc647 This adds most of the thread features visible to emacs lisp.
I roughly followed the Bordeaux threads API:

http://trac.common-lisp.net/bordeaux-threads/wiki/ApiDocumentation

... but not identically.  In particular I chose not to implement
interrupt-thread or destroy-thread, but instead a thread-signalling
approach.

I'm still undecided about *default-special-bindings* (which I did not
implement).  I think it would be more emacs-like to capture the let
bindings at make-thread time, but IIRC Stefan didn't like this idea
the first time around.

There are one or two semantics issues pointed out in the patch where I
could use some advice.
2012-08-15 13:09:32 -06:00