2 * Copyright (C) 2009-2011 the libgit2 contributors
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
7 #ifndef INCLUDE_cache_h__
8 #define INCLUDE_cache_h__
10 #include "git2/common.h"
14 #include "thread-utils.h"
16 #define GIT_DEFAULT_CACHE_SIZE 128
18 typedef void (*git_cached_obj_freeptr
)(void *);
33 unsigned int lru_count
;
35 git_cached_obj_freeptr free_obj
;
39 int git_cache_init(git_cache
*cache
, size_t size
, git_cached_obj_freeptr free_ptr
);
40 void git_cache_free(git_cache
*cache
);
42 void *git_cache_try_store(git_cache
*cache
, void *entry
);
43 void *git_cache_get(git_cache
*cache
, const git_oid
*oid
);
46 GIT_INLINE(int) git_cached_obj_compare(git_cached_obj
*obj
, const git_oid
*oid
)
48 return git_oid_cmp(&obj
->oid
, oid
);
51 GIT_INLINE(void) git_cached_obj_incref(git_cached_obj
*obj
)
53 git_atomic_inc(&obj
->refcount
);
56 GIT_INLINE(void) git_cached_obj_decref(git_cached_obj
*obj
, git_cached_obj_freeptr free_obj
)
58 if (git_atomic_dec(&obj
->refcount
) == 0)