cl: compileFuncDecl/funcName fix; patch library: sync

This commit is contained in:
xushiwei
2024-06-17 18:32:58 +08:00
parent bec29f99e6
commit 98f3e45c0a
6 changed files with 76 additions and 11 deletions

View File

@@ -18,5 +18,39 @@ package sync
// llgo:skipall
import (
_ "unsafe"
"unsafe"
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/c/pthread"
"github.com/goplus/llgo/c/pthread/sync"
)
const (
LLGoPackage = "link"
)
// -----------------------------------------------------------------------------
var onceParam pthread.Key
func init() {
onceParam.Create(nil)
}
type Once sync.Once
func (o *Once) Do(f func()) {
ptr := c.Malloc(unsafe.Sizeof(f))
*(*func())(ptr) = f
onceParam.Set(ptr)
if *(*c.Long)(unsafe.Pointer(o)) == 0 { // try init
*(*sync.Once)(o) = sync.OnceInit
}
(*sync.Once)(o).Do(func() {
ptr := onceParam.Get()
(*(*func())(ptr))()
c.Free(ptr)
})
}
// -----------------------------------------------------------------------------