]> gitweb.factorcode.org Git - factor.git/commitdiff
document nano-count, move monotonic-clock to hell
authorDoug Coleman <doug.coleman@gmail.com>
Wed, 18 Nov 2009 22:33:10 +0000 (16:33 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Wed, 18 Nov 2009 22:33:10 +0000 (16:33 -0600)
15 files changed:
basis/alarms/alarms-docs.factor
basis/monotonic-clock/authors.txt [deleted file]
basis/monotonic-clock/monotonic-clock-docs.factor [deleted file]
basis/monotonic-clock/monotonic-clock.factor [deleted file]
basis/monotonic-clock/unix/authors.txt [deleted file]
basis/monotonic-clock/unix/macosx/authors.txt [deleted file]
basis/monotonic-clock/unix/macosx/macosx.factor [deleted file]
basis/monotonic-clock/unix/macosx/tags.txt [deleted file]
basis/monotonic-clock/unix/unix.factor [deleted file]
basis/monotonic-clock/windows/authors.txt [deleted file]
basis/monotonic-clock/windows/tags.txt [deleted file]
basis/monotonic-clock/windows/windows.factor [deleted file]
basis/threads/threads-docs.factor
basis/threads/threads.factor
core/system/system-docs.factor

index 446ec3d7fad85ecc06d08e9b24c6decd3c9e18f6..2c5a567d62a94cf14fb9694d2a732d3547267a8e 100644 (file)
@@ -1,4 +1,4 @@
-USING: help.markup help.syntax calendar quotations ;\r
+USING: help.markup help.syntax calendar quotations system ;\r
 IN: alarms\r
 \r
 HELP: alarm\r
@@ -37,7 +37,7 @@ HELP: every
 } ;\r
 \r
 ARTICLE: "alarms" "Alarms"\r
-"The " { $vocab-link "alarms" } " vocabulary provides a lightweight way to schedule one-time and recurring tasks without spawning a new thread. Alarms use " { $vocab-link "monotonic-clock" } ", so they continue to work across system clock changes." $nl\r
+"The " { $vocab-link "alarms" } " vocabulary provides a lightweight way to schedule one-time and recurring tasks without spawning a new thread. Alarms use " { $link nano-count } ", so they continue to work across system clock changes." $nl\r
 "The alarm class:"\r
 { $subsections alarm }\r
 "Register a recurring alarm:"\r
