6
c/pthread/sync/_pthd/pthd.c
Normal file
6
c/pthread/sync/_pthd/pthd.c
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
pthread_once_t llgoSyncOnceInitVal() {
|
||||||
|
pthread_once_t initVal = PTHREAD_ONCE_INIT;
|
||||||
|
return initVal;
|
||||||
|
}
|
||||||
BIN
c/pthread/sync/llgo_autogen.lla
Normal file
BIN
c/pthread/sync/llgo_autogen.lla
Normal file
Binary file not shown.
41
c/pthread/sync/sync.go
Normal file
41
c/pthread/sync/sync.go
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package sync
|
||||||
|
|
||||||
|
// #include <pthread.h>
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "unsafe"
|
||||||
|
|
||||||
|
"github.com/goplus/llgo/c"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
LLGoFiles = "_pthd/pthd.c"
|
||||||
|
LLGoPackage = "link"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Once C.pthread_once_t
|
||||||
|
|
||||||
|
//go:linkname onceInitVal C.llgoSyncOnceInitVal
|
||||||
|
func onceInitVal() Once
|
||||||
|
|
||||||
|
var OnceInit = onceInitVal()
|
||||||
|
|
||||||
|
// llgo:link (*Once).Do C.pthread_once
|
||||||
|
func (o *Once) Do(f func()) c.Int { return 0 }
|
||||||
19
cl/_testlibc/once/in.go
Normal file
19
cl/_testlibc/once/in.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/goplus/llgo/c"
|
||||||
|
"github.com/goplus/llgo/c/pthread/sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
var once sync.Once = sync.OnceInit
|
||||||
|
|
||||||
|
func f() {
|
||||||
|
once.Do(func() {
|
||||||
|
c.Printf(c.Str("Do once\n"))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
f()
|
||||||
|
f()
|
||||||
|
}
|
||||||
1
cl/_testlibc/once/out.ll
Normal file
1
cl/_testlibc/once/out.ll
Normal file
@@ -0,0 +1 @@
|
|||||||
|
;
|
||||||
@@ -597,7 +597,7 @@ func llgoPkgLinkFiles(pkg *packages.Package, llFile string, procFile func(linkFi
|
|||||||
|
|
||||||
// files = "file1; file2; ..."
|
// files = "file1; file2; ..."
|
||||||
func clFiles(files string, pkg *packages.Package, procFile func(linkFile string), verbose bool) {
|
func clFiles(files string, pkg *packages.Package, procFile func(linkFile string), verbose bool) {
|
||||||
dir := filepath.Dir(pkg.CompiledGoFiles[0])
|
dir := filepath.Dir(pkg.GoFiles[0])
|
||||||
expFile := pkg.ExportFile
|
expFile := pkg.ExportFile
|
||||||
for _, file := range strings.Split(files, ";") {
|
for _, file := range strings.Split(files, ";") {
|
||||||
cFile := filepath.Join(dir, strings.TrimSpace(file))
|
cFile := filepath.Join(dir, strings.TrimSpace(file))
|
||||||
|
|||||||
Reference in New Issue
Block a user