From 19bc43020d6afa2265447e2dad43ad617812ab38 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 10 Dec 2016 10:49:39 +0200 Subject: Documentation and commentary improvements * src/lisp.h: * src/regex.c: * src/xgselect.c (xg_select): Improve commentary and formatting. * doc/lispref/objects.texi (Thread Type, Mutex Type) (Condition Variable Type): New subsections. (Type Predicates): Add thread-related predicates. * doc/lispref/objects.texi (Editing Types): * doc/lispref/elisp.texi (Top): Update higher-level menus. --- src/lisp.h | 2 ++ src/regex.c | 1 + src/xgselect.c | 3 +++ 3 files changed, 6 insertions(+) (limited to 'src') diff --git a/src/lisp.h b/src/lisp.h index 72ea50d5f27..3c7c3dde904 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -845,6 +845,7 @@ enum pvec_type PVEC_THREAD, PVEC_MUTEX, PVEC_CONDVAR, + /* These should be last, check internal_equal to see why. */ PVEC_COMPILED, PVEC_CHAR_TABLE, @@ -3229,6 +3230,7 @@ union specbinding } bt; }; +/* These 3 are defined as macros in thread.h. */ /* extern union specbinding *specpdl; */ /* extern union specbinding *specpdl_ptr; */ /* extern ptrdiff_t specpdl_size; */ diff --git a/src/regex.c b/src/regex.c index e7231d3882b..f1686cf700c 100644 --- a/src/regex.c +++ b/src/regex.c @@ -1140,6 +1140,7 @@ print_double_string (re_char *where, re_char *string1, ssize_t size1, #endif /* not DEBUG */ #ifndef emacs + /* Set by `re_set_syntax' to the current regexp syntax to recognize. Can also be assigned to arbitrarily: each pattern buffer stores its own syntax, so it can be changed between regex compilations. */ diff --git a/src/xgselect.c b/src/xgselect.c index e418e1a3c4e..2f23764ae41 100644 --- a/src/xgselect.c +++ b/src/xgselect.c @@ -76,6 +76,9 @@ xg_select (int fds_lim, fd_set *rfds, fd_set *wfds, fd_set *efds, if (gfds_size < n_gfds) { + /* Avoid using SAFE_NALLOCA, as that implicitly refers to the + current thread. Using xnmalloc avoids thread-switching + problems here. */ gfds = xnmalloc (n_gfds, sizeof *gfds); must_free = 1; gfds_size = n_gfds; -- cgit v1.2.1 From e4df093e6058c4338a1ea885d44fd0be7f032b8c Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 10 Dec 2016 11:06:23 +0200 Subject: 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 . --- src/thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/thread.c b/src/thread.c index dda262984c0..b2f8561f923 100644 --- a/src/thread.c +++ b/src/thread.c @@ -540,7 +540,7 @@ mark_one_thread (struct thread_state *thread) mark_object (thread->m_last_thing_searched); - if (thread->m_saved_last_thing_searched) + if (!NILP (thread->m_saved_last_thing_searched)) mark_object (thread->m_saved_last_thing_searched); } -- cgit v1.2.1 From c364d62f89a499d22f06f63e81ec7819f51596fa Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 10 Dec 2016 11:31:11 +0200 Subject: 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. --- src/thread.c | 61 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 31 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/thread.c b/src/thread.c index b2f8561f923..ee5b82da905 100644 --- a/src/thread.c +++ b/src/thread.c @@ -301,7 +301,7 @@ finalize_one_mutex (struct Lisp_Mutex *mutex) DEFUN ("make-condition-variable", Fmake_condition_variable, Smake_condition_variable, 1, 2, 0, - doc: /* Make a condition variable. + doc: /* Make a condition variable associated with MUTEX. A condition variable provides a way for a thread to sleep while waiting for a state change. @@ -355,23 +355,23 @@ condition_wait_callback (void *arg) } DEFUN ("condition-wait", Fcondition_wait, Scondition_wait, 1, 1, 0, - doc: /* Wait for the condition variable to be notified. -CONDITION is the condition variable to wait on. + doc: /* Wait for the condition variable COND to be notified. +COND is the condition variable to wait on. -The mutex associated with CONDITION must be held when this is called. +The mutex associated with COND must be held when this is called. It is an error if it is not held. -This releases the mutex and waits for CONDITION to be notified or for +This releases the mutex and waits for COND to be notified or for this thread to be signalled with `thread-signal'. When -`condition-wait' returns, the mutex will again be locked by this -thread. */) - (Lisp_Object condition) +`condition-wait' returns, COND's mutex will again be locked by +this thread. */) + (Lisp_Object cond) { struct Lisp_CondVar *cvar; struct Lisp_Mutex *mutex; - CHECK_CONDVAR (condition); - cvar = XCONDVAR (condition); + CHECK_CONDVAR (cond); + cvar = XCONDVAR (cond); mutex = XMUTEX (cvar->mutex); if (!lisp_mutex_owned_p (&mutex->mutex)) @@ -409,24 +409,24 @@ condition_notify_callback (void *arg) } DEFUN ("condition-notify", Fcondition_notify, Scondition_notify, 1, 2, 0, - doc: /* Notify a condition variable. -This wakes a thread waiting on CONDITION. + doc: /* Notify COND, a condition variable. +This wakes a thread waiting on COND. If ALL is non-nil, all waiting threads are awoken. -The mutex associated with CONDITION must be held when this is called. +The mutex associated with COND must be held when this is called. It is an error if it is not held. -This releases the mutex when notifying CONDITION. When +This releases COND's mutex when notifying COND. When `condition-notify' returns, the mutex will again be locked by this thread. */) - (Lisp_Object condition, Lisp_Object all) + (Lisp_Object cond, Lisp_Object all) { struct Lisp_CondVar *cvar; struct Lisp_Mutex *mutex; struct notify_args args; - CHECK_CONDVAR (condition); - cvar = XCONDVAR (condition); + CHECK_CONDVAR (cond); + cvar = XCONDVAR (cond); mutex = XMUTEX (cvar->mutex); if (!lisp_mutex_owned_p (&mutex->mutex)) @@ -440,26 +440,26 @@ thread. */) } DEFUN ("condition-mutex", Fcondition_mutex, Scondition_mutex, 1, 1, 0, - doc: /* Return the mutex associated with CONDITION. */) - (Lisp_Object condition) + doc: /* Return the mutex associated with condition variable COND. */) + (Lisp_Object cond) { struct Lisp_CondVar *cvar; - CHECK_CONDVAR (condition); - cvar = XCONDVAR (condition); + CHECK_CONDVAR (cond); + cvar = XCONDVAR (cond); return cvar->mutex; } DEFUN ("condition-name", Fcondition_name, Scondition_name, 1, 1, 0, - doc: /* Return the name of CONDITION. -If no name was given when CONDITION was created, return nil. */) - (Lisp_Object condition) + doc: /* Return the name of condition variable COND. +If no name was given when COND was created, return nil. */) + (Lisp_Object cond) { struct Lisp_CondVar *cvar; - CHECK_CONDVAR (condition); - cvar = XCONDVAR (condition); + CHECK_CONDVAR (cond); + cvar = XCONDVAR (cond); return cvar->name; } @@ -678,7 +678,7 @@ finalize_one_thread (struct thread_state *state) DEFUN ("make-thread", Fmake_thread, Smake_thread, 1, 2, 0, doc: /* Start a new thread and run FUNCTION in it. When the function exits, the thread dies. -If NAME is given, it names the new thread. */) +If NAME is given, it must be a string; it names the new thread. */) (Lisp_Object function, Lisp_Object name) { sys_thread_t thr; @@ -843,8 +843,9 @@ thread_join_callback (void *arg) } DEFUN ("thread-join", Fthread_join, Sthread_join, 1, 1, 0, - doc: /* Wait for a thread to exit. -This blocks the current thread until THREAD exits. + doc: /* Wait for THREAD to exit. +This blocks the current thread until THREAD exits or until +the current thread is signaled. It is an error for a thread to try to join itself. */) (Lisp_Object thread) { @@ -863,7 +864,7 @@ It is an error for a thread to try to join itself. */) } DEFUN ("all-threads", Fall_threads, Sall_threads, 0, 0, 0, - doc: /* Return a list of all threads. */) + doc: /* Return a list of all the live threads. */) (void) { Lisp_Object result = Qnil; -- cgit v1.2.1 From 828b4560cd4a0d8cb9b7a7a3e20ff0c53ba86cfa Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 10 Dec 2016 11:42:48 +0200 Subject: Fix error messages in thread.c * src/thread.c (lisp_mutex_unlock, Fcondition_wait) (Fcondition_notify, Fthread_join): Fix error messages. --- src/thread.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/thread.c b/src/thread.c index ee5b82da905..ae2ce3dc02b 100644 --- a/src/thread.c +++ b/src/thread.c @@ -144,7 +144,7 @@ static int lisp_mutex_unlock (lisp_mutex_t *mutex) { if (mutex->owner != current_thread) - error ("blah"); + error ("Cannot unlock mutex owned by another thread"); if (--mutex->count > 0) return 0; @@ -375,7 +375,7 @@ this thread. */) mutex = XMUTEX (cvar->mutex); if (!lisp_mutex_owned_p (&mutex->mutex)) - error ("fixme"); + error ("Condition variable's mutex is not held by current thread"); flush_stack_call_func (condition_wait_callback, cvar); @@ -430,7 +430,7 @@ thread. */) mutex = XMUTEX (cvar->mutex); if (!lisp_mutex_owned_p (&mutex->mutex)) - error ("fixme"); + error ("Condition variable's mutex is not held by current thread"); args.cvar = cvar; args.all = !NILP (all); @@ -855,7 +855,7 @@ It is an error for a thread to try to join itself. */) tstate = XTHREAD (thread); if (tstate == current_thread) - error ("cannot join current thread"); + error ("Cannot join current thread"); if (thread_alive_p (tstate)) flush_stack_call_func (thread_join_callback, tstate); -- cgit v1.2.1