diff --git a/basis/monotonic-clock/authors.txt b/basis/monotonic-clock/authors.txt
deleted file mode 100644 (file)
index 7c1b2f2..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Doug Coleman
diff --git a/basis/monotonic-clock/monotonic-clock-docs.factor b/basis/monotonic-clock/monotonic-clock-docs.factor
deleted file mode 100644 (file)
index 735dbca..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-! Copyright (C) 2009 Doug Coleman.
-! See http://factorcode.org/license.txt for BSD license.
-USING: help.markup help.syntax kernel math ;
-IN: monotonic-clock
-
-HELP: monotonic-count
-{ $values
-    
-    { "n" integer }
-}
-{ $description "Returns a monotonically increasing number of nanoseconds since an arbitrary time. This number can be compared against future calls to " { $link monotonic-count } "." } ;
-
-ARTICLE: "monotonic-clock" "Monotonic clock"
-"The " { $vocab-link "monotonic-clock" } " vocabulary implements a single word which can be used as a clock. A special property of this clock is that it is independent of the system time and time zones." $nl
-"Get the number of nanoseconds since an arbitrary beginning:"
-{ $subsections monotonic-count } ;
-
-ABOUT: "monotonic-clock"
diff --git a/basis/monotonic-clock/monotonic-clock.factor b/basis/monotonic-clock/monotonic-clock.factor
deleted file mode 100755 (executable)
index 678c527..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-! Copyright (C) 2009 Doug Coleman.
-! See http://factorcode.org/license.txt for BSD license.
-USING: combinators system vocabs.loader ;
-IN: monotonic-clock
-
-HOOK: monotonic-count os ( -- n )
-
-{
-    { [ os macosx? ] [ "monotonic-clock.unix.macosx" ] }
-    { [ os unix? ] [ "monotonic-clock.unix" ] }
-    { [ os windows? ] [ "monotonic-clock.windows" ] }
-} cond require
diff --git a/basis/monotonic-clock/unix/authors.txt b/basis/monotonic-clock/unix/authors.txt
deleted file mode 100644 (file)
index 7c1b2f2..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Doug Coleman
diff --git a/basis/monotonic-clock/unix/macosx/authors.txt b/basis/monotonic-clock/unix/macosx/authors.txt
deleted file mode 100644 (file)
index 7c1b2f2..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Doug Coleman
diff --git a/basis/monotonic-clock/unix/macosx/macosx.factor b/basis/monotonic-clock/unix/macosx/macosx.factor
deleted file mode 100755 (executable)
index d1412b8..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-! Copyright (C) 2009 Doug Coleman.
-! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.syntax classes.struct kernel math
-monotonic-clock system unix.types ;
-IN: monotonic-clock.unix.macosx
-
-STRUCT: mach_timebase_info
-    { numer uint32_t }
-    { denom uint32_t } ;
-
-TYPEDEF: mach_timebase_info* mach_timebase_info_t
-TYPEDEF: mach_timebase_info mach_timebase_info_data_t
-
-FUNCTION: uint64_t mach_absolute_time ( ) ;
-FUNCTION: kern_return_t mach_timebase_info ( mach_timebase_info_t info ) ;
-FUNCTION: kern_return_t mach_wait_until ( uint64_t deadline ) ;
-
-ERROR: mach-timebase-info ret ;
-
-M: macosx monotonic-count 
-    mach_absolute_time
-    \ mach_timebase_info <struct> [
-        mach_timebase_info [ mach-timebase-info ] unless-zero
-    ] keep [ numer>> ] [ denom>> ] bi [ * ] dip /i ;
diff --git a/basis/monotonic-clock/unix/macosx/tags.txt b/basis/monotonic-clock/unix/macosx/tags.txt
deleted file mode 100644 (file)
index 6bf6830..0000000
+++ /dev/null
@@ -1 +0,0 @@
-unportable
diff --git a/basis/monotonic-clock/unix/unix.factor b/basis/monotonic-clock/unix/unix.factor
deleted file mode 100644 (file)
index d739735..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-! Copyright (C) 2009 Doug Coleman.
-! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types alien.syntax calendar.unix classes.struct
-kernel monotonic-clock system unix unix.time unix.types ;
-IN: monotonic-clock.unix
-
-LIBRARY: librt
-
-FUNCTION: int clock_settime ( clockid_t clock_id, timespec* tp ) ;
-FUNCTION: int clock_gettime ( clockid_t clock_id, timespec* tp ) ;
-FUNCTION: int clock_getres ( clockid_t clock_id, timespec* res ) ;
-
-CONSTANT: CLOCK_REALTIME 0
-CONSTANT: CLOCK_MONOTONIC 1
-CONSTANT: CLOCK_PROCESS_CPUTIME_ID 2
-CONSTANT: CLOCK_THREAD_CPUTIME_ID 3
-
-CONSTANT: TIMER_ABSTIME 1
-
-M: unix monotonic-count
-    CLOCK_MONOTONIC timespec <struct> [ clock_gettime io-error ] keep
-    timespec>nanoseconds ;
diff --git a/basis/monotonic-clock/windows/authors.txt b/basis/monotonic-clock/windows/authors.txt
deleted file mode 100644 (file)
index 7c1b2f2..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Doug Coleman
diff --git a/basis/monotonic-clock/windows/tags.txt b/basis/monotonic-clock/windows/tags.txt
deleted file mode 100644 (file)
index 6bf6830..0000000
+++ /dev/null
@@ -1 +0,0 @@
-unportable
diff --git a/basis/monotonic-clock/windows/windows.factor b/basis/monotonic-clock/windows/windows.factor
deleted file mode 100755 (executable)
index bb47941..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-! Copyright (C) 2009 Doug Coleman.
-! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types alien.data fry kernel monotonic-clock
-system windows.errors windows.kernel32 math ;
-IN: monotonic-clock.windows
-
-<PRIVATE
-
-: execute-performance-query ( word -- n )
-    [ "LARGE_INTEGER*" <c-object> ] dip
-    '[ _ execute win32-error=0/f ] keep *ulonglong ; inline
-
-PRIVATE>
-
-: cpu-frequency ( -- n )
-    \ QueryPerformanceFrequency execute-performance-query ;
-
-M: windows monotonic-count  ( -- n )
-    \ QueryPerformanceCounter execute-performance-query
-    1000000000 * cpu-frequency /i ;
index 85952ccd911f38d93bcaf7788f19b09b5a474775..2f205b0886924bad1a2590fd8e45f1c99517f941 100644 (file)
@@ -1,6 +1,6 @@
 USING: help.markup help.syntax kernel kernel.private io
 threads.private continuations init quotations strings
