From 7648503cd894549874ff13f7ed94a4708cf50f0d Mon Sep 17 00:00:00 2001 From: Richard Braun Date: Mon, 3 Sep 2012 15:47:25 +0200 Subject: Remove condition implications There is no equivalent for these functions in libpthread. Instead of adding them as non standard extensions, rework their use. * console-client/kbd-repeat.c (kbd_repeat_key): Wake threads waiting on select_alert. (kbd_setrepeater): Remove call to condition_implies. console-client/pc-mouse.c (repeat_event): Wake threads waiting on select_alert. (setrepeater): Remove call to condition_implies. * libpipe/pipe.c (pipe_create): Initialize the `pending_selects' member. (pipe_add_select_cond): New function. (pipe_remove_select_cond): Likewise. (pipe_select_cond_broadcast): Likewise. (_pipe_no_readers): Wake threads waiting on a pending select. (_pipe_no_writers): Likewise. (pipe_send): Likewise. (pipe_recv): Likewise. (pipe_pair_select): Replace condition implications by installing a pending select on the pair of pipes. * libpipe/pipe.h (struct pipe_select_cond): New type. (struct pipe): New member `pending_selects'. * pfinet/tunnel.c (tunnel_xmit): Wake threads waiting on tdev->select_alert. (setup_tunnel_device): Remove call to condition_implies. * term/devio.c (device_write_reply_inband): Wake threads waiting on select_alert. * term/hurdio.c (hurdio_writer_loop): Likewise. * term/main.c (main): Remove calls to condition_implies. * term/ptyio.c (ptyio_init): Remove calls to condition_implies, initialize pty_select_alert. (wake_reader): Wake threads waiting on pty_select_wakeup. * term/term.h (pty_select_alert): New variable. (clear_queue): Wake threads waiting on select_alert and, if acting on the input queue, pty_select_alert, unless it's NULL. (dequeue_quote): Likewise. (enqueue_internal): Likewise. (queue_erase): Likewise. * trans/streamio.c (clear_buffer): Wake threads waiting on select_alert. (buffer_read): Likewise. (buffer_write): Likewise. (device_read_reply_inband): Likewise. (device_write_reply_inband): Likewise. (main): Remove calls to condition_implies. --- term/devio.c | 1 + term/hurdio.c | 1 + term/main.c | 2 -- term/ptyio.c | 4 ++-- term/term.h | 25 ++++++++++++++++++++++--- 5 files changed, 26 insertions(+), 7 deletions(-) (limited to 'term') diff --git a/term/devio.c b/term/devio.c index 38eb996c..8aa960b9 100644 --- a/term/devio.c +++ b/term/devio.c @@ -323,6 +323,7 @@ device_write_reply_inband (mach_port_t replypt, { npending_output = 0; condition_broadcast (outputq->wait); + condition_broadcast (&select_alert); } else { diff --git a/term/hurdio.c b/term/hurdio.c index ef34740b..b1d0c944 100644 --- a/term/hurdio.c +++ b/term/hurdio.c @@ -286,6 +286,7 @@ hurdio_writer_loop (any_t arg) { npending_output = 0; condition_broadcast (outputq->wait); + condition_broadcast (&select_alert); } else { diff --git a/term/main.c b/term/main.c index 405e7cd8..e15fee53 100644 --- a/term/main.c +++ b/term/main.c @@ -443,8 +443,6 @@ main (int argc, char **argv) condition_init (&carrier_alert); condition_init (&select_alert); - condition_implies (inputq->wait, &select_alert); - condition_implies (outputq->wait, &select_alert); /* Launch. */ ports_manage_port_operations_multithread (term_bucket, demuxer, 0, 0, 0); diff --git a/term/ptyio.c b/term/ptyio.c index 9c1509ff..b02cda3f 100644 --- a/term/ptyio.c +++ b/term/ptyio.c @@ -58,8 +58,7 @@ static int nptyperopens = 0; static error_t ptyio_init (void) { - condition_implies (inputq->wait, &pty_select_wakeup); - condition_implies (&pty_read_wakeup, &pty_select_wakeup); + pty_select_alert = &pty_select_wakeup; return 0; } @@ -132,6 +131,7 @@ wake_reader () { pty_read_blocked = 0; condition_broadcast (&pty_read_wakeup); + condition_broadcast (&pty_select_wakeup); } } diff --git a/term/term.h b/term/term.h index 81d0efee..2df20337 100644 --- a/term/term.h +++ b/term/term.h @@ -103,6 +103,9 @@ struct condition carrier_alert; /* Wakeup for select */ struct condition select_alert; +/* Wakeup for pty select, if not null */ +struct condition *pty_select_alert; + /* Bucket for all our ports. */ struct port_bucket *term_bucket; @@ -225,6 +228,9 @@ clear_queue (struct queue *q) q->susp = 0; q->cs = q->ce = q->array; condition_broadcast (q->wait); + condition_broadcast (&select_alert); + if (q == inputq && pty_select_alert != NULL) + condition_broadcast (pty_select_alert); } #endif /* Use extern inlines. */ @@ -249,7 +255,10 @@ dequeue_quote (struct queue *q) if (beep) { condition_broadcast (q->wait); - if (q == outputq) + condition_broadcast (&select_alert); + if (q == inputq && pty_select_alert != NULL) + condition_broadcast (pty_select_alert); + else if (q == outputq) call_asyncs (O_WRITE); } return *q->cs++; @@ -280,8 +289,13 @@ enqueue_internal (struct queue **qp, quoted_char c) if (qsize (q) == 1) { condition_broadcast (q->wait); + condition_broadcast (&select_alert); if (q == inputq) - call_asyncs (O_READ); + { + if (pty_select_alert != NULL) + condition_broadcast (pty_select_alert); + call_asyncs (O_READ); + } } if (!q->susp && (qsize (q) > q->hiwat)) @@ -334,7 +348,12 @@ queue_erase (struct queue *q) if (qsize (q) == 0) beep = 1; if (beep) - condition_broadcast (q->wait); + { + condition_broadcast (q->wait); + condition_broadcast (&select_alert); + if (q == inputq && pty_select_alert != NULL) + condition_broadcast (pty_select_alert); + } return answer; } #endif /* Use extern inlines. */ -- cgit v1.2.3