Skip to content

Commit

Permalink
Have set_try_to_free_routine return the previous routine
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
j6t authored and gitster committed May 9, 2010
1 parent 9374919 commit 851c34b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 4 additions & 2 deletions builtin-pack-objects.c
Expand Up @@ -1556,6 +1556,8 @@ static void try_to_free_from_threads(size_t size)
read_unlock();
}

try_to_free_t old_try_to_free_routine;

/*
* 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
Expand Down Expand Up @@ -1590,12 +1592,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);
old_try_to_free_routine = set_try_to_free_routine(try_to_free_from_threads);
}

static void cleanup_threaded_search(void)
{
set_try_to_free_routine(NULL);
set_try_to_free_routine(old_try_to_free_routine);
pthread_cond_destroy(&progress_cond);
pthread_mutex_destroy(&read_mutex);
pthread_mutex_destroy(&cache_mutex);
Expand Down
3 changes: 2 additions & 1 deletion git-compat-util.h
Expand Up @@ -346,7 +346,8 @@ static inline char *gitstrchrnul(const char *s, int c)

extern void release_pack_memory(size_t, int);

extern void set_try_to_free_routine(void (*routine)(size_t));
typedef void (*try_to_free_t)(size_t);
extern try_to_free_t set_try_to_free_routine(try_to_free_t);

extern char *xstrdup(const char *str);
extern void *xmalloc(size_t size);
Expand Down
6 changes: 4 additions & 2 deletions wrapper.c
Expand Up @@ -10,9 +10,11 @@ static void try_to_free_builtin(size_t size)

static void (*try_to_free_routine)(size_t size) = try_to_free_builtin;

void set_try_to_free_routine(void (*routine)(size_t))
try_to_free_t set_try_to_free_routine(try_to_free_t routine)
{
try_to_free_routine = (routine) ? routine : try_to_free_builtin;
try_to_free_t old = try_to_free_routine;
try_to_free_routine = routine;
return old;
}

char *xstrdup(const char *str)
Expand Down

0 comments on commit 851c34b

Please sign in to comment.