1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00

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.
This commit is contained in:
Andy Wingo 2016-12-29 18:46:16 +01:00
parent 0ce8a9a5e0
commit a0656ad4cf
4 changed files with 142 additions and 56 deletions

View file

@ -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;
}
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);
if (scm_i_prepare_to_wait_on_cond (t, mutex, &t->sleep_cond))
return EINTR;
/* 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);
}
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);
/* 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))
{