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
cb92467b
Commit
cb92467b
authored
Aug 27, 2014
by
Vicent Marti
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2537 from libgit2/reduce-cache-contention
Refactor git_cache to use an rwlock
parents
00e9ae5a
6a211d7c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
10 deletions
+10
-10
src/cache.c
+9
-9
src/cache.h
+1
-1
No files found.
src/cache.c
View file @
cb92467b
...
...
@@ -68,8 +68,8 @@ int git_cache_init(git_cache *cache)
{
memset
(
cache
,
0
,
sizeof
(
*
cache
));
cache
->
map
=
git_oidmap_alloc
();
if
(
git_
mutex
_init
(
&
cache
->
lock
))
{
giterr_set
(
GITERR_OS
,
"Failed to initialize cache
mutex
"
);
if
(
git_
rwlock
_init
(
&
cache
->
lock
))
{
giterr_set
(
GITERR_OS
,
"Failed to initialize cache
rwlock
"
);
return
-
1
;
}
return
0
;
...
...
@@ -94,19 +94,19 @@ static void clear_cache(git_cache *cache)
void
git_cache_clear
(
git_cache
*
cache
)
{
if
(
git_
mutex_
lock
(
&
cache
->
lock
)
<
0
)
if
(
git_
rwlock_wr
lock
(
&
cache
->
lock
)
<
0
)
return
;
clear_cache
(
cache
);
git_
mutex_
unlock
(
&
cache
->
lock
);
git_
rwlock_wr
unlock
(
&
cache
->
lock
);
}
void
git_cache_free
(
git_cache
*
cache
)
{
git_cache_clear
(
cache
);
git_oidmap_free
(
cache
->
map
);
git_
mutex
_free
(
&
cache
->
lock
);
git_
rwlock
_free
(
&
cache
->
lock
);
git__memzero
(
cache
,
sizeof
(
*
cache
));
}
...
...
@@ -152,7 +152,7 @@ static void *cache_get(git_cache *cache, const git_oid *oid, unsigned int flags)
khiter_t
pos
;
git_cached_obj
*
entry
=
NULL
;
if
(
!
git_cache__enabled
||
git_
mutex_
lock
(
&
cache
->
lock
)
<
0
)
if
(
!
git_cache__enabled
||
git_
rwlock_rd
lock
(
&
cache
->
lock
)
<
0
)
return
NULL
;
pos
=
kh_get
(
oid
,
cache
->
map
,
oid
);
...
...
@@ -166,7 +166,7 @@ static void *cache_get(git_cache *cache, const git_oid *oid, unsigned int flags)
}
}
git_
mutex_
unlock
(
&
cache
->
lock
);
git_
rwlock_rd
unlock
(
&
cache
->
lock
);
return
entry
;
}
...
...
@@ -185,7 +185,7 @@ static void *cache_store(git_cache *cache, git_cached_obj *entry)
if
(
!
cache_should_store
(
entry
->
type
,
entry
->
size
))
return
entry
;
if
(
git_
mutex_
lock
(
&
cache
->
lock
)
<
0
)
if
(
git_
rwlock_wr
lock
(
&
cache
->
lock
)
<
0
)
return
entry
;
/* soften the load on the cache */
...
...
@@ -227,7 +227,7 @@ static void *cache_store(git_cache *cache, git_cached_obj *entry)
}
}
git_
mutex_
unlock
(
&
cache
->
lock
);
git_
rwlock_wr
unlock
(
&
cache
->
lock
);
return
entry
;
}
...
...
src/cache.h
View file @
cb92467b
...
...
@@ -30,7 +30,7 @@ typedef struct {
typedef
struct
{
git_oidmap
*
map
;
git_
mutex
lock
;
git_
rwlock
lock
;
ssize_t
used_memory
;
}
git_cache
;
...
...
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