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. --- odb.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'odb.go') diff --git a/odb.go b/odb.go index eaa7872..638ef74 100644 --- a/odb.go +++ b/odb.go @@ -25,6 +25,10 @@ func (v *Odb) Exists(oid *Oid) bool { func (v *Odb) Write(data []byte, otype ObjectType) (oid *Oid, err error) { oid = new(Oid) hdr := (*reflect.SliceHeader)(unsafe.Pointer(&data)) + + runtime.LockOSThread() + defer runtime.UnlockOSThread() + ret := C.git_odb_write(oid.toC(), v.ptr, unsafe.Pointer(hdr.Data), C.size_t(hdr.Len), C.git_otype(otype)) if ret < 0 { @@ -36,6 +40,10 @@ func (v *Odb) Write(data []byte, otype ObjectType) (oid *Oid, err error) { func (v *Odb) Read(oid *Oid) (obj *OdbObject, err error) { obj = new(OdbObject) + + runtime.LockOSThread() + defer runtime.UnlockOSThread() + ret := C.git_odb_read(&obj.ptr, v.ptr, oid.toC()) if ret < 0 { return nil, LastError() -- cgit v1.2.3