1 |
/* Copyright (C) 1995,1996,1997,1998,2000,2001 Free Software Foundation, Inc. |
/* Copyright (C) 1995,1996,1997,1998,2000,2001, 2002 Free Software Foundation, Inc. |
2 |
* |
* |
3 |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
4 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
66 |
{ |
{ |
67 |
coop_init(); |
coop_init(); |
68 |
|
|
69 |
|
scm_tc16_thread = scm_make_smob_type ("thread", 0); |
70 |
|
scm_tc16_mutex = scm_make_smob_type ("mutex", sizeof (coop_m)); |
71 |
|
scm_tc16_condvar = scm_make_smob_type ("condition-variable", |
72 |
|
sizeof (coop_c)); |
73 |
|
|
74 |
scm_thread_count = 1; |
scm_thread_count = 1; |
75 |
|
|
76 |
#ifndef GUILE_PTHREAD_COMPAT |
#ifndef GUILE_PTHREAD_COMPAT |
423 |
if (thread_data) |
if (thread_data) |
424 |
/* The thread is still alive */ |
/* The thread is still alive */ |
425 |
coop_join (thread_data); |
coop_join (thread_data); |
426 |
|
/* XXX - return real result. */ |
427 |
return SCM_BOOL_T; |
return SCM_BOOL_T; |
428 |
} |
} |
429 |
#undef FUNC_NAME |
#undef FUNC_NAME |
430 |
|
|
431 |
|
int |
432 |
|
scm_c_thread_exited_p (SCM thread) |
433 |
|
#define FUNC_NAME s_scm_thread_exited_p |
434 |
|
{ |
435 |
|
SCM_VALIDATE_THREAD (1, thread); |
436 |
|
return SCM_THREAD_DATA (thread) != NULL; |
437 |
|
} |
438 |
|
#undef FUNC_NAME |
439 |
|
|
440 |
SCM |
SCM |
441 |
scm_yield (void) |
scm_yield (void) |
442 |
{ |
{ |
472 |
} |
} |
473 |
|
|
474 |
SCM |
SCM |
475 |
|
scm_try_mutex (SCM m) |
476 |
|
{ |
477 |
|
SCM_ASSERT (SCM_MUTEXP (m), m, SCM_ARG1, s_lock_mutex); |
478 |
|
return SCM_BOOL (coop_mutex_trylock (SCM_MUTEX_DATA (m))); |
479 |
|
} |
480 |
|
|
481 |
|
SCM |
482 |
scm_unlock_mutex (SCM m) |
scm_unlock_mutex (SCM m) |
483 |
{ |
{ |
484 |
SCM_ASSERT (SCM_MUTEXP (m), m, SCM_ARG1, s_unlock_mutex); |
SCM_ASSERT (SCM_MUTEXP (m), m, SCM_ARG1, s_unlock_mutex); |
500 |
} |
} |
501 |
|
|
502 |
SCM |
SCM |
503 |
scm_wait_condition_variable (SCM c, SCM m) |
scm_timed_wait_condition_variable (SCM c, SCM m, SCM t) |
504 |
|
#define FUNC_NAME s_wait_condition_variable |
505 |
{ |
{ |
506 |
|
coop_c *cv; |
507 |
|
coop_m *mx; |
508 |
|
struct timespec waittime; |
509 |
|
|
510 |
SCM_ASSERT (SCM_CONDVARP (c), |
SCM_ASSERT (SCM_CONDVARP (c), |
511 |
c, |
c, |
512 |
SCM_ARG1, |
SCM_ARG1, |
515 |
m, |
m, |
516 |
SCM_ARG2, |
SCM_ARG2, |
517 |
s_wait_condition_variable); |
s_wait_condition_variable); |
518 |
coop_condition_variable_wait_mutex (SCM_CONDVAR_DATA (c), |
|
519 |
SCM_MUTEX_DATA (m)); |
cv = SCM_CONDVAR_DATA (c); |
520 |
return SCM_BOOL_T; |
mx = SCM_MUTEX_DATA (m); |
521 |
|
|
522 |
|
if (!SCM_UNBNDP (t)) |
523 |
|
{ |
524 |
|
if (SCM_CONSP (t)) |
525 |
|
{ |
526 |
|
SCM_VALIDATE_UINT_COPY (3, SCM_CAR(t), waittime.tv_sec); |
527 |
|
SCM_VALIDATE_UINT_COPY (3, SCM_CDR(t), waittime.tv_nsec); |
528 |
|
waittime.tv_nsec *= 1000; |
529 |
|
} |
530 |
|
else |
531 |
|
{ |
532 |
|
SCM_VALIDATE_UINT_COPY (3, t, waittime.tv_sec); |
533 |
|
waittime.tv_nsec = 0; |
534 |
|
} |
535 |
|
return SCM_BOOL( |
536 |
|
coop_condition_variable_timed_wait_mutex (cv, mx, &waittime)); |
537 |
|
} |
538 |
|
else |
539 |
|
{ |
540 |
|
coop_condition_variable_wait_mutex (cv, mx); |
541 |
|
return SCM_BOOL_T; |
542 |
|
} |
543 |
} |
} |
544 |
|
#undef FUNC_NAME |
545 |
|
|
546 |
SCM |
SCM |
547 |
scm_signal_condition_variable (SCM c) |
scm_signal_condition_variable (SCM c) |
554 |
return SCM_BOOL_T; |
return SCM_BOOL_T; |
555 |
} |
} |
556 |
|
|
557 |
|
SCM |
558 |
|
scm_broadcast_condition_variable (SCM c) |
559 |
|
{ |
560 |
|
SCM_ASSERT (SCM_CONDVARP (c), |
561 |
|
c, |
562 |
|
SCM_ARG1, |
563 |
|
s_broadcast_condition_variable); |
564 |
|
coop_condition_variable_broadcast (SCM_CONDVAR_DATA (c)); |
565 |
|
return SCM_BOOL_T; |
566 |
|
} |
567 |
|
|
568 |
/* |
/* |
569 |
Local Variables: |
Local Variables: |
570 |
c-file-style: "gnu" |
c-file-style: "gnu" |