-USING: help.markup help.syntax calendar quotations ;\r
+USING: help.markup help.syntax calendar quotations system ;\r
IN: alarms\r
\r
HELP: alarm\r
} ;\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
+++ /dev/null
-Doug Coleman
+++ /dev/null
-! 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"
+++ /dev/null
-! 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
+++ /dev/null
-Doug Coleman
+++ /dev/null
-Doug Coleman
+++ /dev/null
-! 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 ;
+++ /dev/null
-unportable
+++ /dev/null
-! 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 ;
+++ /dev/null
-Doug Coleman
+++ /dev/null
-unportable
+++ /dev/null
-! 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 ;
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"
{ $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 } "." } ;
: yield ( -- ) [ resume ] f suspend drop ;
-GENERIC: sleep-until ( time/f -- )
+GENERIC: sleep-until ( n/f -- )
M: integer sleep-until
'[ _ schedule-sleep ] "sleep" suspend drop ;
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"
system-micros
system-micros
}
+"Getting a monotonically increasing nanosecond count:"
+{ $subsections nano-count }
"Exiting the Factor VM:"
{ $subsections exit } ;
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." } ;