diff options
| author | Carlos Martín Nieto <[email protected]> | 2013-09-18 09:23:47 +0200 |
|---|---|---|
| committer | Carlos Martín Nieto <[email protected]> | 2013-12-18 16:18:32 +0100 |
| commit | a40bdfd4202db244bfc5da348a0f0c528ef122cd (patch) | |
| tree | 115fcae49287c82eb55bb275cbbd4556fbed72b7 /git.go | |
| parent | 625ffd022e2c39f3820543cc1239deeb21837266 (diff) | |
Lock the OS thread when acessing errors
The library stores error information in thread-local storage, which
means we need to make sure that the Go runtime doesn't switch OS
threads between the time we call a function and th time we attempt to
retrieve the error information.
Diffstat (limited to 'git.go')
| -rw-r--r-- | git.go | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -9,6 +9,7 @@ import "C" import ( "bytes" "errors" + "runtime" "unsafe" "strings" ) @@ -57,6 +58,9 @@ func NewOidFromString(s string) (*Oid, error) { cs := C.CString(s) defer C.free(unsafe.Pointer(cs)) + runtime.LockOSThread() + defer runtime.UnlockOSThread() + if C.git_oid_fromstr(o.toC(), cs) < 0 { return nil, LastError() } @@ -109,6 +113,10 @@ func ShortenOids(ids []*Oid, minlen int) (int, error) { defer C.git_oid_shorten_free(shorten) var ret C.int + + runtime.LockOSThread() + defer runtime.UnlockOSThread() + for _, id := range ids { buf := make([]byte, 41) C.git_oid_fmt((*C.char)(unsafe.Pointer(&buf[0])), id.toC()) @@ -162,6 +170,9 @@ func Discover(start string, across_fs bool, ceiling_dirs []string) (string, erro retpath := (*C.char)(C.malloc(C.GIT_PATH_MAX)) defer C.free(unsafe.Pointer(retpath)) + runtime.LockOSThread() + defer runtime.UnlockOSThread() + r := C.git_repository_discover(retpath, C.GIT_PATH_MAX, cstart, cbool(across_fs), ceildirs) if r == 0 { |
