1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-29 08:31:35 -08:00
Commit graph

64 commits

Author SHA1 Message Date
Eli Zaretskii
ea39d470bf Avoid crashes on C-g when several threads wait for input
* src/thread.h (m_getcjmp): New member of 'struct thread_state'.
(getcjmp): Define to current thread's 'm_getcjmp'.
* src/thread.c (maybe_reacquire_global_lock): Switch to main
thread, since this is called from a SIGINT handler, which always
runs in the context of the main thread.
* src/lisp.h (sys_jmp_buf, sys_setjmp, sys_longjmp): Move the
definitions before thread.h is included, as thread.h now uses
sys_jmp_buf.
* src/keyboard.c (getcjmp): Remove declaration.
(read_char): Don't call maybe_reacquire_global_lock here.
(handle_interrupt): Call maybe_reacquire_global_lock here, if
invoked from the SIGINT handler, to make sure
quit_throw_to_read_char runs with main thread's Lisp bindings and
uses the main thread's jmp_buf buffer.  (Bug#28630)
2017-10-04 10:27:49 +03:00
Paul Eggert
bc511a64f6 Prefer HTTPS to FTP and HTTP in documentation
Most of this change is to boilerplate commentary such as license URLs.
This change was prompted by ftp://ftp.gnu.org's going-away party,
planned for November.  Change these FTP URLs to https://ftp.gnu.org
instead.  Make similar changes for URLs to other organizations moving
away from FTP.  Also, change HTTP to HTTPS for URLs to gnu.org and
fsf.org when this works, as this will further help defend against
man-in-the-middle attacks (for this part I omitted the MS-DOS and
MS-Windows sources and the test tarballs to keep the workload down).
HTTPS is not fully working to lists.gnu.org so I left those URLs alone
for now.
2017-09-13 15:54:37 -07:00
Paul Eggert
9dee1c884e Improve stack-overflow heuristic on GNU/Linux
Problem reported by Steve Kemp (Bug#27585).
* src/eval.c (near_C_stack_top): Remove.  All uses replaced
by current_thread->stack_top.
(record_in_backtrace): Set current_thread->stack_top.
This is for when the Lisp interpreter calls itself.
* src/lread.c (read1): Set current_thread->stack_top.
This is for recursive s-expression reads.
* src/print.c (print_object): Set current_thread->stack_top.
This is for recursive s-expression printing.
* src/thread.c (mark_one_thread): Get stack top first.
* src/thread.h (struct thread_state.stack_top): Now void *, not char *.
2017-07-14 04:57:18 -07:00
Paul Eggert
b867eb8ecf Use ptrdiff_t, not int, for stack sizes
* src/thread.c (invoke_thread_function):
* src/xterm.c (x_cr_export_frames):
Don’t assume SPECPDL_INDEX fits in ‘int’.
2017-05-02 15:05:08 -07:00
Eli Zaretskii
5fefaaa8c0 Fix a bug with signaling a thread that waits for condvar
* src/thread.c (lisp_mutex_lock_for_thread): New function,
with all the guts of lisp_mutex_lock.
(lisp_mutex_lock): Call lisp_mutex_lock_for_thread.
(condition_wait_callback): Don't call post_acquire_global_lock
before locking the mutex, as that could cause a signaled thread to
exit prematurely, because the condvar's mutex is recorded to be
not owned by any thread, and with-mutex wants to unlock it as part
of unwinding the stack in response to the signal.
2017-01-18 18:06:42 +02:00
Eli Zaretskii
571532605b Rudimentary error handling for non-main threads
* src/thread.c (last_thread_error): New static variable.
(syms_of_threads): Staticpro it.
(record_thread_error, Fthread_last_error): New functions.
(syms_of_threads): Defsubr Fthread_last_error.

* doc/lispref/threads.texi (Basic Thread Functions): Document
thread-last-error.

* test/src/thread-tests.el (thread-errors, thread-signal-early)
(threads-condvar-wait): Test the values returned by
thread-last-error.
2017-01-18 18:00:16 +02:00
Eli Zaretskii
03e4ab0d58 Fix a bug in waiting for condition variable
* src/thread.c (lisp_mutex_lock, lisp_mutex_unlock)
(lisp_mutex_unlock_for_wait, condition_wait_callback)
(condition_notify_callback): Improve commentary.
(condition_wait_callback): Call post_acquire_global_lock before
attempting to lock the mutex, to make sure the lock's owner is
recorded correctly.

* test/src/thread-tests.el (threads-condvar-wait): New test.
2017-01-13 11:48:51 +02:00
Paul Eggert
e6a782ee1a Update copyright year to 2017 in master
Run admin/update-copyright in the master branch.  This fixes files
that were not already fixed in the emacs-25 branch before it was
merged here.
2017-01-01 01:48:59 -08:00
Paul Eggert
108ef8033b Rename primary_thread to main_thread
This avoids the confusion of using two different phrases "main thread"
and "primary thread" internally to mean the same thing.  See:
http://lists.gnu.org/archive/html/emacs-devel/2016-12/msg01142.html
* src/thread.c (main_thread): Rename from primary_thread,
since the new name no longer clashes with main_thread_id
and Emacs internals normally call this the "main thread".
(init_main_thread): Rename from init_primary_thread.
(main_thread_p): Rename from primary_thread_p.
All uses changed.
2016-12-30 13:43:24 -08:00
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