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. --- checkout.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'checkout.go') diff --git a/checkout.go b/checkout.go index 63637e2..f4c1d4e 100644 --- a/checkout.go +++ b/checkout.go @@ -9,6 +9,7 @@ git_checkout_opts git_checkout_opts_init() { */ import "C" import ( + "runtime" "os" ) @@ -59,6 +60,9 @@ func (v *Repository) Checkout(opts *CheckoutOpts) error { var copts C.git_checkout_opts populateCheckoutOpts(&copts, opts) + runtime.LockOSThread() + defer runtime.UnlockOSThread() + ret := C.git_checkout_head(v.ptr, &copts) if ret < 0 { return LastError() @@ -72,6 +76,9 @@ func (v *Repository) CheckoutIndex(index *Index, opts *CheckoutOpts) error { var copts C.git_checkout_opts populateCheckoutOpts(&copts, opts) + runtime.LockOSThread() + defer runtime.UnlockOSThread() + ret := C.git_checkout_index(v.ptr, index.ptr, &copts) if ret < 0 { return LastError() -- cgit v1.2.3