Add goroutines and function pointers

This commit is contained in:
Ayke van Laethem
2018-06-07 14:48:24 +02:00
parent 8df220a53b
commit 0168bf7797
10 changed files with 796 additions and 59 deletions
+13 -2
View File
@@ -10,6 +10,7 @@ import (
// #include <stdio.h>
// #include <stdlib.h>
// #include <unistd.h>
// #include <time.h>
import "C"
const Microsecond = 1
@@ -18,10 +19,20 @@ func putchar(c byte) {
C.putchar(C.int(c))
}
func Sleep(d Duration) {
func sleep(d Duration) {
C.usleep(C.useconds_t(d))
}
// Return monotonic time in microseconds.
//
// TODO: use nanoseconds?
// TODO: noescape
func monotime() uint64 {
var ts C.struct_timespec
C.clock_gettime(C.CLOCK_MONOTONIC, &ts)
return uint64(ts.tv_sec) * 1000 * 1000 + uint64(ts.tv_nsec) / 1000
}
func abort() {
C.abort()
}
@@ -35,5 +46,5 @@ func alloc(size uintptr) unsafe.Pointer {
}
func free(ptr unsafe.Pointer) {
C.free(ptr)
//C.free(ptr) // TODO
}