From 070393df70477b8ecb7bffd148d2123fdcaf3b12 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 18 Nov 2009 16:20:29 -0600 Subject: [PATCH] use nano-count instead of monotonic counters, dont allow sleeping for timestamps --- basis/alarms/alarms.factor | 11 +++++------ basis/calendar/calendar.factor | 4 +--- basis/threads/threads.factor | 7 ++++--- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/basis/alarms/alarms.factor b/basis/alarms/alarms.factor index 089992b6a9..dc56852c23 100644 --- a/basis/alarms/alarms.factor +++ b/basis/alarms/alarms.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors assocs boxes calendar combinators.short-circuit fry heaps init kernel math.order -namespaces quotations threads math monotonic-clock ; +namespaces quotations threads math system ; IN: alarms TUPLE: alarm @@ -25,7 +25,7 @@ SYMBOL: alarm-thread : ( quot start interval -- alarm ) alarm new swap dup [ normalize-argument ] when >>interval - swap dup [ normalize-argument monotonic-count + ] when >>start + swap dup [ normalize-argument nano-count + ] when >>start swap >>quot >>entry ; @@ -38,7 +38,7 @@ SYMBOL: alarm-thread [ start>> ] dip <= ; : reschedule-alarm ( alarm -- ) - dup interval>> monotonic-count + >>start register-alarm ; + dup interval>> nano-count + >>start register-alarm ; : call-alarm ( alarm -- ) [ entry>> box> drop ] @@ -57,13 +57,12 @@ SYMBOL: alarm-thread ] if ; : trigger-alarms ( alarms -- ) - monotonic-count (trigger-alarms) ; + nano-count (trigger-alarms) ; : next-alarm ( alarms -- timestamp/f ) dup heap-empty? [ drop f ] [ heap-peek drop start>> - monotonic-count swap - - nanoseconds hence + nano-count swap - ] if ; : alarm-thread-loop ( -- ) diff --git a/basis/calendar/calendar.factor b/basis/calendar/calendar.factor index e40b9be7fa..fd51feeed9 100644 --- a/basis/calendar/calendar.factor +++ b/basis/calendar/calendar.factor @@ -560,9 +560,7 @@ M: integer end-of-year 12 31 ; : unix-time>timestamp ( seconds -- timestamp ) seconds unix-1970 time+ ; -M: timestamp sleep-until timestamp>micros sleep-until ; - -M: duration sleep hence sleep-until ; +M: duration sleep duration>nanoseconds nano-count + sleep-until ; { { [ os unix? ] [ "calendar.unix" ] } diff --git a/basis/threads/threads.factor b/basis/threads/threads.factor index 036324be87..4969b62948 100644 --- a/basis/threads/threads.factor +++ b/basis/threads/threads.factor @@ -95,7 +95,7 @@ PRIVATE> { { [ run-queue deque-empty? not ] [ 0 ] } { [ sleep-queue heap-empty? ] [ f ] } - [ sleep-queue heap-peek nip system-micros [-] ] + [ sleep-queue heap-peek nip nano-count [-] ] } cond ; DEFER: stop @@ -108,7 +108,7 @@ DEFER: stop : expire-sleep? ( heap -- ? ) dup heap-empty? - [ drop f ] [ heap-peek nip system-micros <= ] if ; + [ drop f ] [ heap-peek nip nano-count <= ] if ; : expire-sleep ( thread -- ) f >>sleep-entry resume ; @@ -184,7 +184,8 @@ M: f sleep-until GENERIC: sleep ( dt -- ) M: real sleep - system-micros + >integer sleep-until ; + >integer 1000 * + nano-count + sleep-until ; : interrupt ( thread -- ) dup state>> [