make runtime compatible with wasm
This commit is contained in:
@@ -6,10 +6,8 @@ package time
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
"github.com/goplus/llgo/runtime/internal/clite/libuv"
|
||||
)
|
||||
|
||||
// Sleep pauses the current goroutine for at least the duration d.
|
||||
@@ -21,7 +19,7 @@ func Sleep(d Duration) {
|
||||
// Interface to timers implemented in package runtime.
|
||||
// Must be in sync with ../runtime/time.go:/^type timer
|
||||
type runtimeTimer struct {
|
||||
libuv.Timer
|
||||
// libuv.Timer
|
||||
when int64
|
||||
f func(any, uintptr)
|
||||
arg any
|
||||
@@ -178,62 +176,65 @@ func goFunc(arg any, seq uintptr) {
|
||||
}
|
||||
|
||||
var (
|
||||
timerLoop *libuv.Loop
|
||||
// timerLoop *libuv.Loop
|
||||
timerOnce sync.Once
|
||||
)
|
||||
|
||||
func init() {
|
||||
timerOnce.Do(func() {
|
||||
timerLoop = libuv.LoopNew()
|
||||
})
|
||||
go func() {
|
||||
timerLoop.Run(libuv.RUN_DEFAULT)
|
||||
}()
|
||||
}
|
||||
// func init() {
|
||||
// timerOnce.Do(func() {
|
||||
// timerLoop = libuv.LoopNew()
|
||||
// })
|
||||
// go func() {
|
||||
// timerLoop.Run(libuv.RUN_DEFAULT)
|
||||
// }()
|
||||
// }
|
||||
|
||||
// cross thread
|
||||
func timerEvent(async *libuv.Async) {
|
||||
a := (*asyncTimerEvent)(unsafe.Pointer(async))
|
||||
a.cb()
|
||||
a.Close(nil)
|
||||
}
|
||||
// func timerEvent(async *libuv.Async) {
|
||||
// a := (*asyncTimerEvent)(unsafe.Pointer(async))
|
||||
// a.cb()
|
||||
// a.Close(nil)
|
||||
// }
|
||||
|
||||
type asyncTimerEvent struct {
|
||||
libuv.Async
|
||||
// libuv.Async
|
||||
cb func()
|
||||
}
|
||||
|
||||
func timerCallback(t *libuv.Timer) {
|
||||
}
|
||||
// func timerCallback(t *libuv.Timer) {
|
||||
// }
|
||||
|
||||
func startTimer(r *runtimeTimer) {
|
||||
asyncTimer := &asyncTimerEvent{
|
||||
cb: func() {
|
||||
libuv.InitTimer(timerLoop, &r.Timer)
|
||||
r.Start(timerCallback, uint64(r.when), 0)
|
||||
},
|
||||
}
|
||||
timerLoop.Async(&asyncTimer.Async, timerEvent)
|
||||
asyncTimer.Send()
|
||||
panic("not implemented")
|
||||
// asyncTimer := &asyncTimerEvent{
|
||||
// cb: func() {
|
||||
// libuv.InitTimer(timerLoop, &r.Timer)
|
||||
// r.Start(timerCallback, uint64(r.when), 0)
|
||||
// },
|
||||
// }
|
||||
// timerLoop.Async(&asyncTimer.Async, timerEvent)
|
||||
// asyncTimer.Send()
|
||||
}
|
||||
|
||||
func stopTimer(r *runtimeTimer) bool {
|
||||
asyncTimer := &asyncTimerEvent{
|
||||
cb: func() {
|
||||
r.Stop()
|
||||
},
|
||||
}
|
||||
timerLoop.Async(&asyncTimer.Async, timerEvent)
|
||||
return asyncTimer.Send() == 0
|
||||
panic("not implemented")
|
||||
// asyncTimer := &asyncTimerEvent{
|
||||
// cb: func() {
|
||||
// r.Stop()
|
||||
// },
|
||||
// }
|
||||
// timerLoop.Async(&asyncTimer.Async, timerEvent)
|
||||
// return asyncTimer.Send() == 0
|
||||
}
|
||||
|
||||
func resetTimer(r *runtimeTimer, when int64) bool {
|
||||
asyncTimer := &asyncTimerEvent{
|
||||
cb: func() {
|
||||
r.Stop()
|
||||
r.Start(timerCallback, uint64(when), 0)
|
||||
},
|
||||
}
|
||||
timerLoop.Async(&asyncTimer.Async, timerEvent)
|
||||
return asyncTimer.Send() == 0
|
||||
panic("not implemented")
|
||||
// asyncTimer := &asyncTimerEvent{
|
||||
// cb: func() {
|
||||
// r.Stop()
|
||||
// r.Start(timerCallback, uint64(when), 0)
|
||||
// },
|
||||
// }
|
||||
// timerLoop.Async(&asyncTimer.Async, timerEvent)
|
||||
// return asyncTimer.Send() == 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user