diff --git a/basis/io/backend/unix/multiplexers/epoll/epoll.factor b/basis/io/backend/unix/multiplexers/epoll/epoll.factor index b9c224c629..3985729935 100644 --- a/basis/io/backend/unix/multiplexers/epoll/epoll.factor +++ b/basis/io/backend/unix/multiplexers/epoll/epoll.factor @@ -51,8 +51,8 @@ M: epoll-mx remove-output-callbacks ( fd mx -- seq ) [ EPOLLOUT do-epoll-del ] [ call-next-method ] 2bi ] [ 2drop f ] if ; -: wait-event ( mx us -- n ) - [ [ fd>> ] [ events>> ] bi dup length ] [ 1000 /i ] bi* +: wait-event ( mx nanos -- n ) + [ [ fd>> ] [ events>> ] bi dup length ] [ 1000000 /i ] bi* epoll_wait multiplexer-error ; : handle-event ( event mx -- ) @@ -63,5 +63,5 @@ M: epoll-mx remove-output-callbacks ( fd mx -- seq ) : handle-events ( mx n -- ) [ dup events>> ] dip head-slice swap '[ _ handle-event ] each ; -M: epoll-mx wait-for-events ( us mx -- ) +M: epoll-mx wait-for-events ( nanos mx -- ) swap 60000000 or dupd wait-event handle-events ; diff --git a/basis/io/backend/unix/multiplexers/kqueue/kqueue.factor b/basis/io/backend/unix/multiplexers/kqueue/kqueue.factor index c777e57f1d..16d0338da5 100644 --- a/basis/io/backend/unix/multiplexers/kqueue/kqueue.factor +++ b/basis/io/backend/unix/multiplexers/kqueue/kqueue.factor @@ -73,6 +73,6 @@ M: kqueue-mx remove-output-callbacks ( fd mx -- seq ) [ dup events>> ] dip head-slice [ handle-kevent ] with each ; -M: kqueue-mx wait-for-events ( us mx -- ) +M: kqueue-mx wait-for-events ( nanos mx -- ) swap dup [ make-timespec ] when dupd wait-kevent handle-kevents ; diff --git a/basis/io/backend/unix/multiplexers/multiplexers.factor b/basis/io/backend/unix/multiplexers/multiplexers.factor index 73d8a60310..ded028dda4 100644 --- a/basis/io/backend/unix/multiplexers/multiplexers.factor +++ b/basis/io/backend/unix/multiplexers/multiplexers.factor @@ -26,7 +26,7 @@ GENERIC: remove-output-callbacks ( fd mx -- callbacks ) M: mx remove-output-callbacks writes>> delete-at* drop ; -GENERIC: wait-for-events ( ms mx -- ) +GENERIC: wait-for-events ( nanos mx -- ) : input-available ( fd mx -- ) reads>> delete-at* drop [ resume ] each ; diff --git a/basis/io/backend/unix/multiplexers/select/select.factor b/basis/io/backend/unix/multiplexers/select/select.factor index 8022ed34e2..f2d1a3a3b7 100644 --- a/basis/io/backend/unix/multiplexers/select/select.factor +++ b/basis/io/backend/unix/multiplexers/select/select.factor @@ -48,9 +48,9 @@ TUPLE: select-mx < mx read-fdset write-fdset ; [ write-fdset/tasks [ init-fdset ] keep ] tri f ; -M:: select-mx wait-for-events ( us mx -- ) +M:: select-mx wait-for-events ( nanos mx -- ) mx - [ init-fdsets us dup [ make-timeval ] when select multiplexer-error drop ] + [ init-fdsets nanos 1000 /i dup [ make-timeval ] when select multiplexer-error drop ] [ [ read-fdset/tasks ] keep [ input-available ] check-fdset ] [ [ write-fdset/tasks ] keep [ output-available ] check-fdset ] tri ; diff --git a/basis/threads/threads-docs.factor b/basis/threads/threads-docs.factor index 2f205b0886..995fc867e7 100644 --- a/basis/threads/threads-docs.factor +++ b/basis/threads/threads-docs.factor @@ -113,8 +113,8 @@ HELP: sleep-queue { $var-description "A " { $link min-heap } " storing the queue of sleeping threads." } ; HELP: sleep-time -{ $values { "us/f" "a non-negative integer or " { $link f } } } -{ $description "Outputs the time until the next sleeping thread is scheduled to wake up, which could be zero if there are threads in the run queue, or threads which need to wake up right now. If there are no runnable or sleeping threads, outputs " { $link f } "." } ; +{ $values { "nanos/f" "a non-negative integer or " { $link f } } } +{ $description "Returns the time until the next sleeping thread is scheduled to wake up, which could be zero if there are threads in the run queue, or threads which need to wake up right now. If there are no runnable or sleeping threads, returns " { $link f } "." } ; HELP: stop { $description "Stops the current thread. The thread may be started again from another thread using " { $link (spawn) } "." } ; diff --git a/basis/threads/threads.factor b/basis/threads/threads.factor index 1330625db0..af11d77f84 100644 --- a/basis/threads/threads.factor +++ b/basis/threads/threads.factor @@ -91,7 +91,7 @@ PRIVATE> f >>state check-registered 2array run-queue push-front ; -: sleep-time ( -- us/f ) +: sleep-time ( -- nanos/f ) { { [ run-queue deque-empty? not ] [ 0 ] } { [ sleep-queue heap-empty? ] [ f ] } @@ -184,8 +184,7 @@ M: f sleep-until GENERIC: sleep ( dt -- ) M: real sleep - >integer 1000 * - nano-count + sleep-until ; + >integer nano-count + sleep-until ; : interrupt ( thread -- ) dup state>> [ diff --git a/basis/unix/time/time.factor b/basis/unix/time/time.factor index 4f5ac99309..0a63965c20 100644 --- a/basis/unix/time/time.factor +++ b/basis/unix/time/time.factor @@ -18,8 +18,8 @@ STRUCT: timespec swap >>usec swap >>sec ; -: make-timespec ( us -- timespec ) - 1000000 /mod 1000 * +: make-timespec ( nanos -- timespec ) + 1000000000 /mod timespec swap >>nsec swap >>sec ; diff --git a/core/bootstrap/primitives.factor b/core/bootstrap/primitives.factor index 64e22ebabf..3dcd5969c9 100644 --- a/core/bootstrap/primitives.factor +++ b/core/bootstrap/primitives.factor @@ -495,7 +495,7 @@ tuple { "" "classes.tuple.private" (( layout -- tuple )) } { "profiling" "tools.profiler.private" (( ? -- )) } { "become" "kernel.private" (( old new -- )) } - { "(sleep)" "threads.private" (( us -- )) } + { "(sleep)" "threads.private" (( nanos -- )) } { "" "classes.tuple.private" (( ... layout -- tuple )) } { "callstack>array" "kernel" (( callstack -- array )) } { "innermost-frame-executing" "kernel.private" (( callstack -- obj )) }