Merge branch 'ph/pack-objects-mutex-fix'
"git pack-objects" incorrectly used uninitialized mutex, which has been corrected. * ph/pack-objects-mutex-fix: pack-objects: merge read_lock and lock in packing_data struct pack-objects: move read mutex to packing_data struct
This commit is contained in:
@@ -1953,11 +1953,6 @@ static int delta_cacheable(unsigned long src_size, unsigned long trg_size,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Protect access to object database */
|
|
||||||
static pthread_mutex_t read_mutex;
|
|
||||||
#define read_lock() pthread_mutex_lock(&read_mutex)
|
|
||||||
#define read_unlock() pthread_mutex_unlock(&read_mutex)
|
|
||||||
|
|
||||||
/* Protect delta_cache_size */
|
/* Protect delta_cache_size */
|
||||||
static pthread_mutex_t cache_mutex;
|
static pthread_mutex_t cache_mutex;
|
||||||
#define cache_lock() pthread_mutex_lock(&cache_mutex)
|
#define cache_lock() pthread_mutex_lock(&cache_mutex)
|
||||||
@@ -1993,11 +1988,11 @@ unsigned long oe_get_size_slow(struct packing_data *pack,
|
|||||||
unsigned long used, avail, size;
|
unsigned long used, avail, size;
|
||||||
|
|
||||||
if (e->type_ != OBJ_OFS_DELTA && e->type_ != OBJ_REF_DELTA) {
|
if (e->type_ != OBJ_OFS_DELTA && e->type_ != OBJ_REF_DELTA) {
|
||||||
read_lock();
|
packing_data_lock(&to_pack);
|
||||||
if (oid_object_info(the_repository, &e->idx.oid, &size) < 0)
|
if (oid_object_info(the_repository, &e->idx.oid, &size) < 0)
|
||||||
die(_("unable to get size of %s"),
|
die(_("unable to get size of %s"),
|
||||||
oid_to_hex(&e->idx.oid));
|
oid_to_hex(&e->idx.oid));
|
||||||
read_unlock();
|
packing_data_unlock(&to_pack);
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2005,7 +2000,7 @@ unsigned long oe_get_size_slow(struct packing_data *pack,
|
|||||||
if (!p)
|
if (!p)
|
||||||
BUG("when e->type is a delta, it must belong to a pack");
|
BUG("when e->type is a delta, it must belong to a pack");
|
||||||
|
|
||||||
read_lock();
|
packing_data_lock(&to_pack);
|
||||||
w_curs = NULL;
|
w_curs = NULL;
|
||||||
buf = use_pack(p, &w_curs, e->in_pack_offset, &avail);
|
buf = use_pack(p, &w_curs, e->in_pack_offset, &avail);
|
||||||
used = unpack_object_header_buffer(buf, avail, &type, &size);
|
used = unpack_object_header_buffer(buf, avail, &type, &size);
|
||||||
@@ -2014,7 +2009,7 @@ unsigned long oe_get_size_slow(struct packing_data *pack,
|
|||||||
oid_to_hex(&e->idx.oid));
|
oid_to_hex(&e->idx.oid));
|
||||||
|
|
||||||
unuse_pack(&w_curs);
|
unuse_pack(&w_curs);
|
||||||
read_unlock();
|
packing_data_unlock(&to_pack);
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2076,9 +2071,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
|
|||||||
|
|
||||||
/* Load data if not already done */
|
/* Load data if not already done */
|
||||||
if (!trg->data) {
|
if (!trg->data) {
|
||||||
read_lock();
|
packing_data_lock(&to_pack);
|
||||||
trg->data = read_object_file(&trg_entry->idx.oid, &type, &sz);
|
trg->data = read_object_file(&trg_entry->idx.oid, &type, &sz);
|
||||||
read_unlock();
|
packing_data_unlock(&to_pack);
|
||||||
if (!trg->data)
|
if (!trg->data)
|
||||||
die(_("object %s cannot be read"),
|
die(_("object %s cannot be read"),
|
||||||
oid_to_hex(&trg_entry->idx.oid));
|
oid_to_hex(&trg_entry->idx.oid));
|
||||||
@@ -2089,9 +2084,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
|
|||||||
*mem_usage += sz;
|
*mem_usage += sz;
|
||||||
}
|
}
|
||||||
if (!src->data) {
|
if (!src->data) {
|
||||||
read_lock();
|
packing_data_lock(&to_pack);
|
||||||
src->data = read_object_file(&src_entry->idx.oid, &type, &sz);
|
src->data = read_object_file(&src_entry->idx.oid, &type, &sz);
|
||||||
read_unlock();
|
packing_data_unlock(&to_pack);
|
||||||
if (!src->data) {
|
if (!src->data) {
|
||||||
if (src_entry->preferred_base) {
|
if (src_entry->preferred_base) {
|
||||||
static int warned = 0;
|
static int warned = 0;
|
||||||
@@ -2337,9 +2332,9 @@ static void find_deltas(struct object_entry **list, unsigned *list_size,
|
|||||||
|
|
||||||
static void try_to_free_from_threads(size_t size)
|
static void try_to_free_from_threads(size_t size)
|
||||||
{
|
{
|
||||||
read_lock();
|
packing_data_lock(&to_pack);
|
||||||
release_pack_memory(size);
|
release_pack_memory(size);
|
||||||
read_unlock();
|
packing_data_unlock(&to_pack);
|
||||||
}
|
}
|
||||||
|
|
||||||
static try_to_free_t old_try_to_free_routine;
|
static try_to_free_t old_try_to_free_routine;
|
||||||
@@ -2381,7 +2376,6 @@ static pthread_cond_t progress_cond;
|
|||||||
*/
|
*/
|
||||||
static void init_threaded_search(void)
|
static void init_threaded_search(void)
|
||||||
{
|
{
|
||||||
init_recursive_mutex(&read_mutex);
|
|
||||||
pthread_mutex_init(&cache_mutex, NULL);
|
pthread_mutex_init(&cache_mutex, NULL);
|
||||||
pthread_mutex_init(&progress_mutex, NULL);
|
pthread_mutex_init(&progress_mutex, NULL);
|
||||||
pthread_cond_init(&progress_cond, NULL);
|
pthread_cond_init(&progress_cond, NULL);
|
||||||
@@ -2392,7 +2386,6 @@ static void cleanup_threaded_search(void)
|
|||||||
{
|
{
|
||||||
set_try_to_free_routine(old_try_to_free_routine);
|
set_try_to_free_routine(old_try_to_free_routine);
|
||||||
pthread_cond_destroy(&progress_cond);
|
pthread_cond_destroy(&progress_cond);
|
||||||
pthread_mutex_destroy(&read_mutex);
|
|
||||||
pthread_mutex_destroy(&cache_mutex);
|
pthread_mutex_destroy(&cache_mutex);
|
||||||
pthread_mutex_destroy(&progress_mutex);
|
pthread_mutex_destroy(&progress_mutex);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,9 +150,7 @@ void prepare_packing_data(struct repository *r, struct packing_data *pdata)
|
|||||||
1U << OE_SIZE_BITS);
|
1U << OE_SIZE_BITS);
|
||||||
pdata->oe_delta_size_limit = git_env_ulong("GIT_TEST_OE_DELTA_SIZE",
|
pdata->oe_delta_size_limit = git_env_ulong("GIT_TEST_OE_DELTA_SIZE",
|
||||||
1UL << OE_DELTA_SIZE_BITS);
|
1UL << OE_DELTA_SIZE_BITS);
|
||||||
#ifndef NO_PTHREADS
|
init_recursive_mutex(&pdata->odb_lock);
|
||||||
pthread_mutex_init(&pdata->lock, NULL);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct object_entry *packlist_alloc(struct packing_data *pdata,
|
struct object_entry *packlist_alloc(struct packing_data *pdata,
|
||||||
|
|||||||
@@ -148,7 +148,11 @@ struct packing_data {
|
|||||||
struct packed_git **in_pack_by_idx;
|
struct packed_git **in_pack_by_idx;
|
||||||
struct packed_git **in_pack;
|
struct packed_git **in_pack;
|
||||||
|
|
||||||
pthread_mutex_t lock;
|
/*
|
||||||
|
* During packing with multiple threads, protect the in-core
|
||||||
|
* object database from concurrent accesses.
|
||||||
|
*/
|
||||||
|
pthread_mutex_t odb_lock;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This list contains entries for bases which we know the other side
|
* This list contains entries for bases which we know the other side
|
||||||
@@ -168,13 +172,14 @@ struct packing_data {
|
|||||||
|
|
||||||
void prepare_packing_data(struct repository *r, struct packing_data *pdata);
|
void prepare_packing_data(struct repository *r, struct packing_data *pdata);
|
||||||
|
|
||||||
|
/* Protect access to object database */
|
||||||
static inline void packing_data_lock(struct packing_data *pdata)
|
static inline void packing_data_lock(struct packing_data *pdata)
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&pdata->lock);
|
pthread_mutex_lock(&pdata->odb_lock);
|
||||||
}
|
}
|
||||||
static inline void packing_data_unlock(struct packing_data *pdata)
|
static inline void packing_data_unlock(struct packing_data *pdata)
|
||||||
{
|
{
|
||||||
pthread_mutex_unlock(&pdata->lock);
|
pthread_mutex_unlock(&pdata->odb_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct object_entry *packlist_alloc(struct packing_data *pdata,
|
struct object_entry *packlist_alloc(struct packing_data *pdata,
|
||||||
|
|||||||
Reference in New Issue
Block a user