index-pack: guard nr_resolved_deltas reads by lock

The threaded parts of index-pack increment the number of resolved deltas in nr_resolved_deltas guarded by counter_mutex. However, the per-thread outer loop accessed nr_resolved_deltas without any locks. This is not wrong as such, since it doesn't matter all that much whether we get an outdated value. However, unless someone proves that this one lock makes all the performance difference, it would be much cleaner to guard _all_ accesses to the variable with the lock. The only such use is display_progress() in the threaded section (all others are in the conclude_pack() callchain outside the threaded part). To make it obvious that it cannot deadlock, move it out of work_mutex. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Reviewed-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Rast committed Mar 19, 2013 at 15:16 UTC 8f82aad4e7baf32942eb2087a882e0f8646b2da8
1 file changed +3 -1
builtin/index-pack.c
+3 -1
@@ -967,8 +967,10 @@ static void *threaded_second_pass(void *data)
967 set_thread_data(data);
968 for (;;) {
969 int i;
970 - work_lock();
970 + counter_lock();
971 display_progress(progress, nr_resolved_deltas);
972 + counter_unlock();
973 + work_lock();
974 while (nr_dispatched < nr_objects &&
975 is_delta_type(objects[nr_dispatched].type))
976 nr_dispatched++;