Added time.sleep function
This commit is contained in:
parent
819a4a907b
commit
0db4d4fc14
3 changed files with 25 additions and 2 deletions
21
lib/time/time.q
Normal file
21
lib/time/time.q
Normal file
|
@ -0,0 +1,21 @@
|
|||
import mem
|
||||
import sys
|
||||
|
||||
sleep(nanoseconds Int) {
|
||||
seconds := 0
|
||||
|
||||
loop {
|
||||
if nanoseconds >= 1000000000 {
|
||||
nanoseconds = nanoseconds - 1000000000
|
||||
seconds += 1
|
||||
} else {
|
||||
timespec := mem.alloc(16)
|
||||
store(timespec, 8, seconds)
|
||||
offset := timespec + 8
|
||||
store(offset, 8, nanoseconds)
|
||||
sys.nanosleep(timespec)
|
||||
mem.free(timespec, 16)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue