Skip to content

Commit

Permalink
Merge branch 'jc/maint-grep-one-thread-mutex-fix' into maint
Browse files Browse the repository at this point in the history
* jc/maint-grep-one-thread-mutex-fix:
  Fix use of mutex in threaded grep
  • Loading branch information
Junio C Hamano committed Feb 17, 2010
2 parents e7b3cea + 5f02d31 commit 354d9f8
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions builtin-grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,15 +408,25 @@ static int pathspec_matches(const char **paths, const char *name, int max_depth)
return 0;
}

static void *lock_and_read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size)
{
void *data;

if (use_threads) {
read_sha1_lock();
data = read_sha1_file(sha1, type, size);
read_sha1_unlock();
} else {
data = read_sha1_file(sha1, type, size);
}
return data;
}

static void *load_sha1(const unsigned char *sha1, unsigned long *size,
const char *name)
{
enum object_type type;
char *data;

read_sha1_lock();
data = read_sha1_file(sha1, &type, size);
read_sha1_unlock();
void *data = lock_and_read_sha1_file(sha1, &type, size);

if (!data)
error("'%s': unable to read %s", name, sha1_to_hex(sha1));
Expand Down Expand Up @@ -605,10 +615,7 @@ static int grep_tree(struct grep_opt *opt, const char **paths,
void *data;
unsigned long size;

read_sha1_lock();
data = read_sha1_file(entry.sha1, &type, &size);
read_sha1_unlock();

data = lock_and_read_sha1_file(entry.sha1, &type, &size);
if (!data)
die("unable to read tree (%s)",
sha1_to_hex(entry.sha1));
Expand Down

0 comments on commit 354d9f8

Please sign in to comment.