diff --git a/ueforth/common/tasking_tester.fs b/ueforth/common/tasking_tester.fs new file mode 100644 index 0000000..f78ce15 --- /dev/null +++ b/ueforth/common/tasking_tester.fs @@ -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 diff --git a/ueforth/common/tasks.fs b/ueforth/common/tasks.fs index 78410ae..27520e2 100644 --- a/ueforth/common/tasks.fs +++ b/ueforth/common/tasks.fs @@ -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 diff --git a/ueforth/posix/posix.fs b/ueforth/posix/posix.fs index 2e5befd..2cc16bd 100644 --- a/ueforth/posix/posix.fs +++ b/ueforth/posix/posix.fs @@ -139,6 +139,23 @@ O_RDWR constant r/w dup 0 SEEK_END lseek r> swap >r SEEK_SET lseek drop r> d0r 0 >r CLOCK_MONOTONIC_RAW rp@ cell - clock_gettime throw + r> 1000000 / r> 1000 * + ; + ( Other Utils ) : ms ( n -- ) 1000 * usleep drop ;