Skip to content

Commit ec957d3

Browse files
author
Vicent Martí
authored
Merge pull request #650 from tenderlove/no-gvl-on-diff
Unlock GVL around `git_diff_tree_to_tree`
2 parents a0a4cc9 + 70bcbb3 commit ec957d3

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

ext/rugged/rugged_tree.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#include "rugged.h"
9+
#include <ruby/thread.h>
910

1011
extern VALUE rb_mRugged;
1112
extern VALUE rb_cRuggedObject;
@@ -363,13 +364,31 @@ static VALUE rb_git_diff_tree_to_index(VALUE self, VALUE rb_repo, VALUE rb_self,
363364
return rugged_diff_new(rb_cRuggedDiff, rb_repo, diff);
364365
}
365366

367+
struct nogvl_diff_args {
368+
git_repository * repo;
369+
git_tree * tree;
370+
git_tree * other_tree;
371+
git_diff_options * opts;
372+
int error;
373+
};
374+
375+
static void * rb_git_diff_tree_to_tree_nogvl(void * _args)
376+
{
377+
struct nogvl_diff_args * args;
378+
git_diff *diff = NULL;
379+
380+
args = (struct nogvl_diff_args *)_args;
381+
args->error = git_diff_tree_to_tree(&diff, args->repo, args->tree, args->other_tree, args->opts);
382+
return diff;
383+
}
384+
366385
static VALUE rb_git_diff_tree_to_tree(VALUE self, VALUE rb_repo, VALUE rb_tree, VALUE rb_other_tree, VALUE rb_options) {
367386
git_tree *tree = NULL;
368387
git_tree *other_tree = NULL;
369388
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
370389
git_repository *repo = NULL;
371390
git_diff *diff = NULL;
372-
int error;
391+
struct nogvl_diff_args args;
373392

374393
Data_Get_Struct(rb_repo, git_repository, repo);
375394
Data_Get_Struct(rb_tree, git_tree, tree);
@@ -379,10 +398,15 @@ static VALUE rb_git_diff_tree_to_tree(VALUE self, VALUE rb_repo, VALUE rb_tree,
379398

380399
rugged_parse_diff_options(&opts, rb_options);
381400

382-
error = git_diff_tree_to_tree(&diff, repo, tree, other_tree, &opts);
401+
args.repo = repo;
402+
args.tree = tree;
403+
args.other_tree = other_tree;
404+
args.opts = &opts;
405+
406+
diff = rb_thread_call_without_gvl(rb_git_diff_tree_to_tree_nogvl, &args, RUBY_UBF_PROCESS, NULL);
383407

384408
xfree(opts.pathspec.strings);
385-
rugged_exception_check(error);
409+
rugged_exception_check(args.error);
386410

387411
return rugged_diff_new(rb_cRuggedDiff, rb_repo, diff);
388412
}

0 commit comments

Comments
 (0)