From 520a0425c736c7d584d21d073b08a8735dd2464f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Sat, 6 Dec 2014 02:58:28 +0100 Subject: [PATCH] Add the newer missing thread-locking instances --- diff.go | 7 +++++++ odb.go | 14 ++++++++++++++ remote.go | 3 +++ 3 files changed, 24 insertions(+) diff --git a/diff.go b/diff.go index d7d8118..00f4bd5 100644 --- a/diff.go +++ b/diff.go @@ -179,6 +179,9 @@ func (diff *Diff) FindSimilar(opts *DiffFindOptions) error { } } + runtime.LockOSThread() + defer runtime.UnlockOSThread() + ecode := C.git_diff_find_similar(diff.ptr, copts) if ecode < 0 { return MakeGitError(ecode) @@ -404,6 +407,10 @@ type DiffFindOptions struct { func DefaultDiffFindOptions() (DiffFindOptions, error) { opts := C.git_diff_find_options{} + + runtime.LockOSThread() + defer runtime.UnlockOSThread() + ecode := C.git_diff_find_init_options(&opts, C.GIT_DIFF_FIND_OPTIONS_VERSION) if ecode < 0 { return DiffFindOptions{}, MakeGitError(ecode) diff --git a/odb.go b/odb.go index 9ea151b..9191656 100644 --- a/odb.go +++ b/odb.go @@ -168,6 +168,10 @@ func (v *Odb) NewReadStream(id *Oid) (*OdbReadStream, error) { // known in advance func (v *Odb) NewWriteStream(size int, otype ObjectType) (*OdbWriteStream, error) { stream := new(OdbWriteStream) + + runtime.LockOSThread() + defer runtime.UnlockOSThread() + ret := C.git_odb_open_wstream(&stream.ptr, v.ptr, C.size_t(size), C.git_otype(otype)) if ret < 0 { return nil, MakeGitError(ret) @@ -221,6 +225,10 @@ func (stream *OdbReadStream) Read(data []byte) (int, error) { header := (*reflect.SliceHeader)(unsafe.Pointer(&data)) ptr := (*C.char)(unsafe.Pointer(header.Data)) size := C.size_t(header.Cap) + + runtime.LockOSThread() + defer runtime.UnlockOSThread() + ret := C.git_odb_stream_read(stream.ptr, ptr, size) if ret < 0 { return 0, MakeGitError(ret) @@ -253,6 +261,9 @@ func (stream *OdbWriteStream) Write(data []byte) (int, error) { ptr := (*C.char)(unsafe.Pointer(header.Data)) size := C.size_t(header.Len) + runtime.LockOSThread() + defer runtime.UnlockOSThread() + ret := C.git_odb_stream_write(stream.ptr, ptr, size) if ret < 0 { return 0, MakeGitError(ret) @@ -264,6 +275,9 @@ func (stream *OdbWriteStream) Write(data []byte) (int, error) { // Close signals that all the data has been written and stores the // resulting object id in the stream's Id field. func (stream *OdbWriteStream) Close() error { + runtime.LockOSThread() + defer runtime.UnlockOSThread() + ret := C.git_odb_stream_finalize_write(stream.Id.toC(), stream.ptr) if ret < 0 { return MakeGitError(ret) diff --git a/remote.go b/remote.go index faff9c5..604ef40 100644 --- a/remote.go +++ b/remote.go @@ -610,6 +610,9 @@ func (o *Remote) Ls(filterRefs ...string) ([]RemoteHead, error) { var refs **C.git_remote_head var length C.size_t + runtime.LockOSThread() + defer runtime.UnlockOSThread() + if ret := C.git_remote_ls(&refs, &length, o.ptr); ret != 0 { return nil, MakeGitError(ret) }