200
int i;
201
202
pthread_mutex_init(&grep_mutex, NULL);
203
- pthread_mutex_init(&grep_read_mutex, NULL);
203
pthread_mutex_init(&grep_attr_mutex, NULL);
204
pthread_cond_init(&cond_add, NULL);
205
pthread_cond_init(&cond_write, NULL);
206
pthread_cond_init(&cond_result, NULL);
207
grep_use_locks = 1;
208
+ enable_obj_read_lock();
209
210
for (i = 0; i < ARRAY_SIZE(todo); i++) {
211
strbuf_init(&todo[i].out, 0);
257
free(threads);
258
259
pthread_mutex_destroy(&grep_mutex);
260
- pthread_mutex_destroy(&grep_read_mutex);
260
pthread_mutex_destroy(&grep_attr_mutex);
261
pthread_cond_destroy(&cond_add);
262
pthread_cond_destroy(&cond_write);
263
pthread_cond_destroy(&cond_result);
264
grep_use_locks = 0;
265
+ disable_obj_read_lock();
266
267
return hit;
268
}
295
return st;
296
}
297
298
-static void *lock_and_read_oid_file(const struct object_id *oid, enum object_type *type, unsigned long *size)
299
-{
300
- void *data;
301
-
302
- grep_read_lock();
303
- data = read_object_file(oid, type, size);
304
- grep_read_unlock();
305
- return data;
306
-}
307
-
298
static int grep_oid(struct grep_opt *opt, const struct object_id *oid,
299
const char *filename, int tree_name_len,
300
const char *path)
403
404
/*
405
* NEEDSWORK: submodules functions need to be protected because they
416
- * access the object store via config_from_gitmodules(): the latter
417
- * uses get_oid() which, for now, relies on the global the_repository
418
- * object.
406
+ * call config_from_gitmodules(): the latter contains in its call stack
407
+ * many thread-unsafe operations that are racy with object reading, such
408
+ * as parse_object() and is_promisor_object().
409
*/
420
- grep_read_lock();
410
+ obj_read_lock();
411
sub = submodule_from_path(superproject, &null_oid, path);
412
413
if (!is_submodule_active(superproject, path)) {
424
- grep_read_unlock();
414
+ obj_read_unlock();
415
return 0;
416
}
417
418
if (repo_submodule_init(&subrepo, superproject, sub)) {
429
- grep_read_unlock();
419
+ obj_read_unlock();
420
return 0;
421
}
422
433
* object.
434
*/
435
add_to_alternates_memory(subrepo.objects->odb->path);
446
- grep_read_unlock();
436
+ obj_read_unlock();
437
438
memcpy(&subopt, opt, sizeof(subopt));
439
subopt.repo = &subrepo;
445
unsigned long size;
446
struct strbuf base = STRBUF_INIT;
447
458
- grep_read_lock();
448
+ obj_read_lock();
449
object = parse_object_or_die(oid, oid_to_hex(oid));
450
+ obj_read_unlock();
451
data = read_object_with_reference(&subrepo,
452
&object->oid, tree_type,
453
&size, NULL);
463
- grep_read_unlock();
464
-
454
if (!data)
455
die(_("unable to read tree (%s)"), oid_to_hex(&object->oid));
456
575
void *data;
576
unsigned long size;
577
589
- data = lock_and_read_oid_file(&entry.oid, &type, &size);
578
+ data = read_object_file(&entry.oid, &type, &size);
579
if (!data)
580
die(_("unable to read tree (%s)"),
581
oid_to_hex(&entry.oid));
613
struct strbuf base;
614
int hit, len;
615
627
- grep_read_lock();
616
data = read_object_with_reference(opt->repo,
617
&obj->oid, tree_type,
618
&size, NULL);
631
- grep_read_unlock();
632
-
619
if (!data)
620
die(_("unable to read tree (%s)"), oid_to_hex(&obj->oid));
621
645
for (i = 0; i < nr; i++) {
646
struct object *real_obj;
647
662
- grep_read_lock();
648
+ obj_read_lock();
649
real_obj = deref_tag(opt->repo, list->objects[i].item,
650
NULL, 0);
665
- grep_read_unlock();
651
+ obj_read_unlock();
652
653
/* load the gitmodules file for this rev */
654
if (recurse_submodules) {
655
submodule_free(opt->repo);
670
- grep_read_lock();
656
+ obj_read_lock();
657
gitmodules_config_oid(&real_obj->oid);
672
- grep_read_unlock();
658
+ obj_read_unlock();
659
}
660
if (grep_object(opt, pathspec, real_obj, list->objects[i].name,
661
list->objects[i].path)) {