diff --git a/kernel/ringbuf.c b/kernel/ringbuf.c index 832a689..8cf00a8 100644 --- a/kernel/ringbuf.c +++ b/kernel/ringbuf.c @@ -31,7 +31,7 @@ size_t ringbuf_read(void *dest, struct ringbuf *buf, size_t len) { uint8_t *tmp = dest; - while (len-- > 0 && buf->len > 0) { + while (len-- && buf->len) { *tmp++ = buf->data[buf->rpos++]; buf->len--; @@ -46,7 +46,7 @@ size_t ringbuf_write(struct ringbuf *buf, const void *src, size_t len) { const uint8_t *tmp = src; - while (len-- > 0 && buf->len < buf->capacity) { + while (len-- && buf->len != buf->capacity) { buf->data[buf->wpos++] = *tmp++; buf->len++; diff --git a/kernel/serial.c b/kernel/serial.c index bd4b59f..d37a361 100644 --- a/kernel/serial.c +++ b/kernel/serial.c @@ -5,6 +5,7 @@ #include #include +#include #include @@ -46,14 +47,23 @@ void serial_exit(struct serial_interface *interface) ssize_t serial_read(void *dest, struct serial_interface *interface, size_t len) { - return (ssize_t)ringbuf_read(dest, interface->rx, len); + ssize_t ret; + + sched_atomic_enter(); + ret = (ssize_t)ringbuf_read(dest, interface->rx, len); + sched_atomic_leave(); + + return ret; } ssize_t serial_write(struct serial_interface *interface, const void *data, size_t len) { - ssize_t ret = (ssize_t)ringbuf_write(interface->tx, data, len); - if (ret > 0) - arch_serial_notify(interface); + ssize_t ret; + + sched_atomic_enter(); + ret = (ssize_t)ringbuf_write(interface->tx, data, len); + sched_atomic_leave(); + return ret; }