Adding posix clocks, optionally ms yields.
This commit is contained in:
11
ueforth/common/tasking_tester.fs
Normal file
11
ueforth/common/tasking_tester.fs
Normal 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
|
||||
@ -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
|
||||
|
||||
@ -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 ;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user