Fix use of mutex in threaded grep
The program can decide at runtime not to use threading even if the support is compiled in. In such a case, mutexes are not necessary and left uninitialized. But the code incorrectly tried to take and release the read_sha1_mutex unconditionally. Signed-off-by: Junio C Hamano <gitster@pobox.com> Acked-by: Fredrik Kuivinen <frekui@gmail.com>maint
parent
b599672316
commit
5f02d31597
|
@ -408,15 +408,25 @@ static int pathspec_matches(const char **paths, const char *name, int max_depth)
|
||||||
return 0;
|
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,
|
static void *load_sha1(const unsigned char *sha1, unsigned long *size,
|
||||||
const char *name)
|
const char *name)
|
||||||
{
|
{
|
||||||
enum object_type type;
|
enum object_type type;
|
||||||
char *data;
|
void *data = lock_and_read_sha1_file(sha1, &type, size);
|
||||||
|
|
||||||
read_sha1_lock();
|
|
||||||
data = read_sha1_file(sha1, &type, size);
|
|
||||||
read_sha1_unlock();
|
|
||||||
|
|
||||||
if (!data)
|
if (!data)
|
||||||
error("'%s': unable to read %s", name, sha1_to_hex(sha1));
|
error("'%s': unable to read %s", name, sha1_to_hex(sha1));
|
||||||
|
@ -605,10 +615,7 @@ static int grep_tree(struct grep_opt *opt, const char **paths,
|
||||||
void *data;
|
void *data;
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
|
|
||||||
read_sha1_lock();
|
data = lock_and_read_sha1_file(entry.sha1, &type, &size);
|
||||||
data = read_sha1_file(entry.sha1, &type, &size);
|
|
||||||
read_sha1_unlock();
|
|
||||||
|
|
||||||
if (!data)
|
if (!data)
|
||||||
die("unable to read tree (%s)",
|
die("unable to read tree (%s)",
|
||||||
sha1_to_hex(entry.sha1));
|
sha1_to_hex(entry.sha1));
|
||||||
|
|
Loading…
Reference in New Issue