From a40bdfd4202db244bfc5da348a0f0c528ef122cd Mon Sep 17 00:00:00 2001 From: Carlos Martín Nieto Date: Wed, 18 Sep 2013 09:23:47 +0200 Subject: 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. --- config.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'config.go') diff --git a/config.go b/config.go index 7235716..2aa073a 100644 --- a/config.go +++ b/config.go @@ -19,6 +19,9 @@ func (c *Config) LookupInt32(name string) (v int32, err error) { cname := C.CString(name) defer C.free(unsafe.Pointer(cname)) + runtime.LockOSThread() + defer runtime.UnlockOSThread() + ret := C.git_config_get_int32(&out, c.ptr, cname) if ret < 0 { return 0, LastError() @@ -32,6 +35,9 @@ func (c *Config) LookupInt64(name string) (v int64, err error) { cname := C.CString(name) defer C.free(unsafe.Pointer(cname)) + runtime.LockOSThread() + defer runtime.UnlockOSThread() + ret := C.git_config_get_int64(&out, c.ptr, cname) if ret < 0 { return 0, LastError() @@ -45,6 +51,9 @@ func (c *Config) LookupString(name string) (v string, err error) { cname := C.CString(name) defer C.free(unsafe.Pointer(cname)) + runtime.LockOSThread() + defer runtime.UnlockOSThread() + ret := C.git_config_get_string(&ptr, c.ptr, cname) if ret < 0 { return "", LastError() @@ -60,6 +69,9 @@ func (c *Config) Set(name, value string) (err error) { cvalue := C.CString(value) defer C.free(unsafe.Pointer(cvalue)) + runtime.LockOSThread() + defer runtime.UnlockOSThread() + ret := C.git_config_set_string(c.ptr, cname, cvalue) if ret < 0 { return LastError() -- cgit v1.2.3