Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
c4e91d45
Commit
c4e91d45
authored
Apr 03, 2013
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Random eviction
parent
6b90e244
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
4 deletions
+21
-4
src/cache.c
+18
-1
src/cache.h
+2
-3
src/object.c
+1
-0
No files found.
src/cache.c
View file @
c4e91d45
...
@@ -32,7 +32,6 @@ size_t git_cache__max_object_size = 4096;
...
@@ -32,7 +32,6 @@ size_t git_cache__max_object_size = 4096;
int
git_cache_init
(
git_cache
*
cache
)
int
git_cache_init
(
git_cache
*
cache
)
{
{
cache
->
lru_count
=
0
;
cache
->
map
=
git_oidmap_alloc
();
cache
->
map
=
git_oidmap_alloc
();
git_mutex_init
(
&
cache
->
lock
);
git_mutex_init
(
&
cache
->
lock
);
return
0
;
return
0
;
...
@@ -44,6 +43,24 @@ void git_cache_free(git_cache *cache)
...
@@ -44,6 +43,24 @@ void git_cache_free(git_cache *cache)
git_mutex_free
(
&
cache
->
lock
);
git_mutex_free
(
&
cache
->
lock
);
}
}
static
void
cache_evict_entries
(
git_cache
*
cache
,
size_t
evict
)
{
uint32_t
seed
=
rand
();
/* do not infinite loop if there's not enough entries to evict */
if
(
evict
>
kh_size
(
cache
->
map
))
return
;
while
(
evict
>
0
)
{
khiter_t
pos
=
seed
++
%
kh_end
(
cache
->
map
);
if
(
kh_exist
(
cache
->
map
,
pos
))
{
kh_del
(
oid
,
cache
->
map
,
pos
);
evict
--
;
}
}
}
static
bool
cache_should_store
(
git_otype
object_type
,
size_t
object_size
)
static
bool
cache_should_store
(
git_otype
object_type
,
size_t
object_size
)
{
{
if
(
!
git_cache__store_types
[
object_type
])
if
(
!
git_cache__store_types
[
object_type
])
...
...
src/cache.h
View file @
c4e91d45
...
@@ -23,14 +23,13 @@ enum {
...
@@ -23,14 +23,13 @@ enum {
typedef
struct
{
typedef
struct
{
git_oid
oid
;
git_oid
oid
;
git_atomic
refcount
;
git_atomic
refcount
;
uint
16_t
flags
;
uint
32_t
cache_size
;
uint
16_t
lru
;
uint
32_t
flags
;
}
git_cached_obj
;
}
git_cached_obj
;
typedef
struct
{
typedef
struct
{
git_oidmap
*
map
;
git_oidmap
*
map
;
git_mutex
lock
;
git_mutex
lock
;
unsigned
int
lru_count
;
}
git_cache
;
}
git_cache
;
int
git_cache_init
(
git_cache
*
cache
);
int
git_cache_init
(
git_cache
*
cache
);
...
...
src/object.c
View file @
c4e91d45
...
@@ -98,6 +98,7 @@ int git_object__from_odb_object(
...
@@ -98,6 +98,7 @@ int git_object__from_odb_object(
/* Initialize parent object */
/* Initialize parent object */
git_oid_cpy
(
&
object
->
cached
.
oid
,
&
odb_obj
->
cached
.
oid
);
git_oid_cpy
(
&
object
->
cached
.
oid
,
&
odb_obj
->
cached
.
oid
);
object
->
cached
.
cache_size
=
(
uint32_t
)
odb_obj
->
raw
.
len
;
object
->
repo
=
repo
;
object
->
repo
=
repo
;
switch
(
type
)
{
switch
(
type
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment