diff options
| author | Michael Albinus | 2018-08-30 21:29:04 +0200 |
|---|---|---|
| committer | Michael Albinus | 2018-08-30 21:29:04 +0200 |
| commit | 54b92132e1ec16565d59d6d9f8ff8910f38843b2 (patch) | |
| tree | 894a20a1c835c5da28d0b74a26667efed5aac189 /test/src | |
| parent | 3cc42bb60099c32f64e57d2ee33c8321adba7942 (diff) | |
| download | emacs-54b92132e1ec16565d59d6d9f8ff8910f38843b2.tar.gz emacs-54b92132e1ec16565d59d6d9f8ff8910f38843b2.zip | |
Handle thread-signal towards the main thread (Bug#32502)
* doc/lispref/threads.texi (Basic Thread Functions):
* etc/NEWS: Document thread-signal towards the main thread.
* lisp/emacs-lisp/thread.el: New package.
* src/keyboard.c (read_char): Check for Qthread_event.
(kbd_buffer_get_event, make_lispy_event): Handle THREAD_EVENT.
(syms_of_keyboard): Declare Qthread_event.
(keys_of_keyboard): Add thread-handle-event to special-event-map.
* src/termhooks.h (enum event_kind): Add THREAD_EVENT.
* src/thread.c: Include "keyboard.h".
(poll_suppress_count) Don't declare extern.
(Fthread_signal): Raise event if THREAD is the main thread. (Bug#32502)
* test/src/thread-tests.el (thread): Require it.
(threads-signal-main-thread): New test.
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/thread-tests.el | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/src/thread-tests.el b/test/src/thread-tests.el index 364f6d61f05..cc1dff8a281 100644 --- a/test/src/thread-tests.el +++ b/test/src/thread-tests.el | |||
| @@ -19,6 +19,8 @@ | |||
| 19 | 19 | ||
| 20 | ;;; Code: | 20 | ;;; Code: |
| 21 | 21 | ||
| 22 | (require 'thread) | ||
| 23 | |||
| 22 | ;; Declare the functions in case Emacs has been configured --without-threads. | 24 | ;; Declare the functions in case Emacs has been configured --without-threads. |
| 23 | (declare-function all-threads "thread.c" ()) | 25 | (declare-function all-threads "thread.c" ()) |
| 24 | (declare-function condition-mutex "thread.c" (cond)) | 26 | (declare-function condition-mutex "thread.c" (cond)) |
| @@ -320,6 +322,25 @@ | |||
| 320 | (should-not (thread-alive-p thread)) | 322 | (should-not (thread-alive-p thread)) |
| 321 | (should (equal (thread-last-error) '(error))))) | 323 | (should (equal (thread-last-error) '(error))))) |
| 322 | 324 | ||
| 325 | (ert-deftest threads-signal-main-thread () | ||
| 326 | "Test signaling the main thread." | ||
| 327 | (skip-unless (featurep 'threads)) | ||
| 328 | ;; We cannot use `ert-with-message-capture', because threads do not | ||
| 329 | ;; know let-bound variables. | ||
| 330 | (with-current-buffer "*Messages*" | ||
| 331 | (let (buffer-read-only) | ||
| 332 | (erase-buffer)) | ||
| 333 | (let ((thread | ||
| 334 | (make-thread #'(lambda () (thread-signal main-thread 'error nil))))) | ||
| 335 | (while (thread-alive-p thread) | ||
| 336 | (thread-yield)) | ||
| 337 | (read-event nil nil 0.1) | ||
| 338 | ;; No error has been raised, which is part of the test. | ||
| 339 | (should | ||
| 340 | (string-match | ||
| 341 | (format-message "Error %s: (error nil)" thread) | ||
| 342 | (buffer-string )))))) | ||
| 343 | |||
| 323 | (defvar threads-condvar nil) | 344 | (defvar threads-condvar nil) |
| 324 | 345 | ||
| 325 | (defun threads-test-condvar-wait () | 346 | (defun threads-test-condvar-wait () |