aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTom Tromey2012-08-17 07:51:19 -0600
committerTom Tromey2012-08-17 07:51:19 -0600
commitf52cfea0dcea4ae9599d4a775901ca06a0517f56 (patch)
tree3b07811f073f6d07cb23a4d19ca2606d8b5455c1 /src
parentabb9e9d865e156bb7ba28063a40a1e54608143b8 (diff)
downloademacs-f52cfea0dcea4ae9599d4a775901ca06a0517f56.tar.gz
emacs-f52cfea0dcea4ae9599d4a775901ca06a0517f56.zip
write docstrings for the thread functions
Diffstat (limited to 'src')
-rw-r--r--src/thread.c80
1 files changed, 54 insertions, 26 deletions
diff --git a/src/thread.c b/src/thread.c
index e492c576793..e8e43c5e402 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -37,7 +37,15 @@ Lisp_Object Qthreadp, Qmutexp;
37 37
38 38
39DEFUN ("make-mutex", Fmake_mutex, Smake_mutex, 0, 1, 0, 39DEFUN ("make-mutex", Fmake_mutex, Smake_mutex, 0, 1, 0,
40 doc: /* FIXME */) 40 doc: /* Create a mutex.
41A mutex provides a synchronization point for threads.
42Only one thread at a time can hold a mutex. Other threads attempting
43to acquire it will block until the mutex is available.
44
45A thread can acquire a mutex any number of times.
46
47NAME, if given, is used as the name of the mutex. The name is
48informational only. */)
41 (Lisp_Object name) 49 (Lisp_Object name)
42{ 50{
43 struct Lisp_Mutex *mutex; 51 struct Lisp_Mutex *mutex;
@@ -71,18 +79,24 @@ do_unwind_mutex_lock (Lisp_Object ignore)
71} 79}
72 80
73DEFUN ("mutex-lock", Fmutex_lock, Smutex_lock, 1, 1, 0, 81DEFUN ("mutex-lock", Fmutex_lock, Smutex_lock, 1, 1, 0,
74 doc: /* FIXME */) 82 doc: /* Acquire a mutex.
75 (Lisp_Object obj) 83If the current thread already owns MUTEX, increment the count and
76{ 84return.
77 struct Lisp_Mutex *mutex; 85Otherwise, if no thread owns MUTEX, make the current thread own it.
86Otherwise, block until MUTEX is available, or until the current thread
87is signalled using `thread-signal'.
88Note that calls to `mutex-lock' and `mutex-unlock' must be paired. */)
89 (Lisp_Object mutex)
90{
91 struct Lisp_Mutex *lmutex;
78 ptrdiff_t count = SPECPDL_INDEX (); 92 ptrdiff_t count = SPECPDL_INDEX ();
79 93
80 CHECK_MUTEX (obj); 94 CHECK_MUTEX (mutex);
81 mutex = XMUTEX (obj); 95 lmutex = XMUTEX (mutex);
82 96
83 current_thread->event_object = obj; 97 current_thread->event_object = mutex;
84 record_unwind_protect (do_unwind_mutex_lock, Qnil); 98 record_unwind_protect (do_unwind_mutex_lock, Qnil);
85 flush_stack_call_func (mutex_lock_callback, mutex); 99 flush_stack_call_func (mutex_lock_callback, lmutex);
86 return unbind_to (count, Qnil); 100 return unbind_to (count, Qnil);
87} 101}
88 102
@@ -96,28 +110,32 @@ mutex_unlock_callback (void *arg)
96} 110}
97 111
98DEFUN ("mutex-unlock", Fmutex_unlock, Smutex_unlock, 1, 1, 0, 112DEFUN ("mutex-unlock", Fmutex_unlock, Smutex_unlock, 1, 1, 0,
99 doc: /* FIXME */) 113 doc: /* Release the mutex.
100 (Lisp_Object obj) 114If this thread does not own MUTEX, signal an error.
115Otherwise, decrement the mutex's count. If the count is zero,
116release MUTEX. */)
117 (Lisp_Object mutex)
101{ 118{
102 struct Lisp_Mutex *mutex; 119 struct Lisp_Mutex *lmutex;
103 120
104 CHECK_MUTEX (obj); 121 CHECK_MUTEX (mutex);
105 mutex = XMUTEX (obj); 122 lmutex = XMUTEX (mutex);
106 123
107 flush_stack_call_func (mutex_unlock_callback, mutex); 124 flush_stack_call_func (mutex_unlock_callback, lmutex);
108 return Qnil; 125 return Qnil;
109} 126}
110 127
111DEFUN ("mutex-name", Fmutex_name, Smutex_name, 1, 1, 0, 128DEFUN ("mutex-name", Fmutex_name, Smutex_name, 1, 1, 0,
112 doc: /* FIXME */) 129 doc: /* Return the name of MUTEX.
113 (Lisp_Object obj) 130If no name was given when MUTEX was created, return nil. */)
131 (Lisp_Object mutex)
114{ 132{
115 struct Lisp_Mutex *mutex; 133 struct Lisp_Mutex *lmutex;
116 134
117 CHECK_MUTEX (obj); 135 CHECK_MUTEX (mutex);
118 mutex = XMUTEX (obj); 136 lmutex = XMUTEX (mutex);
119 137
120 return mutex->name; 138 return lmutex->name;
121} 139}
122 140
123void 141void
@@ -472,7 +490,11 @@ thread_signal_callback (void *arg)
472} 490}
473 491
474DEFUN ("thread-signal", Fthread_signal, Sthread_signal, 3, 3, 0, 492DEFUN ("thread-signal", Fthread_signal, Sthread_signal, 3, 3, 0,
475 doc: /* FIXME */) 493 doc: /* Signal an error in a thread.
494This acts like `signal', but arranges for the signal to be raised
495in THREAD. If THREAD is the current thread, acts just like `signal'.
496This will interrupt a blocked call to `mutex-lock' or`thread-join' in
497the target thread. */)
476 (Lisp_Object thread, Lisp_Object error_symbol, Lisp_Object data) 498 (Lisp_Object thread, Lisp_Object error_symbol, Lisp_Object data)
477{ 499{
478 struct thread_state *tstate; 500 struct thread_state *tstate;
@@ -495,7 +517,7 @@ DEFUN ("thread-signal", Fthread_signal, Sthread_signal, 3, 3, 0,
495} 517}
496 518
497DEFUN ("thread-alive-p", Fthread_alive_p, Sthread_alive_p, 1, 1, 0, 519DEFUN ("thread-alive-p", Fthread_alive_p, Sthread_alive_p, 1, 1, 0,
498 doc: /* FIXME */) 520 doc: /* Return t if THREAD is alive, or nil if it has exited. */)
499 (Lisp_Object thread) 521 (Lisp_Object thread)
500{ 522{
501 struct thread_state *tstate; 523 struct thread_state *tstate;
@@ -509,7 +531,11 @@ DEFUN ("thread-alive-p", Fthread_alive_p, Sthread_alive_p, 1, 1, 0,
509} 531}
510 532
511DEFUN ("thread-blocker", Fthread_blocker, Sthread_blocker, 1, 1, 0, 533DEFUN ("thread-blocker", Fthread_blocker, Sthread_blocker, 1, 1, 0,
512 doc: /* FIXME */) 534 doc: /* Return the object that THREAD is blocking on.
535If THREAD is blocked in `thread-join' on a second thread, return that
536thread.
537If THREAD is blocked in `mutex-lock', return the mutex.
538Otherwise, if THREAD is not blocked, return nil. */)
513 (Lisp_Object thread) 539 (Lisp_Object thread)
514{ 540{
515 struct thread_state *tstate; 541 struct thread_state *tstate;
@@ -539,7 +565,9 @@ thread_join_callback (void *arg)
539} 565}
540 566
541DEFUN ("thread-join", Fthread_join, Sthread_join, 1, 1, 0, 567DEFUN ("thread-join", Fthread_join, Sthread_join, 1, 1, 0,
542 doc: /* FIXME */) 568 doc: /* Wait for a thread to exit.
569This blocks the current thread until THREAD exits.
570It is an error for a thread to try to join itself. */)
543 (Lisp_Object thread) 571 (Lisp_Object thread)
544{ 572{
545 struct thread_state *tstate; 573 struct thread_state *tstate;
@@ -555,7 +583,7 @@ DEFUN ("thread-join", Fthread_join, Sthread_join, 1, 1, 0,
555 583
556DEFUN ("all-threads", Fall_threads, Sall_threads, 0, 0, 0, 584DEFUN ("all-threads", Fall_threads, Sall_threads, 0, 0, 0,
557 doc: /* Return a list of all threads. */) 585 doc: /* Return a list of all threads. */)
558 (void) 586 (void)
559{ 587{
560 Lisp_Object result = Qnil; 588 Lisp_Object result = Qnil;
561 struct thread_state *iter; 589 struct thread_state *iter;