diff options
author | Nicolas Pitre <nico@fluxnic.net> | 2010-03-24 16:22:34 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-03-24 14:15:09 -0700 |
commit | a9a746364bd26d333c7229c6f7e851b507cd284a (patch) | |
tree | 72116fd86230efbfdd21f0fa78e68cb8a88a2a2d /builtin-pack-objects.c | |
parent | 846b8f681a0a75cec2b930007c84e98346940459 (diff) | |
download | git-a9a746364bd26d333c7229c6f7e851b507cd284a.tar.gz |
Make xmalloc and xrealloc thread-safe
By providing a hook for the routine responsible for trying to free some
memory on malloc failure, we can ensure that the called routine is
protected by the appropriate locks when threads are in play.
The obvious offender here was pack-objects which was calling xmalloc()
within threads while release_pack_memory() is not thread safe.
Signed-off-by: Nicolas Pitre <nico@fluxnic.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-pack-objects.c')
-rw-r--r-- | builtin-pack-objects.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index 539e75d56f..0ecc198422 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -1549,6 +1549,13 @@ static void find_deltas(struct object_entry **list, unsigned *list_size, #ifndef NO_PTHREADS +static void try_to_free_from_threads(size_t size) +{ + read_lock(); + release_pack_memory(size, -1); + read_unlock(); +} + /* * The main thread waits on the condition that (at least) one of the workers * has stopped working (which is indicated in the .working member of @@ -1583,10 +1590,12 @@ static void init_threaded_search(void) pthread_mutex_init(&cache_mutex, NULL); pthread_mutex_init(&progress_mutex, NULL); pthread_cond_init(&progress_cond, NULL); + set_try_to_free_routine(try_to_free_from_threads); } static void cleanup_threaded_search(void) { + set_try_to_free_routine(NULL); pthread_cond_destroy(&progress_cond); pthread_mutex_destroy(&read_mutex); pthread_mutex_destroy(&cache_mutex); |