diff --git a/basis/alarms/alarms-docs.factor b/basis/alarms/alarms-docs.factor index 446ec3d7fa..2c5a567d62 100644 --- a/basis/alarms/alarms-docs.factor +++ b/basis/alarms/alarms-docs.factor @@ -1,4 +1,4 @@ -USING: help.markup help.syntax calendar quotations ; +USING: help.markup help.syntax calendar quotations system ; IN: alarms HELP: alarm @@ -37,7 +37,7 @@ HELP: every } ; ARTICLE: "alarms" "Alarms" -"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 +"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 "The alarm class:" { $subsections alarm } "Register a recurring alarm:" diff --git a/basis/monotonic-clock/authors.txt b/basis/monotonic-clock/authors.txt deleted file mode 100644 index 7c1b2f2279..0000000000 --- a/basis/monotonic-clock/authors.txt +++ /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 index 735dbcab40..0000000000 --- a/basis/monotonic-clock/monotonic-clock-docs.factor +++ /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 index 678c527bab..0000000000 --- a/basis/monotonic-clock/monotonic-clock.factor +++ /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 index 7c1b2f2279..0000000000 --- a/basis/monotonic-clock/unix/authors.txt +++ /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 index 7c1b2f2279..0000000000 --- a/basis/monotonic-clock/unix/macosx/authors.txt +++ /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 index d1412b8d54..0000000000 --- a/basis/monotonic-clock/unix/macosx/macosx.factor +++ /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 [ - 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 index 6bf68304bb..0000000000 --- a/basis/monotonic-clock/unix/macosx/tags.txt +++ /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 index d739735f42..0000000000 --- a/basis/monotonic-clock/unix/unix.factor +++ /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 [ 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 index 7c1b2f2279..0000000000 --- a/basis/monotonic-clock/windows/authors.txt +++ /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 index 6bf68304bb..0000000000 --- a/basis/monotonic-clock/windows/tags.txt +++ /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 index bb47941479..0000000000 --- a/basis/monotonic-clock/windows/windows.factor +++ /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 - - ] 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 ; diff --git a/basis/threads/threads-docs.factor b/basis/threads/threads-docs.factor index 85952ccd91..2f205b0886 100644 --- a/basis/threads/threads-docs.factor +++ b/basis/threads/threads-docs.factor @@ -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 } "." } ; diff --git a/basis/threads/threads.factor b/basis/threads/threads.factor index 4969b62948..1330625db0 100644 --- a/basis/threads/threads.factor +++ b/basis/threads/threads.factor @@ -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 ; diff --git a/core/system/system-docs.factor b/core/system/system-docs.factor index 364ad04fa2..3148fd6fdb 100644 --- a/core/system/system-docs.factor +++ b/core/system/system-docs.factor @@ -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." } ;