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
f9774eea
Commit
f9774eea
authored
Apr 22, 2013
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
atomic: Add an atomic type for 64-bit operations
parent
d08dd728
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
0 deletions
+42
-0
src/thread-utils.h
+42
-0
No files found.
src/thread-utils.h
View file @
f9774eea
...
@@ -18,6 +18,14 @@ typedef struct {
...
@@ -18,6 +18,14 @@ typedef struct {
#endif
#endif
}
git_atomic
;
}
git_atomic
;
typedef
struct
{
#if defined(GIT_WIN32)
__int64
val
;
#else
int64_t
val
;
#endif
}
git_atomic64
;
GIT_INLINE
(
void
)
git_atomic_set
(
git_atomic
*
a
,
int
val
)
GIT_INLINE
(
void
)
git_atomic_set
(
git_atomic
*
a
,
int
val
)
{
{
a
->
val
=
val
;
a
->
val
=
val
;
...
@@ -57,6 +65,17 @@ GIT_INLINE(int) git_atomic_inc(git_atomic *a)
...
@@ -57,6 +65,17 @@ GIT_INLINE(int) git_atomic_inc(git_atomic *a)
#endif
#endif
}
}
GIT_INLINE
(
int
)
git_atomic_add
(
git_atomic
*
a
,
int32_t
addend
)
{
#if defined(GIT_WIN32)
return
_InterlockedExchangeAdd
(
&
a
->
val
,
addend
);
#elif defined(__GNUC__)
return
__sync_add_and_fetch
(
&
a
->
val
,
addend
);
#else
# error "Unsupported architecture for atomic operations"
#endif
}
GIT_INLINE
(
int
)
git_atomic_dec
(
git_atomic
*
a
)
GIT_INLINE
(
int
)
git_atomic_dec
(
git_atomic
*
a
)
{
{
#if defined(GIT_WIN32)
#if defined(GIT_WIN32)
...
@@ -82,6 +101,17 @@ GIT_INLINE(void *) git___compare_and_swap(
...
@@ -82,6 +101,17 @@ GIT_INLINE(void *) git___compare_and_swap(
return
(
foundval
==
oldval
)
?
oldval
:
newval
;
return
(
foundval
==
oldval
)
?
oldval
:
newval
;
}
}
GIT_INLINE
(
int
)
git_atomic64_add
(
git_atomic64
*
a
,
int64_t
addend
)
{
#if defined(GIT_WIN32)
return
_InterlockedExchangeAdd64
(
&
a
->
val
,
addend
);
#elif defined(__GNUC__)
return
__sync_add_and_fetch
(
&
a
->
val
,
addend
);
#else
# error "Unsupported architecture for atomic operations"
#endif
}
#else
#else
#define git_thread unsigned int
#define git_thread unsigned int
...
@@ -110,6 +140,12 @@ GIT_INLINE(int) git_atomic_inc(git_atomic *a)
...
@@ -110,6 +140,12 @@ GIT_INLINE(int) git_atomic_inc(git_atomic *a)
return
++
a
->
val
;
return
++
a
->
val
;
}
}
GIT_INLINE
(
int
)
git_atomic_add
(
git_atomic
*
a
,
int32_t
addend
)
{
a
->
val
+=
addend
;
return
a
->
val
;
}
GIT_INLINE
(
int
)
git_atomic_dec
(
git_atomic
*
a
)
GIT_INLINE
(
int
)
git_atomic_dec
(
git_atomic
*
a
)
{
{
return
--
a
->
val
;
return
--
a
->
val
;
...
@@ -125,6 +161,12 @@ GIT_INLINE(void *) git___compare_and_swap(
...
@@ -125,6 +161,12 @@ GIT_INLINE(void *) git___compare_and_swap(
return
oldval
;
return
oldval
;
}
}
GIT_INLINE
(
int
)
git_atomic64_add
(
git_atomic64
*
a
,
int64_t
addend
)
{
a
->
val
+=
addend
;
return
a
->
val
;
}
#endif
#endif
/* Atomically replace oldval with newval
/* Atomically replace oldval with newval
...
...
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