本文整理汇总了Golang中runtime.UnlockOSThread函数的典型用法代码示例。如果您正苦于以下问题:Golang UnlockOSThread函数的具体用法?Golang UnlockOSThread怎么用?Golang UnlockOSThread使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了UnlockOSThread函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NsEnter
// NsEnter locks the current goroutine the OS thread and switches to a
// new network namespace. The returned function must be called in order
// to restore the previous state and unlock the thread.
func NsEnter(ns netns.NsHandle) (func() error, error) {
runtime.LockOSThread()
origns, err := netns.Get()
if err != nil {
runtime.UnlockOSThread()
return nil, err
}
err = netns.Set(ns)
if err != nil {
origns.Close()
runtime.UnlockOSThread()
return nil, err
}
return func() error {
defer runtime.UnlockOSThread()
defer origns.Close()
if err := netns.Set(origns); err != nil {
return err
}
return nil
}, nil
}
示例2: goMouseCallback
//export goMouseCallback
func goMouseCallback(name *C.char, event, x, y, flags C.int) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
winName := C.GoString(name)
win, ok := allWindows[winName]
if !ok {
return
}
if win.mouseHandle == nil {
return
}
if fa, ok := win.mouseHandle.(func(event, x, y, flags int)); ok {
fa(int(event), int(x), int(y), int(flags))
return
}
if fb, ok := win.mouseHandle.(func(event, x, y, flags int, param ...interface{})); ok {
if win.param != nil {
fb(int(event), int(x), int(y), int(flags), win.param...)
} else {
fb(int(event), int(x), int(y), int(flags))
}
return
}
}
示例3: verifySandbox
func verifySandbox(t *testing.T, s Sandbox, ifaceSuffixes []string) {
_, ok := s.(*networkNamespace)
if !ok {
t.Fatalf("The sandox interface returned is not of type networkNamespace")
}
origns, err := netns.Get()
if err != nil {
t.Fatalf("Could not get the current netns: %v", err)
}
defer origns.Close()
f, err := os.OpenFile(s.Key(), os.O_RDONLY, 0)
if err != nil {
t.Fatalf("Failed top open network namespace path %q: %v", s.Key(), err)
}
defer f.Close()
runtime.LockOSThread()
defer runtime.UnlockOSThread()
nsFD := f.Fd()
if err = netns.Set(netns.NsHandle(nsFD)); err != nil {
t.Fatalf("Setting to the namespace pointed to by the sandbox %s failed: %v", s.Key(), err)
}
defer netns.Set(origns)
for _, suffix := range ifaceSuffixes {
_, err = netlink.LinkByName(sboxIfaceName + suffix)
if err != nil {
t.Fatalf("Could not find the interface %s inside the sandbox: %v",
sboxIfaceName+suffix, err)
}
}
}
示例4: SetSymbolicTarget
func (v *Reference) SetSymbolicTarget(target string, sig *Signature, msg string) (*Reference, error) {
var ptr *C.git_reference
ctarget := C.CString(target)
defer C.free(unsafe.Pointer(ctarget))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
csig := sig.toC()
defer C.free(unsafe.Pointer(csig))
var cmsg *C.char
if msg == "" {
cmsg = nil
} else {
cmsg = C.CString(msg)
defer C.free(unsafe.Pointer(cmsg))
}
ret := C.git_reference_symbolic_set_target(&ptr, v.ptr, ctarget, csig, cmsg)
if ret < 0 {
return nil, MakeGitError(ret)
}
return newReferenceFromC(ptr), nil
}
示例5: Clone
func Clone(url string, path string, options *CloneOptions) (*Repository, error) {
repo := new(Repository)
curl := C.CString(url)
defer C.free(unsafe.Pointer(curl))
cpath := C.CString(path)
defer C.free(unsafe.Pointer(cpath))
var copts C.git_clone_options
populateCloneOptions(&copts, options)
defer freeCheckoutOpts(&copts.checkout_opts)
if len(options.CheckoutBranch) != 0 {
copts.checkout_branch = C.CString(options.CheckoutBranch)
defer C.free(unsafe.Pointer(copts.checkout_branch))
}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_clone(&repo.ptr, curl, cpath, &copts)
if ret < 0 {
return nil, MakeGitError(ret)
}
runtime.SetFinalizer(repo, (*Repository).Free)
return repo, nil
}
示例6: Move
func (b *Branch) Move(newBranchName string, force bool, signature *Signature, msg string) (*Branch, error) {
var ptr *C.git_reference
cNewBranchName := C.CString(newBranchName)
cForce := cbool(force)
cSignature, err := signature.toC()
if err != nil {
return nil, err
}
defer C.git_signature_free(cSignature)
var cmsg *C.char
if msg == "" {
cmsg = nil
} else {
cmsg = C.CString(msg)
defer C.free(unsafe.Pointer(cmsg))
}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_branch_move(&ptr, b.Reference.ptr, cNewBranchName, cForce, cSignature, cmsg)
if ret < 0 {
return nil, MakeGitError(ret)
}
return newReferenceFromC(ptr, b.repo).Branch(), nil
}
示例7: MergeBases
// MergeBases retrieves the list of merge bases between two commits.
//
// If none are found, an empty slice is returned and the error is set
// approprately
func (r *Repository) MergeBases(one, two *Oid) ([]*Oid, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
var coids C.git_oidarray
ret := C.git_merge_bases(&coids, r.ptr, one.toC(), two.toC())
if ret < 0 {
return make([]*Oid, 0), MakeGitError(ret)
}
oids := make([]*Oid, coids.count)
hdr := reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(coids.ids)),
Len: int(coids.count),
Cap: int(coids.count),
}
goSlice := *(*[]C.git_oid)(unsafe.Pointer(&hdr))
for i, cid := range goSlice {
oids[i] = newOidFromC(&cid)
}
return oids, nil
}
示例8: nsInvoke
func nsInvoke(path string, inNsfunc func(callerFD int) error) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
origns, err := netns.Get()
if err != nil {
return err
}
defer origns.Close()
f, err := os.OpenFile(path, os.O_RDONLY, 0)
if err != nil {
return fmt.Errorf("failed get network namespace %q: %v", path, err)
}
defer f.Close()
nsFD := f.Fd()
if err = netns.Set(netns.NsHandle(nsFD)); err != nil {
return err
}
defer netns.Set(origns)
// Invoked after the namespace switch.
return inNsfunc(int(origns))
}
示例9: destroy
// destroy destroys an OpenGL context and unlocks the current goroutine from
// its os thread.
func (c *contextGL) destroy() {
C.CGLUnlockContext(c.ctx)
C.CGLSetCurrentContext(nil)
C.CGLDestroyContext(c.ctx)
c.ctx = nil
runtime.UnlockOSThread()
}
示例10: AddConflict
func (v *Index) AddConflict(ancestor *IndexEntry, our *IndexEntry, their *IndexEntry) error {
var cancestor *C.git_index_entry
var cour *C.git_index_entry
var ctheir *C.git_index_entry
if ancestor != nil {
cancestor = &C.git_index_entry{}
populateCIndexEntry(ancestor, cancestor)
defer freeCIndexEntry(cancestor)
}
if our != nil {
cour = &C.git_index_entry{}
populateCIndexEntry(our, cour)
defer freeCIndexEntry(cour)
}
if their != nil {
ctheir = &C.git_index_entry{}
populateCIndexEntry(their, ctheir)
defer freeCIndexEntry(ctheir)
}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ecode := C.git_index_conflict_add(v.ptr, cancestor, cour, ctheir)
if ecode < 0 {
return MakeGitError(ecode)
}
return nil
}
示例11: RemoveAll
func (v *Index) RemoveAll(pathspecs []string, callback IndexMatchedPathCallback) error {
cpathspecs := C.git_strarray{}
cpathspecs.count = C.size_t(len(pathspecs))
cpathspecs.strings = makeCStringsFromStrings(pathspecs)
defer freeStrarray(&cpathspecs)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
var handle unsafe.Pointer
if callback != nil {
handle = pointerHandles.Track(callback)
defer pointerHandles.Untrack(handle)
}
ret := C._go_git_index_remove_all(
v.ptr,
&cpathspecs,
handle,
)
if ret < 0 {
return MakeGitError(ret)
}
return nil
}
示例12: main
func main() {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
defer glfw.Terminate()
gorgasm.Verbose = true
if !glfw.Init() {
panic("Can't init glfw!")
}
// Enable OpenGL ES 2.0.
glfw.WindowHint(glfw.ClientApi, glfw.OpenglEsApi)
glfw.WindowHint(glfw.ContextVersionMajor, 2)
window, err := glfw.CreateWindow(testlib.Width, testlib.Height, "Gorgasm Test", nil, nil)
if err != nil {
panic(err)
}
gorgasm.Init(window)
go prettytest.Run(new(testing.T), testlib.NewTestSuite())
for !window.ShouldClose() {
glfw.WaitEvents()
}
}
示例13: MergeFile
func MergeFile(ancestor MergeFileInput, ours MergeFileInput, theirs MergeFileInput, options *MergeFileOptions) (*MergeFileResult, error) {
var cancestor C.git_merge_file_input
var cours C.git_merge_file_input
var ctheirs C.git_merge_file_input
populateCMergeFileInput(&cancestor, ancestor)
defer freeCMergeFileInput(&cancestor)
populateCMergeFileInput(&cours, ours)
defer freeCMergeFileInput(&cours)
populateCMergeFileInput(&ctheirs, theirs)
defer freeCMergeFileInput(&ctheirs)
var copts *C.git_merge_file_options
if options != nil {
copts = &C.git_merge_file_options{}
ecode := C.git_merge_file_init_options(copts, C.GIT_MERGE_FILE_OPTIONS_VERSION)
if ecode < 0 {
return nil, MakeGitError(ecode)
}
populateCMergeFileOptions(copts, *options)
}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
var result C.git_merge_file_result
ecode := C.git_merge_file(&result, &cancestor, &cours, &ctheirs, copts)
if ecode < 0 {
return nil, MakeGitError(ecode)
}
return newMergeFileResultFromC(&result), nil
}
示例14: AddAll
func (v *Index) AddAll(pathspecs []string, flags IndexAddOpts, callback IndexMatchedPathCallback) error {
cpathspecs := C.git_strarray{}
cpathspecs.count = C.size_t(len(pathspecs))
cpathspecs.strings = makeCStringsFromStrings(pathspecs)
defer freeStrarray(&cpathspecs)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
var cb *IndexMatchedPathCallback
if callback != nil {
cb = &callback
}
ret := C._go_git_index_add_all(
v.ptr,
&cpathspecs,
C.uint(flags),
unsafe.Pointer(cb),
)
if ret < 0 {
return MakeGitError(ret)
}
return nil
}
示例15: Clone
func Clone(url string, path string, options *CloneOptions) (*Repository, error) {
curl := C.CString(url)
defer C.free(unsafe.Pointer(curl))
cpath := C.CString(path)
defer C.free(unsafe.Pointer(cpath))
copts := (*C.git_clone_options)(C.calloc(1, C.size_t(unsafe.Sizeof(C.git_clone_options{}))))
populateCloneOptions(copts, options)
defer freeCloneOptions(copts)
if len(options.CheckoutBranch) != 0 {
copts.checkout_branch = C.CString(options.CheckoutBranch)
}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
var ptr *C.git_repository
ret := C.git_clone(&ptr, curl, cpath, copts)
freeCheckoutOpts(&copts.checkout_opts)
if ret < 0 {
return nil, MakeGitError(ret)
}
return newRepositoryFromC(ptr), nil
}