pack-objects: move read mutex to packing_data struct
ac77d0c37 ("pack-objects: shrink size field in struct object_entry", 2018-04-14) added an extra usage of read_lock/read_unlock in the newly introduced oe_get_size_slow for thread safety in parallel calls to try_delta(). Unfortunately oe_get_size_slow is also used in serial code, some of which is called before the first invocation of ll_find_deltas. As such the read mutex is not guaranteed to be initialized. Resolve this by moving the read mutex to packing_data and initializing it in prepare_packing_data which is initialized in cmd_pack_objects. Signed-off-by: Patrick Hogg <phogg@novamoon.net> Reviewed-by: Duy Nguyen <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Hogg committed
Jan 24, 2019 at 19:22 UTC
459307b139c9a859ca0b6ca5276cf9be3d2b8e3e
3 files changed
+13
-5
builtin/pack-objects.c
+2
-5
@@ -1954,9 +1954,8 @@ static int delta_cacheable(unsigned long src_size, unsigned long trg_size,
1954
}
1955
1956
/* Protect access to object database */
1957
-static pthread_mutex_t read_mutex;
1958
-#define read_lock() pthread_mutex_lock(&read_mutex)
1959
-#define read_unlock() pthread_mutex_unlock(&read_mutex)
1957
+#define read_lock() packing_data_read_lock(&to_pack)
1958
+#define read_unlock() packing_data_read_unlock(&to_pack)
1959
1960
/* Protect delta_cache_size */
1961
static pthread_mutex_t cache_mutex;
@@ -2381,7 +2380,6 @@ static pthread_cond_t progress_cond;
2380
*/
2381
static void init_threaded_search(void)
2382
{
2384
- init_recursive_mutex(&read_mutex);
2383
pthread_mutex_init(&cache_mutex, NULL);
2384
pthread_mutex_init(&progress_mutex, NULL);
2385
pthread_cond_init(&progress_cond, NULL);
@@ -2392,7 +2390,6 @@ static void cleanup_threaded_search(void)
2390
{
2391
set_try_to_free_routine(old_try_to_free_routine);
2392
pthread_cond_destroy(&progress_cond);
2395
- pthread_mutex_destroy(&read_mutex);
2393
pthread_mutex_destroy(&cache_mutex);
2394
pthread_mutex_destroy(&progress_mutex);
2395
}
pack-objects.c
+1
@@ -150,6 +150,7 @@ void prepare_packing_data(struct packing_data *pdata)
150
1UL << OE_DELTA_SIZE_BITS);
151
#ifndef NO_PTHREADS
152
pthread_mutex_init(&pdata->lock, NULL);
153
+ init_recursive_mutex(&pdata->read_lock);
154
#endif
155
}
156
pack-objects.h
+10
@@ -146,6 +146,7 @@ struct packing_data {
146
struct packed_git **in_pack;
147
148
pthread_mutex_t lock;
149
+ pthread_mutex_t read_lock;
150
151
/*
152
* This list contains entries for bases which we know the other side
@@ -174,6 +175,15 @@ static inline void packing_data_unlock(struct packing_data *pdata)
175
pthread_mutex_unlock(&pdata->lock);
176
}
177
178
+static inline void packing_data_read_lock(struct packing_data *pdata)
179
+{
180
+ pthread_mutex_lock(&pdata->read_lock);
181
+}
182
+static inline void packing_data_read_unlock(struct packing_data *pdata)
183
+{
184
+ pthread_mutex_unlock(&pdata->read_lock);
185
+}
186
+
187
struct object_entry *packlist_alloc(struct packing_data *pdata,
188
const unsigned char *sha1,
189
uint32_t index_pos);