testlibgo: sync (to do)

This commit is contained in:
xushiwei
2024-06-17 19:30:59 +08:00
parent 592500cb0c
commit 6442279a44
11 changed files with 116 additions and 112 deletions

View File

@@ -46,11 +46,14 @@ func (o *Once) Do(f func()) {
if *(*c.Long)(unsafe.Pointer(o)) == 0 { // try init
*(*sync.Once)(o) = sync.OnceInit
}
(*sync.Once)(o).Do(func() {
onceDo(o, func() {
ptr := onceParam.Get()
(*(*func())(ptr))()
c.Free(ptr)
})
}
//go:linkname onceDo C.pthread_once
func onceDo(o *Once, f func()) c.Int
// -----------------------------------------------------------------------------