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
fe719932
Commit
fe719932
authored
Apr 22, 2013
by
Russell Belfer
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1497 from carlosmn/atomic-refcount
Make refcounting atomic
parents
d08dd728
05b17964
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
12 deletions
+12
-12
src/util.h
+4
-4
tests-clar/repo/getters.c
+2
-2
tests-clar/repo/setters.c
+6
-6
No files found.
src/util.h
View file @
fe719932
...
...
@@ -188,20 +188,20 @@ extern int git__strncmp(const char *a, const char *b, size_t sz);
extern
int
git__strncasecmp
(
const
char
*
a
,
const
char
*
b
,
size_t
sz
);
typedef
struct
{
short
refcount
;
git_atomic
refcount
;
void
*
owner
;
}
git_refcount
;
typedef
void
(
*
git_refcount_freeptr
)(
void
*
r
);
#define GIT_REFCOUNT_INC(r) { \
((git_refcount *)(r))->refcount++;
\
git_atomic_inc(&((git_refcount *)(r))->refcount);
\
}
#define GIT_REFCOUNT_DEC(_r, do_free) { \
git_refcount *r = (git_refcount *)(_r); \
r->refcount--
; \
if (
r->refcount
<= 0 && r->owner == NULL) { do_free(_r); } \
int val = git_atomic_dec(&r->refcount)
; \
if (
val
<= 0 && r->owner == NULL) { do_free(_r); } \
}
#define GIT_REFCOUNT_OWN(r, o) { \
...
...
tests-clar/repo/getters.c
View file @
fe719932
...
...
@@ -31,10 +31,10 @@ void test_repo_getters__retrieving_the_odb_honors_the_refcount(void)
cl_git_pass
(
git_repository_open
(
&
repo
,
cl_fixture
(
"testrepo.git"
)));
cl_git_pass
(
git_repository_odb
(
&
odb
,
repo
));
cl_assert
(((
git_refcount
*
)
odb
)
->
refcount
==
2
);
cl_assert
(((
git_refcount
*
)
odb
)
->
refcount
.
val
==
2
);
git_repository_free
(
repo
);
cl_assert
(((
git_refcount
*
)
odb
)
->
refcount
==
1
);
cl_assert
(((
git_refcount
*
)
odb
)
->
refcount
.
val
==
1
);
git_odb_free
(
odb
);
}
tests-clar/repo/setters.c
View file @
fe719932
...
...
@@ -69,13 +69,13 @@ void test_repo_setters__setting_a_new_index_on_a_repo_which_has_already_loaded_o
git_index
*
new_index
;
cl_git_pass
(
git_index_open
(
&
new_index
,
"./my-index"
));
cl_assert
(((
git_refcount
*
)
new_index
)
->
refcount
==
1
);
cl_assert
(((
git_refcount
*
)
new_index
)
->
refcount
.
val
==
1
);
git_repository_set_index
(
repo
,
new_index
);
cl_assert
(((
git_refcount
*
)
new_index
)
->
refcount
==
2
);
cl_assert
(((
git_refcount
*
)
new_index
)
->
refcount
.
val
==
2
);
git_repository_free
(
repo
);
cl_assert
(((
git_refcount
*
)
new_index
)
->
refcount
==
1
);
cl_assert
(((
git_refcount
*
)
new_index
)
->
refcount
.
val
==
1
);
git_index_free
(
new_index
);
...
...
@@ -90,13 +90,13 @@ void test_repo_setters__setting_a_new_odb_on_a_repo_which_already_loaded_one_pro
git_odb
*
new_odb
;
cl_git_pass
(
git_odb_open
(
&
new_odb
,
"./testrepo.git/objects"
));
cl_assert
(((
git_refcount
*
)
new_odb
)
->
refcount
==
1
);
cl_assert
(((
git_refcount
*
)
new_odb
)
->
refcount
.
val
==
1
);
git_repository_set_odb
(
repo
,
new_odb
);
cl_assert
(((
git_refcount
*
)
new_odb
)
->
refcount
==
2
);
cl_assert
(((
git_refcount
*
)
new_odb
)
->
refcount
.
val
==
2
);
git_repository_free
(
repo
);
cl_assert
(((
git_refcount
*
)
new_odb
)
->
refcount
==
1
);
cl_assert
(((
git_refcount
*
)
new_odb
)
->
refcount
.
val
==
1
);
git_odb_free
(
new_odb
);
...
...
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