]>
Commit | Line | Data |
---|---|---|
bb742ede | 1 | /* |
359fc2d2 | 2 | * Copyright (C) the libgit2 contributors. All rights reserved. |
bb742ede VM |
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 | */ | |
bb3de0c4 VM |
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" | |
5df18424 | 15 | #include "oidmap.h" |
bb3de0c4 | 16 | |
5df18424 VM |
17 | enum { |
18 | GIT_CACHE_STORE_ANY = 0, | |
19 | GIT_CACHE_STORE_RAW = 1, | |
20 | GIT_CACHE_STORE_PARSED = 2 | |
21 | }; | |
bb3de0c4 VM |
22 | |
23 | typedef struct { | |
78606263 RB |
24 | git_oid oid; |
25 | int16_t type; /* git_otype value */ | |
26 | uint16_t flags; /* GIT_CACHE_STORE value */ | |
27 | size_t size; | |
8842c75f | 28 | git_atomic refcount; |
bb3de0c4 VM |
29 | } git_cached_obj; |
30 | ||
31 | typedef struct { | |
5df18424 | 32 | git_oidmap *map; |
6a211d7c | 33 | git_rwlock lock; |
eb63fda2 | 34 | ssize_t used_memory; |
bb3de0c4 VM |
35 | } git_cache; |
36 | ||
b12b72ea | 37 | extern bool git_cache__enabled; |
eb63fda2 ET |
38 | extern ssize_t git_cache__max_storage; |
39 | extern git_atomic_ssize git_cache__current_storage; | |
b12b72ea RB |
40 | |
41 | int git_cache_set_max_object_size(git_otype type, size_t size); | |
42 | ||
5df18424 | 43 | int git_cache_init(git_cache *cache); |
bb3de0c4 | 44 | void git_cache_free(git_cache *cache); |
879458e7 | 45 | void git_cache_clear(git_cache *cache); |
bb3de0c4 | 46 | |
5df18424 VM |
47 | void *git_cache_store_raw(git_cache *cache, git_odb_object *entry); |
48 | void *git_cache_store_parsed(git_cache *cache, git_object *entry); | |
49 | ||
50 | git_odb_object *git_cache_get_raw(git_cache *cache, const git_oid *oid); | |
51 | git_object *git_cache_get_parsed(git_cache *cache, const git_oid *oid); | |
52 | void *git_cache_get_any(git_cache *cache, const git_oid *oid); | |
bb3de0c4 | 53 | |
b12b72ea RB |
54 | GIT_INLINE(size_t) git_cache_size(git_cache *cache) |
55 | { | |
56 | return (size_t)kh_size(cache->map); | |
57 | } | |
58 | ||
e4b4da14 | 59 | GIT_INLINE(void) git_cached_obj_incref(void *_obj) |
72a3fe42 | 60 | { |
e4b4da14 | 61 | git_cached_obj *obj = _obj; |
72a3fe42 VM |
62 | git_atomic_inc(&obj->refcount); |
63 | } | |
64 | ||
5df18424 | 65 | void git_cached_obj_decref(void *_obj); |
72a3fe42 | 66 | |
bb3de0c4 | 67 | #endif |