nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge: Loose Tokens
[nit.git]
/
lib
/
realtime.nit
diff --git
a/lib/realtime.nit
b/lib/realtime.nit
index
72a9d5f
..
960a3cb
100644
(file)
--- a/
lib/realtime.nit
+++ b/
lib/realtime.nit
@@
-11,7
+11,7
@@
# another product.
# Provides the Clock utility class to keep time of real time flow
# another product.
# Provides the Clock utility class to keep time of real time flow
-module realtime is c_linker_option("-lrt")
+module realtime is ldflags "-lrt"
in "C header" `{
#ifdef _POSIX_C_SOURCE
in "C header" `{
#ifdef _POSIX_C_SOURCE
@@
-21,17
+21,24
@@
in "C header" `{
#include <time.h>
`}
#include <time.h>
`}
+# Elapsed time representation.
extern class Timespec `{struct timespec*`}
extern class Timespec `{struct timespec*`}
+
+ # Init a new Timespec from `s` seconds and `ns` nanoseconds.
new ( s, ns : Int ) `{
struct timespec* tv = malloc( sizeof(struct timespec) );
tv->tv_sec = s; tv->tv_nsec = ns;
return tv;
`}
new ( s, ns : Int ) `{
struct timespec* tv = malloc( sizeof(struct timespec) );
tv->tv_sec = s; tv->tv_nsec = ns;
return tv;
`}
+
+ # Init a new Timespec from now.
new monotonic_now `{
struct timespec* tv = malloc( sizeof(struct timespec) );
clock_gettime( CLOCK_MONOTONIC, tv );
return tv;
`}
new monotonic_now `{
struct timespec* tv = malloc( sizeof(struct timespec) );
clock_gettime( CLOCK_MONOTONIC, tv );
return tv;
`}
+
+ # Init a new Timespec copied from another.
new copy_of( other : Timespec ) `{
struct timespec* tv = malloc( sizeof(struct timespec) );
tv->tv_sec = other->tv_sec;
new copy_of( other : Timespec ) `{
struct timespec* tv = malloc( sizeof(struct timespec) );
tv->tv_sec = other->tv_sec;
@@
-39,9
+46,12
@@
extern class Timespec `{struct timespec*`}
return tv;
`}
return tv;
`}
+ # Update `self` clock.
fun update `{
fun update `{
- clock_gettime( CLOCK_MONOTONIC, recv );
+ clock_gettime(CLOCK_MONOTONIC, self);
`}
`}
+
+ # Substract a Timespec from `self`.
fun - ( o : Timespec ) : Timespec
do
var s = sec - o.sec
fun - ( o : Timespec ) : Timespec
do
var s = sec - o.sec
@@
-50,11
+60,16
@@
extern class Timespec `{struct timespec*`}
return new Timespec( s, ns )
end
return new Timespec( s, ns )
end
+ # Number of whole seconds of elapsed time.
fun sec : Int `{
fun sec : Int `{
- return recv->tv_sec;
+ return self->tv_sec;
`}
`}
+
+ # Rest of the elapsed time (a fraction of a second).
+ #
+ # Number of nanoseconds.
fun nanosec : Int `{
fun nanosec : Int `{
- return recv->tv_nsec;
+ return self->tv_nsec;
`}
# Seconds in Float
`}
# Seconds in Float