summaryrefslogtreecommitdiff
path: root/kernel/serial.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/serial.c')
-rw-r--r--kernel/serial.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/kernel/serial.c b/kernel/serial.c
index 911f02c..f5610f5 100644
--- a/kernel/serial.c
+++ b/kernel/serial.c
@@ -97,18 +97,19 @@ ssize_t rsread(void *buf, size_t len) {
return 0;
while(n--) {
- if(rxread == rxwrite) {
- /* put the current task to sleep */
- waiting_task = ctask;
- ctask->state = TSTATE_INTERRUPTIBLE;
- reschedule();
- }
+ /* check if the buffer's empty and if so, go to sleep */
+ cli();
+ if(rxread == rxwrite)
+ interruptible_sleep_on(&waiting_task);
+
/* check again to see if anything was read, or we were interrupted */
if(rxread == rxwrite) {
- waiting_task = NULL;
+ sti();
return -EINTR;
}
+ sti();
+
*b++ = rxbuf[rxread];
rxread = rxread + 1 % sizeof(rxbuf);
}