From 074540d65b2d77576931aeda46a77a7d3b1f80b8 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sat, 24 Jan 2015 23:39:03 +0000 Subject: [PATCH] tty: allow -1 return from waitready to indicate the driver knows sleeping is good --- Kernel/tty.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Kernel/tty.c b/Kernel/tty.c index 97624981..190b3605 100644 --- a/Kernel/tty.c +++ b/Kernel/tty.c @@ -374,6 +374,7 @@ void tty_erase(uint8_t minor) void tty_putc_wait(uint8_t minor, unsigned char c) { + uint8_t t; #ifdef CONFIG_DEV_PTY if (minor >= PTY_OFFSET) ptty_putc_wait(minor, c); @@ -381,10 +382,13 @@ void tty_putc_wait(uint8_t minor, unsigned char c) #endif /* For slower platforms it's not worth the task switching and return costs versus waiting a bit. A box with tx interrupts and sufficient - performance can buffer or sleep in in tty_putc instead. */ + performance can buffer or sleep in in tty_putc instead. + + The driver should return 1 - send bytes, 0 - spinning may be useful, + -1 - blocked, don't spin (eg flow controlled) */ if (!udata.u_ininterrupt) { - while (!tty_writeready(minor)) - if (need_resched()) + while ((t = tty_writeready(minor)) != 1) + if (t || need_resched()) psleep(&ttydata[minor]); } tty_putc(minor, c); -- 2.34.1