diff options
| author | Eli Zaretskii | 2017-01-18 18:00:16 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2017-01-18 18:00:16 +0200 |
| commit | 571532605bc0db221c76e36067435e4355e0d1a1 (patch) | |
| tree | 5a8120468d552a682c5bbfc1ec9f83c80d364b11 /src/thread.c | |
| parent | dbb29d7eb428dd53617d31a9cc159d889deb1e8e (diff) | |
| download | emacs-571532605bc0db221c76e36067435e4355e0d1a1.tar.gz emacs-571532605bc0db221c76e36067435e4355e0d1a1.zip | |
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.
Diffstat (limited to 'src/thread.c')
| -rw-r--r-- | src/thread.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/thread.c b/src/thread.c index 5498fe5efcb..6048516659e 100644 --- a/src/thread.c +++ b/src/thread.c | |||
| @@ -663,10 +663,13 @@ invoke_thread_function (void) | |||
| 663 | return unbind_to (count, Qnil); | 663 | return unbind_to (count, Qnil); |
| 664 | } | 664 | } |
| 665 | 665 | ||
| 666 | static Lisp_Object last_thread_error; | ||
| 667 | |||
| 666 | static Lisp_Object | 668 | static Lisp_Object |
| 667 | do_nothing (Lisp_Object whatever) | 669 | record_thread_error (Lisp_Object error_form) |
| 668 | { | 670 | { |
| 669 | return whatever; | 671 | last_thread_error = error_form; |
| 672 | return error_form; | ||
| 670 | } | 673 | } |
| 671 | 674 | ||
| 672 | static void * | 675 | static void * |
| @@ -695,7 +698,7 @@ run_thread (void *state) | |||
| 695 | handlerlist_sentinel->next = NULL; | 698 | handlerlist_sentinel->next = NULL; |
| 696 | 699 | ||
| 697 | /* It might be nice to do something with errors here. */ | 700 | /* It might be nice to do something with errors here. */ |
| 698 | internal_condition_case (invoke_thread_function, Qt, do_nothing); | 701 | internal_condition_case (invoke_thread_function, Qt, record_thread_error); |
| 699 | 702 | ||
| 700 | update_processes_for_thread_death (Fcurrent_thread ()); | 703 | update_processes_for_thread_death (Fcurrent_thread ()); |
| 701 | 704 | ||
| @@ -944,6 +947,13 @@ DEFUN ("all-threads", Fall_threads, Sall_threads, 0, 0, 0, | |||
| 944 | return result; | 947 | return result; |
| 945 | } | 948 | } |
| 946 | 949 | ||
| 950 | DEFUN ("thread-last-error", Fthread_last_error, Sthread_last_error, 0, 0, 0, | ||
| 951 | doc: /* Return the last error form recorded by a dying thread. */) | ||
| 952 | (void) | ||
| 953 | { | ||
| 954 | return last_thread_error; | ||
| 955 | } | ||
| 956 | |||
| 947 | 957 | ||
| 948 | 958 | ||
| 949 | bool | 959 | bool |
| @@ -1028,6 +1038,10 @@ syms_of_threads (void) | |||
| 1028 | defsubr (&Scondition_notify); | 1038 | defsubr (&Scondition_notify); |
| 1029 | defsubr (&Scondition_mutex); | 1039 | defsubr (&Scondition_mutex); |
| 1030 | defsubr (&Scondition_name); | 1040 | defsubr (&Scondition_name); |
| 1041 | defsubr (&Sthread_last_error); | ||
| 1042 | |||
| 1043 | staticpro (&last_thread_error); | ||
| 1044 | last_thread_error = Qnil; | ||
| 1031 | } | 1045 | } |
| 1032 | 1046 | ||
| 1033 | DEFSYM (Qthreadp, "threadp"); | 1047 | DEFSYM (Qthreadp, "threadp"); |