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. --- index.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'index.go') diff --git a/index.go b/index.go index 4a69c1e..ac5148c 100644 --- a/index.go +++ b/index.go @@ -24,6 +24,9 @@ func (v *Index) AddByPath(path string) error { cstr := C.CString(path) defer C.free(unsafe.Pointer(cstr)) + runtime.LockOSThread() + defer runtime.UnlockOSThread() + ret := C.git_index_add_bypath(v.ptr, cstr) if ret < 0 { return LastError() @@ -34,6 +37,10 @@ func (v *Index) AddByPath(path string) error { func (v *Index) WriteTree() (*Oid, error) { oid := new(Oid) + + runtime.LockOSThread() + defer runtime.UnlockOSThread() + ret := C.git_index_write_tree(oid.toC(), v.ptr) if ret < 0 { return nil, LastError() -- cgit v1.2.3