Skip to content

Commit

Permalink
index-pack: guard nr_resolved_deltas reads by lock
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Thomas Rast authored and Junio C Hamano committed Mar 19, 2013
1 parent 3aba2fd commit 8f82aad
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion builtin/index-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -967,8 +967,10 @@ static void *threaded_second_pass(void *data)
set_thread_data(data);
for (;;) {
int i;
work_lock();
counter_lock();
display_progress(progress, nr_resolved_deltas);
counter_unlock();
work_lock();
while (nr_dispatched < nr_objects &&
is_delta_type(objects[nr_dispatched].type))
nr_dispatched++;
Expand Down

0 comments on commit 8f82aad

Please sign in to comment.