@matheusbsbs / matheus-bagliano / commits / 851c34b04e
Fork 0

Have set_try_to_free_routine return the previous routine

This effectively requires from the callers of set_try_to_free_routine to treat the try-to-free-routines as a stack. We will need this for the next patch where the only current caller cannot depend on that the previously set routine was the default routine. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Sixt committed May 8, 2010 at 17:13 UTC 851c34b04e0ce866e15c28e144986eca7533a6f4
3 files changed +10 -5
builtin-pack-objects.c
+4 -2
@@ -1556,6 +1556,8 @@ static void try_to_free_from_threads(size_t size)
1556 read_unlock();
1557 }
1558
1559 +try_to_free_t old_try_to_free_routine;
1560 +
1561 /*
1562 * The main thread waits on the condition that (at least) one of the workers
1563 * has stopped working (which is indicated in the .working member of
@@ -1590,12 +1592,12 @@ static void init_threaded_search(void)
1592 pthread_mutex_init(&cache_mutex, NULL);
1593 pthread_mutex_init(&progress_mutex, NULL);
1594 pthread_cond_init(&progress_cond, NULL);
1593 - set_try_to_free_routine(try_to_free_from_threads);
1595 + old_try_to_free_routine = set_try_to_free_routine(try_to_free_from_threads);
1596 }
1597
1598 static void cleanup_threaded_search(void)
1599 {
1598 - set_try_to_free_routine(NULL);
1600 + set_try_to_free_routine(old_try_to_free_routine);
1601 pthread_cond_destroy(&progress_cond);
1602 pthread_mutex_destroy(&read_mutex);
1603 pthread_mutex_destroy(&cache_mutex);
git-compat-util.h
+2 -1
@@ -346,7 +346,8 @@ static inline char *gitstrchrnul(const char *s, int c)
346
347 extern void release_pack_memory(size_t, int);
348
349 -extern void set_try_to_free_routine(void (*routine)(size_t));
349 +typedef void (*try_to_free_t)(size_t);
350 +extern try_to_free_t set_try_to_free_routine(try_to_free_t);
351
352 extern char *xstrdup(const char *str);
353 extern void *xmalloc(size_t size);
wrapper.c
+4 -2
@@ -10,9 +10,11 @@ static void try_to_free_builtin(size_t size)
10
11 static void (*try_to_free_routine)(size_t size) = try_to_free_builtin;
12
13 -void set_try_to_free_routine(void (*routine)(size_t))
13 +try_to_free_t set_try_to_free_routine(try_to_free_t routine)
14 {
15 - try_to_free_routine = (routine) ? routine : try_to_free_builtin;
15 + try_to_free_t old = try_to_free_routine;
16 + try_to_free_routine = routine;
17 + return old;
18 }
19
20 char *xstrdup(const char *str)