Skip to content

Commit f4df84d

Browse files
committed
Merge branch 'nd/index-pack-threaded-fixes' into maint
* nd/index-pack-threaded-fixes: index-pack: guard nr_resolved_deltas reads by lock index-pack: protect deepest_delta in multithread code
2 parents 68447f0 + 8f82aad commit f4df84d

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

builtin/index-pack.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ static int nr_threads;
7878
static int from_stdin;
7979
static int strict;
8080
static int verbose;
81+
static int show_stat;
8182

8283
static struct progress *progress;
8384

@@ -108,6 +109,10 @@ static pthread_mutex_t work_mutex;
108109
#define work_lock() lock_mutex(&work_mutex)
109110
#define work_unlock() unlock_mutex(&work_mutex)
110111

112+
static pthread_mutex_t deepest_delta_mutex;
113+
#define deepest_delta_lock() lock_mutex(&deepest_delta_mutex)
114+
#define deepest_delta_unlock() unlock_mutex(&deepest_delta_mutex)
115+
111116
static pthread_key_t key;
112117

113118
static inline void lock_mutex(pthread_mutex_t *mutex)
@@ -130,6 +135,8 @@ static void init_thread(void)
130135
init_recursive_mutex(&read_mutex);
131136
pthread_mutex_init(&counter_mutex, NULL);
132137
pthread_mutex_init(&work_mutex, NULL);
138+
if (show_stat)
139+
pthread_mutex_init(&deepest_delta_mutex, NULL);
133140
pthread_key_create(&key, NULL);
134141
thread_data = xcalloc(nr_threads, sizeof(*thread_data));
135142
threads_active = 1;
@@ -143,6 +150,8 @@ static void cleanup_thread(void)
143150
pthread_mutex_destroy(&read_mutex);
144151
pthread_mutex_destroy(&counter_mutex);
145152
pthread_mutex_destroy(&work_mutex);
153+
if (show_stat)
154+
pthread_mutex_destroy(&deepest_delta_mutex);
146155
pthread_key_delete(key);
147156
free(thread_data);
148157
}
@@ -158,6 +167,9 @@ static void cleanup_thread(void)
158167
#define work_lock()
159168
#define work_unlock()
160169

170+
#define deepest_delta_lock()
171+
#define deepest_delta_unlock()
172+
161173
#endif
162174

163175

@@ -833,9 +845,13 @@ static void resolve_delta(struct object_entry *delta_obj,
833845
void *base_data, *delta_data;
834846

835847
delta_obj->real_type = base->obj->real_type;
836-
delta_obj->delta_depth = base->obj->delta_depth + 1;
837-
if (deepest_delta < delta_obj->delta_depth)
838-
deepest_delta = delta_obj->delta_depth;
848+
if (show_stat) {
849+
delta_obj->delta_depth = base->obj->delta_depth + 1;
850+
deepest_delta_lock();
851+
if (deepest_delta < delta_obj->delta_depth)
852+
deepest_delta = delta_obj->delta_depth;
853+
deepest_delta_unlock();
854+
}
839855
delta_obj->base_object_no = base->obj - objects;
840856
delta_data = get_data_from_pack(delta_obj);
841857
base_data = get_base_data(base);
@@ -951,8 +967,10 @@ static void *threaded_second_pass(void *data)
951967
set_thread_data(data);
952968
for (;;) {
953969
int i;
954-
work_lock();
970+
counter_lock();
955971
display_progress(progress, nr_resolved_deltas);
972+
counter_unlock();
973+
work_lock();
956974
while (nr_dispatched < nr_objects &&
957975
is_delta_type(objects[nr_dispatched].type))
958976
nr_dispatched++;
@@ -1465,7 +1483,7 @@ static void show_pack_info(int stat_only)
14651483

14661484
int cmd_index_pack(int argc, const char **argv, const char *prefix)
14671485
{
1468-
int i, fix_thin_pack = 0, verify = 0, stat_only = 0, stat = 0;
1486+
int i, fix_thin_pack = 0, verify = 0, stat_only = 0;
14691487
const char *curr_pack, *curr_index;
14701488
const char *index_name = NULL, *pack_name = NULL;
14711489
const char *keep_name = NULL, *keep_msg = NULL;
@@ -1498,10 +1516,10 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
14981516
verify = 1;
14991517
} else if (!strcmp(arg, "--verify-stat")) {
15001518
verify = 1;
1501-
stat = 1;
1519+
show_stat = 1;
15021520
} else if (!strcmp(arg, "--verify-stat-only")) {
15031521
verify = 1;
1504-
stat = 1;
1522+
show_stat = 1;
15051523
stat_only = 1;
15061524
} else if (!strcmp(arg, "--keep")) {
15071525
keep_msg = "";
@@ -1609,7 +1627,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
16091627
if (strict)
16101628
check_objects();
16111629

1612-
if (stat)
1630+
if (show_stat)
16131631
show_pack_info(stat_only);
16141632

16151633
idx_objects = xmalloc((nr_objects) * sizeof(struct pack_idx_entry *));

0 commit comments

Comments
 (0)