From b0859c6d921212cf62797ac30033d3ed6f99eb5d Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Fri, 2 Dec 2011 22:37:17 +0100 Subject: [PATCH] usleep'ing for 0 usecs simply causes a context-switch. --- libmaxsi/c/hsrc/unistd.h | 5 +++-- sortix/scheduler.cpp | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/libmaxsi/c/hsrc/unistd.h b/libmaxsi/c/hsrc/unistd.h index 5ae24953..6d794ebf 100644 --- a/libmaxsi/c/hsrc/unistd.h +++ b/libmaxsi/c/hsrc/unistd.h @@ -165,9 +165,10 @@ int isatty(int); int pipe(int [2]); ssize_t read(int, void*, size_t); unsigned sleep(unsigned); -#if __POSIX_OBSOLETE <= 200112 +/*#if __POSIX_OBSOLETE <= 200112*/ +typedef unsigned int useconds_t; int usleep(useconds_t useconds); -#endif +/*#endif*/ int unlink(const char*); ssize_t write(int, const void*, size_t); diff --git a/sortix/scheduler.cpp b/sortix/scheduler.cpp index 34afcd87..14636ce6 100644 --- a/sortix/scheduler.cpp +++ b/sortix/scheduler.cpp @@ -319,7 +319,12 @@ namespace Sortix { Thread* thread = currentthread; uintmax_t timetosleep = ((uintmax_t) secs) * 1000ULL * 1000ULL; - if ( timetosleep == 0 ) { return; } + if ( timetosleep == 0 ) + { + Switch(Syscall::InterruptRegs()); + Syscall::AsIs(); + return; + } PutThreadToSleep(thread, timetosleep); Syscall::Incomplete(); } @@ -328,7 +333,12 @@ namespace Sortix { Thread* thread = currentthread; uintmax_t timetosleep = usecs; - if ( timetosleep == 0 ) { return; } + if ( timetosleep == 0 ) + { + Switch(Syscall::InterruptRegs()); + Syscall::AsIs(); + return; + } PutThreadToSleep(thread, timetosleep); Syscall::Incomplete(); }