diff options
author | Andy Wingo <wingo@pobox.com> | 2016-12-29 18:46:16 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2016-12-29 18:46:16 +0100 |
commit | a0656ad4cf976b3845e9b9663a90b46b4cf9fc5a (patch) | |
tree | 22e621b5b32acb84fcbd82b1b7ff7d7f9e303740 /libguile/threads.c | |
parent | 0ce8a9a5e01d3a12d83fea85968e1abb602c9298 (diff) | |
download | guile-a0656ad4cf976b3845e9b9663a90b46b4cf9fc5a.tar.gz |
New interfaces to help wait on fd/cond
* libguile/async.h:
* libguile/async.c (struct scm_thread_wake_data): Include the cond to
signal. Be a union and include a tag.
(scm_i_prepare_to_wait): Rename from scm_i_setup_sleep and take wake
data directly. Also call scm_i_wait_finished as appropriate.
(scm_i_wait_finished): Rename from scm_i_reset_sleep.
(scm_i_prepare_to_wait_on_fd, scm_c_prepare_to_wait_on_fd):
(scm_i_prepare_to_wait_on_cond, scm_c_prepare_to_wait_on_cond): New
functions.
(scm_c_wait_finished): New function.
(scm_system_async_mark_for_thread): Adapt to wake data change.
* libguile/threads.c (block_self, scm_std_select): Adapt to async
interface changes.
* doc/ref/api-scheduling.texi (Asyncs): Doc new public interfaces.
Diffstat (limited to 'libguile/threads.c')
-rw-r--r-- | libguile/threads.c | 46 |
1 files changed, 19 insertions, 27 deletions
diff --git a/libguile/threads.c b/libguile/threads.c index 91b18b43a..48a91e84f 100644 --- a/libguile/threads.c +++ b/libguile/threads.c @@ -307,29 +307,24 @@ block_self (SCM queue, scm_i_pthread_mutex_t *mutex, SCM q_handle; int err; - if (scm_i_setup_sleep (t, mutex, -1)) - { - scm_i_reset_sleep (t); - err = EINTR; - } + if (scm_i_prepare_to_wait_on_cond (t, mutex, &t->sleep_cond)) + return EINTR; + + t->block_asyncs++; + q_handle = enqueue (queue, t->handle); + if (waittime == NULL) + err = scm_i_scm_pthread_cond_wait (&t->sleep_cond, mutex); else - { - t->block_asyncs++; - q_handle = enqueue (queue, t->handle); - if (waittime == NULL) - err = scm_i_scm_pthread_cond_wait (&t->sleep_cond, mutex); - else - err = scm_i_scm_pthread_cond_timedwait (&t->sleep_cond, mutex, waittime); + err = scm_i_scm_pthread_cond_timedwait (&t->sleep_cond, mutex, waittime); - /* When we are still on QUEUE, we have been interrupted. We - report this only when no other error (such as a timeout) has - happened above. - */ - if (remqueue (queue, q_handle) && err == 0) - err = EINTR; - t->block_asyncs--; - scm_i_reset_sleep (t); - } + /* When we are still on QUEUE, we have been interrupted. We + report this only when no other error (such as a timeout) has + happened above. + */ + if (remqueue (queue, q_handle) && err == 0) + err = EINTR; + t->block_asyncs--; + scm_i_wait_finished (t); return err; } @@ -1479,11 +1474,8 @@ scm_std_select (int nfds, readfds = &my_readfds; } - while (scm_i_setup_sleep (t, NULL, t->sleep_pipe[1])) - { - scm_i_reset_sleep (t); - SCM_TICK; - } + while (scm_i_prepare_to_wait_on_fd (t, t->sleep_pipe[1])) + SCM_TICK; wakeup_fd = t->sleep_pipe[0]; FD_SET (wakeup_fd, readfds); @@ -1502,7 +1494,7 @@ scm_std_select (int nfds, res = args.result; eno = args.errno_value; - scm_i_reset_sleep (t); + scm_i_wait_finished (t); if (res > 0 && FD_ISSET (wakeup_fd, readfds)) { |