Adding posix clocks, optionally ms yields.

This commit is contained in:
Brad Nelson
2021-03-05 21:50:57 -08:00
parent 705f04d37e
commit d90dd1ceac
3 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,11 @@
( Trying some things with tasks )
: printer1 begin 42 emit 1000 ms again ;
: printer2 begin 43 emit 500 ms again ;
: runner begin pause again ;
' printer1 1000 1000 task print1
' printer2 1000 1000 task print2
print1 start-task
print2 start-task
runner

View File

@ -30,6 +30,10 @@ forth definitions tasks
task-list @ 2 cells + @ rp!
;
DEFINED? ms-ticks [IF]
: ms ( n -- ) ms-ticks >r begin pause ms-ticks r@ - over >= until rdrop drop ;
[THEN]
tasks definitions
0 0 0 task main-task main-task start-task
forth definitions

View File

@ -139,6 +139,23 @@ O_RDWR constant r/w
dup 0 SEEK_END lseek r> swap >r
SEEK_SET lseek drop r> d0<ior ;
( Clock )
z" clock_gettime" 2 sysfunc clock_gettime
: timespec ( "name" ) create 0 , 0 , ;
0 constant CLOCK_REALTIME
1 constant CLOCK_MONOTONIC
2 constant CLOCK_PROCESS_CPUTIME_ID
3 constant CLOCK_THREAD_CPUTIME_ID
4 constant CLOCK_MONOTONIC_RAW
5 constant CLOCK_REALTIME_COARSE
6 constant CLOCK_MONOTONIC_COARSE
7 constant CLOCK_BOOTTIME
8 constant CLOCK_REALTIME_ALARM
9 constant CLOCK_BOOTTIME_ALARM
: ms-ticks ( -- n )
0 >r 0 >r CLOCK_MONOTONIC_RAW rp@ cell - clock_gettime throw
r> 1000000 / r> 1000 * + ;
( Other Utils )
: ms ( n -- ) 1000 * usleep drop ;