[PATCH 16/27] console_simple: Use tstc_raw() as tstc()

Andrey Smirnov andrew.smirnov at gmail.com
Thu Jun 14 21:11:25 PDT 2018


Semantics implemented by tstc_raw() in CONSOLE_FULL is reasonably
close to what testc() in CONSOLE_SIMPLE does. Arguably tstc_raw() is
bulkier that what CONSOLE_SIMPLE has, but this replacement allows us
to share more code between CONSOLE_SIMPLE and CONSOLE_FULL as well as
reduce our dependencies on global console pointer in CONSOLE_SIMPLE.

Signed-off-by: Andrey Smirnov <andrew.smirnov at gmail.com>
---
 common/console.c        | 14 --------------
 common/console_common.c | 17 +++++++++++++++++
 common/console_simple.c |  9 ---------
 include/console.h       |  2 ++
 4 files changed, 19 insertions(+), 23 deletions(-)

diff --git a/common/console.c b/common/console.c
index f454f91c0..c8c413a5e 100644
--- a/common/console.c
+++ b/common/console.c
@@ -454,20 +454,6 @@ static int getc_raw(void)
 	}
 }
 
-static int tstc_raw(void)
-{
-	struct console_device *cdev;
-
-	for_each_console(cdev) {
-		if (!(cdev->f_active & CONSOLE_STDIN))
-			continue;
-		if (cdev->tstc(cdev))
-			return 1;
-	}
-
-	return 0;
-}
-
 int getchar(void)
 {
 	unsigned char ch;
diff --git a/common/console_common.c b/common/console_common.c
index 324d42915..0653cb916 100644
--- a/common/console_common.c
+++ b/common/console_common.c
@@ -326,6 +326,23 @@ void console_flush(void)
 }
 EXPORT_SYMBOL(console_flush);
 
+int tstc_raw(void)
+{
+	struct console_device *cdev;
+
+	for_each_console(cdev) {
+		if (!(cdev->f_active & CONSOLE_STDIN))
+			continue;
+		if (cdev->tstc(cdev))
+			return 1;
+	}
+
+	return 0;
+}
+
+__weak int tstc(void) __alias(tstc_raw);
+EXPORT_SYMBOL(tstc);
+
 #endif /* !CONFIG_CONSOLE_NONE */
 
 int dprintf(int file, const char *fmt, ...)
diff --git a/common/console_simple.c b/common/console_simple.c
index 9da516ee9..475d96b68 100644
--- a/common/console_simple.c
+++ b/common/console_simple.c
@@ -7,15 +7,6 @@
 
 extern struct console_device *console;
 
-int tstc(void)
-{
-	if (!console)
-		return 0;
-
-	return console->tstc(console);
-}
-EXPORT_SYMBOL(tstc);
-
 int getchar(void)
 {
 	if (!console)
diff --git a/include/console.h b/include/console.h
index 81a5a5534..d8d36f219 100644
--- a/include/console.h
+++ b/include/console.h
@@ -218,4 +218,6 @@ struct console_device *__console_get_default(void);
 void __console_set_putc(struct console_device *cdev,
 			putc_func_t putcf, void *ctx);
 
+int tstc_raw(void);
+
 #endif
-- 
2.17.0




More information about the barebox mailing list