-assocs heaps boxes namespaces deques dlists ;
+assocs heaps boxes namespaces deques dlists system ;
 IN: threads
 
 ARTICLE: "threads-start/stop" "Starting and stopping threads"
@@ -123,8 +123,8 @@ HELP: yield
 { $description "Adds the current thread to the end of the run queue, and switches to the next runnable thread." } ;
 
 HELP: sleep-until
-{ $values { "time/f" "a non-negative integer or " { $link f } } }
-{ $description "Suspends the current thread until the given time, or indefinitely if a value of " { $link f } " is passed in."
+{ $values { "n/f" "a non-negative integer or " { $link f } } }
+{ $description "Suspends the current thread until the given nanosecond count, returned by " { $link nano-count } ", is reached, or indefinitely if a value of " { $link f } " is passed in."
 $nl
 "Other threads may interrupt the sleep by calling " { $link interrupt } "." } ;
 
index 4969b62948e4037166b86f528de523f53bf82ab2..1330625db0cff42c41fb916d0c1eea8fc81d4539 100644 (file)
@@ -173,7 +173,7 @@ PRIVATE>
 
 : yield ( -- ) [ resume ] f suspend drop ;
 
-GENERIC: sleep-until ( time/f -- )
+GENERIC: sleep-until ( n/f -- )
 
 M: integer sleep-until
     '[ _ schedule-sleep ] "sleep" suspend drop ;
index 364ad04fa2a2176c409bd4f1190f87a7542c1cf6..3148fd6fdb23ae996cd67ab42310c269d8543df8 100644 (file)
@@ -1,5 +1,6 @@
 USING: generic help.markup help.syntax kernel math memory
-namespaces sequences kernel.private strings classes.singleton ;
+namespaces sequences kernel.private strings classes.singleton
+tools.time ;
 IN: system
 
 ABOUT: "system"
@@ -19,6 +20,8 @@ ARTICLE: "system" "System interface"
     system-micros
     system-micros
 }
+"Getting a monotonically increasing nanosecond count:"
+{ $subsections nano-count }
 "Exiting the Factor VM:"
 { $subsections exit } ;
 
@@ -79,14 +82,19 @@ HELP: exit ( n -- )
 
 HELP: system-micros ( -- us )
 { $values { "us" integer } }
-{ $description "Outputs the number of microseconds ellapsed since midnight January 1, 1970." }
-{ $notes "This is a low-level word. The " { $vocab-link "calendar" } " vocabulary provides features for date/time arithmetic and formatting." } ;
+{ $description "Outputs the number of microseconds elapsed since midnight January 1, 1970." }
+{ $notes "This is a low-level word. The " { $vocab-link "calendar" } " vocabulary provides features for date/time arithmetic and formatting. For timing code, use " { $link nano-count } "." } ;
 
 HELP: system-millis ( -- ms )
 { $values { "ms" integer } }
-{ $description "Outputs the number of milliseconds ellapsed since midnight January 1, 1970." }
+{ $description "Outputs the number of milliseconds elapsed since midnight January 1, 1970." }
 { $notes "This is a low-level word. The " { $vocab-link "calendar" } " vocabulary provides features for date/time arithmetic and formatting." } ;
 
+HELP: nano-count ( -- ns )
+{ $values { "ns" integer } }
+{ $description "Outputs a monotonically increasing count of nanoseconds elapsed since an arbitrary starting time. The difference of two calls to this word allows timing. This word is unaffected by system clock changes." }
+{ $notes "This is a low-level word. The " { $link time } " word may be used to time code execution time. For system time, use " { $link system-micros } "." } ;
+
 HELP: image
 { $values { "path" "a pathname string" } }
 { $description "Outputs the pathname of the currently running Factor image." } ;