/[guile]/guile/guile-core/libguile/threads.c
ViewVC logotype

Diff of /guile/guile-core/libguile/threads.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.26 by mvo, Wed Oct 16 16:25:45 2002 UTC revision 1.27 by mvo, Sun Oct 27 20:12:37 2002 UTC
# Line 60  Line 60 
60      * second #inclusion      * second #inclusion
61  */  */
62    
63    #include <errno.h>
64    
65  #include "libguile/_scm.h"  #include "libguile/_scm.h"
66  #include "libguile/dynwind.h"  #include "libguile/dynwind.h"
67  #include "libguile/smob.h"  #include "libguile/smob.h"
# Line 109  SCM_REGISTER_PROC(s_join_thread, "join-t Line 111  SCM_REGISTER_PROC(s_join_thread, "join-t
111  terminates, unless the target @var{thread} has already terminated.  terminates, unless the target @var{thread} has already terminated.
112  */  */
113    
114    SCM_DEFINE (scm_thread_exited_p, "thread-exited?", 1, 0, 0,
115                (SCM thread),
116                "Return @code{#t} iff @var{thread} has exited.\n")
117    #define FUNC_NAME s_scm_thread_exited_p
118    {
119      return SCM_BOOL (scm_c_thread_exited_p (thread));
120    }
121    #undef FUNC_NAME
122    
123  SCM_REGISTER_PROC(s_make_mutex, "make-mutex", 0, 0, 0, scm_make_mutex);  SCM_REGISTER_PROC(s_make_mutex, "make-mutex", 0, 0, 0, scm_make_mutex);
124  /* Create a new mutex object. */  /* Create a new mutex object. */
125    
# Line 117  SCM_REGISTER_PROC(s_lock_mutex, "lock-mu Line 128  SCM_REGISTER_PROC(s_lock_mutex, "lock-mu
128  blocks until the mutex becomes available. The function returns when  blocks until the mutex becomes available. The function returns when
129  the calling thread owns the lock on @var{mutex}. */  the calling thread owns the lock on @var{mutex}. */
130    
131    SCM_REGISTER_PROC(s_try_mutex, "try-mutex", 1, 0, 0, scm_try_mutex);
132    /* Try to lock @var{mutex}. If the mutex is already locked by someone
133    else, return @code{#f}.  Else lock the mutex and return @code{#t}. */
134    
135  SCM_REGISTER_PROC(s_unlock_mutex, "unlock-mutex", 1, 0, 0, scm_unlock_mutex);  SCM_REGISTER_PROC(s_unlock_mutex, "unlock-mutex", 1, 0, 0, scm_unlock_mutex);
136  /* Unlocks @var{mutex} if the calling thread owns the lock on @var{mutex}.  /* Unlocks @var{mutex} if the calling thread owns the lock on @var{mutex}.
137  Calling unlock-mutex on a mutex not owned by the current thread results  Calling unlock-mutex on a mutex not owned by the current thread results
# Line 125  blocked on @var{mutex} is awakened and g Line 140  blocked on @var{mutex} is awakened and g
140    
141  SCM_REGISTER_PROC(s_make_condition_variable, "make-condition-variable", 0, 0, 0, scm_make_condition_variable);  SCM_REGISTER_PROC(s_make_condition_variable, "make-condition-variable", 0, 0, 0, scm_make_condition_variable);
142    
143  SCM_REGISTER_PROC(s_wait_condition_variable, "wait-condition-variable", 2, 0, 0, scm_wait_condition_variable);  SCM_REGISTER_PROC(s_wait_condition_variable, "wait-condition-variable", 2, 1, 0, scm_timed_wait_condition_variable);
144    
145  SCM_REGISTER_PROC(s_signal_condition_variable, "signal-condition-variable", 1, 0, 0, scm_signal_condition_variable);  SCM_REGISTER_PROC(s_signal_condition_variable, "signal-condition-variable", 1, 0, 0, scm_signal_condition_variable);
146    
147    SCM_REGISTER_PROC(s_broadcast_condition_variable, "broadcast-condition-variable", 1, 0, 0, scm_broadcast_condition_variable);
148    
149    SCM
150    scm_wait_condition_variable (SCM c, SCM m)
151    {
152      return scm_timed_wait_condition_variable (c, m, SCM_UNDEFINED);
153    }
154    
155    
156    
157  #ifdef USE_COOP_THREADS  #ifdef USE_COOP_THREADS
158  #include "libguile/coop-threads.c"  #include "libguile/coop-threads.c"
159  #else  #else
160    #ifdef USE_COPT_THREADS
161    #include "libguile/coop-pthreads.c"
162    #else
163  #include "libguile/null-threads.c"  #include "libguile/null-threads.c"
164  #endif  #endif
165    #endif
166    
167    
168    
169    #if (SCM_ENABLE_DEPRECATED == 1)
170    
171    SCM_API int
172    scm_mutex_init (scm_t_mutex *m)
173    {
174      scm_gc_protect_object (m->m = scm_make_mutex ());
175      return 0;
176    }
177    
178    SCM_API int
179    scm_mutex_lock (scm_t_mutex *m)
180    {
181      scm_lock_mutex (m->m);
182      return 0;
183    }
184    
185    SCM_API int
186    scm_mutex_trylock (scm_t_mutex *m)
187    {
188      return SCM_FALSEP (scm_try_mutex (m->m))? EBUSY : 0;
189    }
190    
191    SCM_API int
192    scm_mutex_unlock (scm_t_mutex *m)
193    {
194      scm_unlock_mutex (m->m);
195      return 0;
196    }
197    
198    SCM_API int
199    scm_mutex_destroy (scm_t_mutex *m)
200    {
201      scm_gc_unprotect_object (m->m);
202      return 0;
203    }
204    
205    SCM_API int
206    scm_cond_init (scm_t_cond *c)
207    {
208      scm_gc_protect_object (c->c = scm_make_condition_variable ());
209      return 0;
210    }
211    
212    SCM_API int
213    scm_cond_wait (scm_t_cond *c, scm_t_mutex *m)
214    {
215      scm_wait_condition_variable (c->c, m->m);
216      return 0;
217    }
218    
219    SCM_API int
220    scm_cond_timedwait (scm_t_cond *c, scm_t_mutex *m,
221                        const struct timespec *t)
222    {
223      return !SCM_FALSEP (scm_timed_wait_condition_variable (
224        c->c, m->m, scm_cons (scm_long2num (t->tv_sec),
225                              scm_long2num (t->tv_nsec/1000))));
226    }
227    
228    SCM_API int
229    scm_cond_signal (scm_t_cond *c)
230    {
231      scm_signal_condition_variable (c->c);
232      return 0;
233    }
234    
235    SCM_API int
236    scm_cond_destroy (scm_t_cond *c)
237    {
238      scm_gc_unprotect_object (c->c);
239      return 0;
240    }
241    
242    #endif
243    
244    
245    
246  void  void
247  scm_init_threads (SCM_STACKITEM *i)  scm_init_threads (SCM_STACKITEM *i)
248  {  {
   scm_tc16_thread = scm_make_smob_type ("thread", 0);  
   scm_tc16_mutex = scm_make_smob_type ("mutex", sizeof (scm_t_mutex));  
   scm_tc16_condvar = scm_make_smob_type ("condition-variable",  
                                          sizeof (scm_t_cond));  
                                           
 #include "libguile/threads.x"  
249    /* Initialize implementation specific details of the threads support */    /* Initialize implementation specific details of the threads support */
250    scm_threads_init (i);    scm_threads_init (i);
251  }  }
252    
253    void
254    scm_init_thread_procs ()
255    {
256    #include "libguile/threads.x"
257    }
258    
259  /*  /*
260    Local Variables:    Local Variables:
261    c-file-style: "gnu"    c-file-style: "gnu"

Legend:
Removed from v.1.26  
changed lines
  Added in v.1.27

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26