diff options
| author | Vicent Martà <tanoku@gmail.com> | 2012-01-27 18:28:02 -0800 |
|---|---|---|
| committer | Vicent Martà <tanoku@gmail.com> | 2012-01-27 18:28:02 -0800 |
| commit | e4b4da140648d83f953837d4233dd87cb31f3ca4 (patch) | |
| tree | e41553a06881bc2a5b9ab9b02c84db343c34f6ec /src/cache.h | |
| parent | 7a6f51de6d4f5543634889e58c30a0a6ceb75a09 (diff) | |
| download | libgit2-e4b4da140648d83f953837d4233dd87cb31f3ca4.tar.gz | |
cache: Simplify locking mechanics
The object cache is mostly IO-bound, so it makes no sense to have a lock
per node.
Diffstat (limited to 'src/cache.h')
| -rw-r--r-- | src/cache.h | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/src/cache.h b/src/cache.h index 8c885d9a5..688f14559 100644 --- a/src/cache.h +++ b/src/cache.h @@ -23,42 +23,32 @@ typedef struct { } git_cached_obj; typedef struct { - git_cached_obj *ptr; + git_cached_obj **nodes; git_mutex lock; -} cache_node; - -typedef struct { - cache_node *nodes; unsigned int lru_count; size_t size_mask; git_cached_obj_freeptr free_obj; } git_cache; - int git_cache_init(git_cache *cache, size_t size, git_cached_obj_freeptr free_ptr); void git_cache_free(git_cache *cache); void *git_cache_try_store(git_cache *cache, void *entry); void *git_cache_get(git_cache *cache, const git_oid *oid); - -GIT_INLINE(int) git_cached_obj_compare(git_cached_obj *obj, const git_oid *oid) -{ - return git_oid_cmp(&obj->oid, oid); -} - -GIT_INLINE(void) git_cached_obj_incref(git_cached_obj *obj) +GIT_INLINE(void) git_cached_obj_incref(void *_obj) { + git_cached_obj *obj = _obj; git_atomic_inc(&obj->refcount); } -GIT_INLINE(void) git_cached_obj_decref(git_cached_obj *obj, git_cached_obj_freeptr free_obj) +GIT_INLINE(void) git_cached_obj_decref(void *_obj, git_cached_obj_freeptr free_obj) { + git_cached_obj *obj = _obj; + if (git_atomic_dec(&obj->refcount) == 0) free_obj(obj); } - - #endif |
