[rtems commit] console: Be fair in simple console read

Sebastian Huber sebh at rtems.org
Thu Oct 18 05:23:47 UTC 2018


Module:    rtems
Branch:    master
Commit:    c980eaff1d10cb169ba22ce00e75dae318df21f1
Changeset: http://git.rtems.org/rtems/commit/?id=c980eaff1d10cb169ba22ce00e75dae318df21f1

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue Oct 16 14:35:12 2018 +0200

console: Be fair in simple console read

Wait for one tick in case no character is available after a call to
getchark().  Otherwise the system is constantly busy within an input
loop (for example in the RTEMS shell).  The polled Termios driver uses
the same approach.

---

 cpukit/libcsupport/src/consolesimpleread.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/cpukit/libcsupport/src/consolesimpleread.c b/cpukit/libcsupport/src/consolesimpleread.c
index a796e43..737b441 100644
--- a/cpukit/libcsupport/src/consolesimpleread.c
+++ b/cpukit/libcsupport/src/consolesimpleread.c
@@ -33,9 +33,14 @@ ssize_t _Console_simple_Read(
   for ( i = 0; i < n; ++i ) {
     int c;
 
-    do {
+    while ( true ) {
       c = getchark();
-    } while (c == -1);
+      if ( c != -1 ) {
+        break;
+      }
+
+      (void) rtems_task_wake_after( 1 );
+    }
 
     buf[ i ] = (char) c;
   }




More information about the vc mailing list