]> gitweb.factorcode.org Git - factor.git/commitdiff
use nano-count instead of monotonic counters, dont allow sleeping for
authorDoug Coleman <doug.coleman@gmail.com>
Wed, 18 Nov 2009 22:20:29 +0000 (16:20 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Wed, 18 Nov 2009 22:20:29 +0000 (16:20 -0600)
timestamps

basis/alarms/alarms.factor
basis/calendar/calendar.factor
basis/threads/threads.factor

index 089992b6a9540e6cb69199b6f118982a9dc64666..dc56852c233b4100634020d9d577468775235b2a 100644 (file)
@@ -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
 : <alarm> ( 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
         <box> >>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 ( -- )
index e40b9be7fa41bc925d15f7b34041f3371e5ef31e..fd51feeed97e8e4fc64fe87196c54210c42ee25b 100644 (file)
@@ -560,9 +560,7 @@ M: integer end-of-year 12 31 <date> ;
 : 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" ] }
index 036324be87c61cf291de280a4b9a3cf168f50a3e..4969b62948e4037166b86f528de523f53bf82ab2 100644 (file)
@@ -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>> [