]> git.proxmox.com Git - libgit2.git/blob - src/cache.h
Merge branch 'master' of https://github.com/libgit2/libgit2 into development
[libgit2.git] / src / cache.h
1 /*
2 * Copyright (C) the libgit2 contributors. All rights reserved.
3 *
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.
6 */
7 #ifndef INCLUDE_cache_h__
8 #define INCLUDE_cache_h__
9
10 #include "git2/common.h"
11 #include "git2/oid.h"
12 #include "git2/odb.h"
13
14 #include "thread-utils.h"
15 #include "oidmap.h"
16
17 enum {
18 GIT_CACHE_STORE_ANY = 0,
19 GIT_CACHE_STORE_RAW = 1,
20 GIT_CACHE_STORE_PARSED = 2
21 };
22
23 typedef struct {
24 git_oid oid;
25 int16_t type; /* git_otype value */
26 uint16_t flags; /* GIT_CACHE_STORE value */
27 size_t size;
28 git_atomic refcount;
29 } git_cached_obj;
30
31 typedef struct {
32 git_oidmap *map;
33 git_mutex lock;
34 size_t used_memory;
35 } git_cache;
36
37 extern bool git_cache__enabled;
38 extern size_t git_cache__max_storage;
39
40 int git_cache_set_max_object_size(git_otype type, size_t size);
41
42 int git_cache_init(git_cache *cache);
43 void git_cache_free(git_cache *cache);
44
45 void *git_cache_store_raw(git_cache *cache, git_odb_object *entry);
46 void *git_cache_store_parsed(git_cache *cache, git_object *entry);
47
48 git_odb_object *git_cache_get_raw(git_cache *cache, const git_oid *oid);
49 git_object *git_cache_get_parsed(git_cache *cache, const git_oid *oid);
50 void *git_cache_get_any(git_cache *cache, const git_oid *oid);
51
52 GIT_INLINE(size_t) git_cache_size(git_cache *cache)
53 {
54 return (size_t)kh_size(cache->map);
55 }
56
57 GIT_INLINE(void) git_cached_obj_incref(void *_obj)
58 {
59 git_cached_obj *obj = _obj;
60 git_atomic_inc(&obj->refcount);
61 }
62
63 void git_cached_obj_decref(void *_obj);
64
65 #endif