tty: misc changes

This commit is contained in:
Matheus
2024-09-01 23:38:34 -03:00
parent 7a9f5c48c7
commit 6193310f21
2 changed files with 11 additions and 10 deletions
+2 -2
View File
@@ -7,8 +7,8 @@
#include <ringbuffer.h> #include <ringbuffer.h>
#include <kernel/vfs.h> #include <kernel/vfs.h>
#define DEVICE_BUFFER_SIZE 512 #define TTY_DEVICE_BUFFER_SIZE 512
#define READ_BUFFER_SIZE 4096 #define TTY_READ_BUFFER_SIZE 4096
typedef size_t (*ttydevicewritefn_t)(void *internal, char *str, size_t size); typedef size_t (*ttydevicewritefn_t)(void *internal, char *str, size_t size);
typedef void (*ttyinactivefn_t)(void *internal); typedef void (*ttyinactivefn_t)(void *internal);
+9 -8
View File
@@ -100,7 +100,7 @@ void tty_process(tty_t *tty, char c) {
tty->writetodevice(tty->deviceinternal, "\b \b", 3); tty->writetodevice(tty->deviceinternal, "\b \b", 3);
tty->devicepos = 0; tty->devicepos = 0;
memset(tty->devicebuffer, 0, DEVICE_BUFFER_SIZE); memset(tty->devicebuffer, 0, TTY_DEVICE_BUFFER_SIZE);
return; return;
} else if (c == tty->termios.c_cc[VEOF]) { } else if (c == tty->termios.c_cc[VEOF]) {
// end of file TODO make read return 0 // end of file TODO make read return 0
@@ -115,17 +115,18 @@ void tty_process(tty_t *tty, char c) {
// check if buffer is full // check if buffer is full
tty->devicebuffer[tty->devicepos++] = c; tty->devicebuffer[tty->devicepos++] = c;
if (tty->devicepos == DEVICE_BUFFER_SIZE) if (tty->devicepos == TTY_DEVICE_BUFFER_SIZE)
flush = true; flush = true;
if (flush) { if (flush) {
MUTEX_ACQUIRE(&tty->readmutex, false); MUTEX_ACQUIRE(&tty->readmutex, false);
ringbuffer_write(&tty->readbuffer, tty->devicebuffer, tty->devicepos); ringbuffer_write(&tty->readbuffer, tty->devicebuffer, tty->devicepos);
memset(tty->devicebuffer, 0, TTY_DEVICE_BUFFER_SIZE);
tty->devicepos = 0; tty->devicepos = 0;
// XXX is this needed? poll_event(&tty->pollheader, POLLIN);
size_t datacount = RINGBUFFER_DATACOUNT(&tty->readbuffer);
if (datacount)
poll_event(&tty->pollheader, POLLIN);
MUTEX_RELEASE(&tty->readmutex); MUTEX_RELEASE(&tty->readmutex);
} }
@@ -453,11 +454,11 @@ tty_t *tty_create(char *name, ttydevicewritefn_t writefn, ttyinactivefn_t inacti
if (tty->name == NULL) if (tty->name == NULL)
goto error; goto error;
tty->devicebuffer = alloc(DEVICE_BUFFER_SIZE); tty->devicebuffer = alloc(TTY_DEVICE_BUFFER_SIZE);
if (tty->devicebuffer == NULL) if (tty->devicebuffer == NULL)
goto error; goto error;
if (ringbuffer_init(&tty->readbuffer, READ_BUFFER_SIZE)) if (ringbuffer_init(&tty->readbuffer, TTY_READ_BUFFER_SIZE))
goto error; goto error;
int minor = allocminor(tty); int minor = allocminor(tty);