mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-02 07:28:21 +00:00
console: locking and tty check
This commit is contained in:
@@ -2,11 +2,15 @@
|
|||||||
#define _CONSOLE_H
|
#define _CONSOLE_H
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <kernel/input.h>
|
#include <kernel/input.h>
|
||||||
|
#include <kernel/tty.h>
|
||||||
|
|
||||||
void console_init();
|
void console_init();
|
||||||
void console_putc(char c);
|
void console_putc(char c);
|
||||||
size_t console_write(char *str, size_t size);
|
size_t console_write(char *str, size_t size);
|
||||||
void console_process_events(input_event_t *events, int count);
|
void console_process_events(input_event_t *events, int count);
|
||||||
|
int console_set_lock(bool lock);
|
||||||
|
bool console_is_tty(tty_t *p);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -17,11 +17,24 @@ static semaphore_t input_sem;
|
|||||||
static mutex_t writemutex;
|
static mutex_t writemutex;
|
||||||
static thread_t *thread;
|
static thread_t *thread;
|
||||||
static tty_t *tty;
|
static tty_t *tty;
|
||||||
|
static bool locked;
|
||||||
|
|
||||||
static size_t console_ttywrite(void *internal, char *str, size_t count) {
|
static size_t console_ttywrite(void *internal, char *str, size_t count) {
|
||||||
return console_write(str, count);
|
return console_write(str, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int console_set_lock(bool lock) {
|
||||||
|
bool expected = !lock;
|
||||||
|
if (!__atomic_compare_exchange_n(&locked, &expected, lock, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
|
||||||
|
return EBUSY;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool console_is_tty(tty_t *p) {
|
||||||
|
return p == tty;
|
||||||
|
}
|
||||||
|
|
||||||
void console_putc(char c) {
|
void console_putc(char c) {
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
console_write("\r\n", 2);
|
console_write("\r\n", 2);
|
||||||
|
|||||||
Reference in New Issue
Block a user