當前位置: 首頁>>代碼示例>>Golang>>正文


Golang runtime.UnlockOSThread函數代碼示例

本文整理匯總了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
}
開發者ID:carriercomm,項目名稱:mantle,代碼行數:28,代碼來源:nsenter.go

示例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
	}
}
開發者ID:xushiwei,項目名稱:go-opencv,代碼行數:29,代碼來源:highgui.go

示例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)
		}
	}
}
開發者ID:winsx,項目名稱:libnetwork,代碼行數:35,代碼來源:sandbox_linux_test.go

示例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
}
開發者ID:jingweno,項目名稱:git2go,代碼行數:27,代碼來源:reference.go

示例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
}
開發者ID:jezell,項目名稱:git2go,代碼行數:28,代碼來源:clone.go

示例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
}
開發者ID:jezell,項目名稱:git2go,代碼行數:28,代碼來源:branch.go

示例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
}
開發者ID:ianlancetaylor,項目名稱:git2go,代碼行數:29,代碼來源:merge.go

示例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))
}
開發者ID:AdamOssenford,項目名稱:docker-pi,代碼行數:26,代碼來源:sandbox.go

示例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()
}
開發者ID:2722,項目名稱:lantern,代碼行數:9,代碼來源:context_darwin_amd64.go

示例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
}
開發者ID:wid,項目名稱:git2go,代碼行數:33,代碼來源:index.go

示例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
}
開發者ID:wid,項目名稱:git2go,代碼行數:25,代碼來源:index.go

示例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()
	}
}
開發者ID:kebo,項目名稱:gorgasm,代碼行數:27,代碼來源:runner.go

示例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

}
開發者ID:juniorchandler,項目名稱:git2go,代碼行數:35,代碼來源:merge.go

示例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
}
開發者ID:rjeczalik,項目名稱:git2go,代碼行數:25,代碼來源:index.go

示例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
}
開發者ID:wid,項目名稱:git2go,代碼行數:28,代碼來源:clone.go


注:本文中的runtime.UnlockOSThread函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。