Added time.sleep function
This commit is contained in:
parent
271ae0fb18
commit
715635aaa7
@ -1,5 +1,6 @@
|
|||||||
import sys
|
import sys
|
||||||
import thread
|
import thread
|
||||||
|
import time
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
thread.create(work)
|
thread.create(work)
|
||||||
@ -10,6 +11,7 @@ main() {
|
|||||||
|
|
||||||
work() {
|
work() {
|
||||||
sys.write(1, "[ ] start\n", 10)
|
sys.write(1, "[ ] start\n", 10)
|
||||||
|
time.sleep(10 * 1000 * 1000)
|
||||||
sys.write(1, "[x] end\n", 8)
|
sys.write(1, "[x] end\n", 8)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
}
|
}
|
@ -22,8 +22,8 @@ munmap(address Pointer, length Int) -> Int {
|
|||||||
return syscall(11, address, length)
|
return syscall(11, address, length)
|
||||||
}
|
}
|
||||||
|
|
||||||
nanosleep(requested Pointer, remaining Pointer) -> Int {
|
nanosleep(timespec Pointer) -> Int {
|
||||||
return syscall(35, requested, remaining)
|
return syscall(35, timespec, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
clone(flags Int, stack Pointer) -> Int {
|
clone(flags Int, stack Pointer) -> Int {
|
||||||
|
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…
x
Reference in New Issue
Block a user