This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 2864ccba1e35fad114e65ac1494d66d55cecbe5b
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Tue Oct 8 16:10:52 2019 +0200

    sys/console: Add console locking on input
    
    To avoid mixing prompt and other logs console is now
    locked when input characters are processed.
---
 sys/console/full/src/console.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/sys/console/full/src/console.c b/sys/console/full/src/console.c
index c41be33..213bbf0 100644
--- a/sys/console/full/src/console.c
+++ b/sys/console/full/src/console.c
@@ -826,10 +826,14 @@ console_handle_char(uint8_t byte)
         return 0;
     }
 
+    if (console_lock(1000)) {
+        return -1;
+    }
+
     /* Handle ANSI escape mode */
     if (esc_state & ESC_ANSI) {
         handle_ansi(byte, input->line);
-        return 0;
+        goto unlock;
     }
 
     /* Handle escape mode */
@@ -845,7 +849,7 @@ console_handle_char(uint8_t byte)
             break;
         }
 
-        return 0;
+        goto unlock;
     }
 
     /* Handle special control characters */
@@ -901,11 +905,11 @@ console_handle_char(uint8_t byte)
             console_clear_line();
             break;
         }
-
-        return 0;
+    } else {
+        insert_char(&input->line[cur], byte);
     }
-
-    insert_char(&input->line[cur], byte);
+unlock:
+    (void)console_unlock();
 
     return 0;
 }

Reply via email to