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
eb63fda2
Commit
eb63fda2
authored
Apr 25, 2013
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
git_atomic_ssize for 64-bit atomics only on 64-bit platforms
parent
b4117e19
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
16 deletions
+48
-16
CMakeLists.txt
+9
-0
src/cache.c
+7
-6
src/cache.h
+3
-3
src/thread-utils.h
+26
-4
src/util.c
+3
-3
No files found.
CMakeLists.txt
View file @
eb63fda2
...
@@ -277,6 +277,15 @@ ELSE()
...
@@ -277,6 +277,15 @@ ELSE()
ENDIF
()
ENDIF
()
FILE
(
GLOB SRC_GIT2 src/*.c src/transports/*.c src/xdiff/*.c
)
FILE
(
GLOB SRC_GIT2 src/*.c src/transports/*.c src/xdiff/*.c
)
# Determine architecture of the machine
IF
(
CMAKE_SIZEOF_VOID_P EQUAL 8
)
ADD_DEFINITIONS
(
-DGIT_ARCH_64
)
ELSEIF
(
CMAKE_SIZEOF_VOID_P EQUAL 4
)
ADD_DEFINITIONS
(
-DGIT_ARCH_32
)
ELSE
()
message
(
FATAL_ERROR
"Unsupported architecture"
)
ENDIF
()
# Compile and link libgit2
# Compile and link libgit2
ADD_LIBRARY
(
git2
${
SRC_GIT2
}
${
SRC_OS
}
${
SRC_ZLIB
}
${
SRC_HTTP
}
${
SRC_REGEX
}
${
SRC_SHA1
}
${
WIN_RC
}
)
ADD_LIBRARY
(
git2
${
SRC_GIT2
}
${
SRC_OS
}
${
SRC_ZLIB
}
${
SRC_HTTP
}
${
SRC_REGEX
}
${
SRC_SHA1
}
${
WIN_RC
}
)
TARGET_LINK_LIBRARIES
(
git2
${
SSL_LIBRARIES
}
)
TARGET_LINK_LIBRARIES
(
git2
${
SSL_LIBRARIES
}
)
...
...
src/cache.c
View file @
eb63fda2
...
@@ -18,8 +18,8 @@
...
@@ -18,8 +18,8 @@
GIT__USE_OIDMAP
GIT__USE_OIDMAP
bool
git_cache__enabled
=
true
;
bool
git_cache__enabled
=
true
;
int64
_t
git_cache__max_storage
=
(
256
*
1024
*
1024
);
ssize
_t
git_cache__max_storage
=
(
256
*
1024
*
1024
);
git_atomic
64
git_cache__current_storage
=
{
0
};
git_atomic
_ssize
git_cache__current_storage
=
{
0
};
static
size_t
git_cache__max_object_size
[
8
]
=
{
static
size_t
git_cache__max_object_size
[
8
]
=
{
0
,
/* GIT_OBJ__EXT1 */
0
,
/* GIT_OBJ__EXT1 */
...
@@ -85,7 +85,7 @@ static void clear_cache(git_cache *cache)
...
@@ -85,7 +85,7 @@ static void clear_cache(git_cache *cache)
});
});
kh_clear
(
oid
,
cache
->
map
);
kh_clear
(
oid
,
cache
->
map
);
git_atomic
64
_add
(
&
git_cache__current_storage
,
-
cache
->
used_memory
);
git_atomic
_ssize
_add
(
&
git_cache__current_storage
,
-
cache
->
used_memory
);
cache
->
used_memory
=
0
;
cache
->
used_memory
=
0
;
}
}
...
@@ -111,7 +111,8 @@ void git_cache_free(git_cache *cache)
...
@@ -111,7 +111,8 @@ void git_cache_free(git_cache *cache)
static
void
cache_evict_entries
(
git_cache
*
cache
)
static
void
cache_evict_entries
(
git_cache
*
cache
)
{
{
uint32_t
seed
=
rand
();
uint32_t
seed
=
rand
();
int64_t
evicted_memory
=
0
,
evict_count
=
8
;
size_t
evict_count
=
8
;
ssize_t
evicted_memory
=
0
;
/* do not infinite loop if there's not enough entries to evict */
/* do not infinite loop if there's not enough entries to evict */
if
(
evict_count
>
kh_size
(
cache
->
map
))
{
if
(
evict_count
>
kh_size
(
cache
->
map
))
{
...
@@ -134,7 +135,7 @@ static void cache_evict_entries(git_cache *cache)
...
@@ -134,7 +135,7 @@ static void cache_evict_entries(git_cache *cache)
}
}
cache
->
used_memory
-=
evicted_memory
;
cache
->
used_memory
-=
evicted_memory
;
git_atomic
64
_add
(
&
git_cache__current_storage
,
-
evicted_memory
);
git_atomic
_ssize
_add
(
&
git_cache__current_storage
,
-
evicted_memory
);
}
}
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
)
...
@@ -195,7 +196,7 @@ static void *cache_store(git_cache *cache, git_cached_obj *entry)
...
@@ -195,7 +196,7 @@ static void *cache_store(git_cache *cache, git_cached_obj *entry)
kh_val
(
cache
->
map
,
pos
)
=
entry
;
kh_val
(
cache
->
map
,
pos
)
=
entry
;
git_cached_obj_incref
(
entry
);
git_cached_obj_incref
(
entry
);
cache
->
used_memory
+=
entry
->
size
;
cache
->
used_memory
+=
entry
->
size
;
git_atomic
64_add
(
&
git_cache__current_storage
,
(
int64
_t
)
entry
->
size
);
git_atomic
_ssize_add
(
&
git_cache__current_storage
,
(
ssize
_t
)
entry
->
size
);
}
}
}
}
/* found */
/* found */
...
...
src/cache.h
View file @
eb63fda2
...
@@ -31,12 +31,12 @@ typedef struct {
...
@@ -31,12 +31,12 @@ typedef struct {
typedef
struct
{
typedef
struct
{
git_oidmap
*
map
;
git_oidmap
*
map
;
git_mutex
lock
;
git_mutex
lock
;
int64
_t
used_memory
;
ssize
_t
used_memory
;
}
git_cache
;
}
git_cache
;
extern
bool
git_cache__enabled
;
extern
bool
git_cache__enabled
;
extern
int64
_t
git_cache__max_storage
;
extern
ssize
_t
git_cache__max_storage
;
extern
git_atomic
64
git_cache__current_storage
;
extern
git_atomic
_ssize
git_cache__current_storage
;
int
git_cache_set_max_object_size
(
git_otype
type
,
size_t
size
);
int
git_cache_set_max_object_size
(
git_otype
type
,
size_t
size
);
...
...
src/thread-utils.h
View file @
eb63fda2
...
@@ -18,6 +18,8 @@ typedef struct {
...
@@ -18,6 +18,8 @@ typedef struct {
#endif
#endif
}
git_atomic
;
}
git_atomic
;
#ifdef GIT_ARCH_64
typedef
struct
{
typedef
struct
{
#if defined(GIT_WIN32)
#if defined(GIT_WIN32)
__int64
val
;
__int64
val
;
...
@@ -26,6 +28,18 @@ typedef struct {
...
@@ -26,6 +28,18 @@ typedef struct {
#endif
#endif
}
git_atomic64
;
}
git_atomic64
;
typedef
git_atomic64
git_atomic_ssize
;
#define git_atomic_ssize_add git_atomic64_add
#else
typedef
git_atomic
git_atomic_ssize
;
#define git_atomic_ssize_add git_atomic_add
#endif
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
;
...
@@ -68,7 +82,7 @@ GIT_INLINE(int) git_atomic_inc(git_atomic *a)
...
@@ -68,7 +82,7 @@ GIT_INLINE(int) git_atomic_inc(git_atomic *a)
GIT_INLINE
(
int
)
git_atomic_add
(
git_atomic
*
a
,
int32_t
addend
)
GIT_INLINE
(
int
)
git_atomic_add
(
git_atomic
*
a
,
int32_t
addend
)
{
{
#if defined(GIT_WIN32)
#if defined(GIT_WIN32)
return
_
InterlockedExchangeAdd
(
&
a
->
val
,
addend
);
return
InterlockedExchangeAdd
(
&
a
->
val
,
addend
);
#elif defined(__GNUC__)
#elif defined(__GNUC__)
return
__sync_add_and_fetch
(
&
a
->
val
,
addend
);
return
__sync_add_and_fetch
(
&
a
->
val
,
addend
);
#else
#else
...
@@ -101,10 +115,12 @@ GIT_INLINE(void *) git___compare_and_swap(
...
@@ -101,10 +115,12 @@ 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
)
#ifdef GIT_ARCH_64
GIT_INLINE
(
int64_t
)
git_atomic64_add
(
git_atomic64
*
a
,
int64_t
addend
)
{
{
#if defined(GIT_WIN32)
#if defined(GIT_WIN32)
return
_
InterlockedExchangeAdd64
(
&
a
->
val
,
addend
);
return
InterlockedExchangeAdd64
(
&
a
->
val
,
addend
);
#elif defined(__GNUC__)
#elif defined(__GNUC__)
return
__sync_add_and_fetch
(
&
a
->
val
,
addend
);
return
__sync_add_and_fetch
(
&
a
->
val
,
addend
);
#else
#else
...
@@ -112,6 +128,8 @@ GIT_INLINE(int) git_atomic64_add(git_atomic64 *a, int64_t addend)
...
@@ -112,6 +128,8 @@ GIT_INLINE(int) git_atomic64_add(git_atomic64 *a, int64_t addend)
#endif
#endif
}
}
#endif
#else
#else
#define git_thread unsigned int
#define git_thread unsigned int
...
@@ -161,7 +179,9 @@ GIT_INLINE(void *) git___compare_and_swap(
...
@@ -161,7 +179,9 @@ GIT_INLINE(void *) git___compare_and_swap(
return
oldval
;
return
oldval
;
}
}
GIT_INLINE
(
int
)
git_atomic64_add
(
git_atomic64
*
a
,
int64_t
addend
)
#ifdef GIT_ARCH_64
GIT_INLINE
(
int64_t
)
git_atomic64_add
(
git_atomic64
*
a
,
int64_t
addend
)
{
{
a
->
val
+=
addend
;
a
->
val
+=
addend
;
return
a
->
val
;
return
a
->
val
;
...
@@ -169,6 +189,8 @@ GIT_INLINE(int) git_atomic64_add(git_atomic64 *a, int64_t addend)
...
@@ -169,6 +189,8 @@ GIT_INLINE(int) git_atomic64_add(git_atomic64 *a, int64_t addend)
#endif
#endif
#endif
/* Atomically replace oldval with newval
/* Atomically replace oldval with newval
* @return oldval if it was replaced or newval if it was not
* @return oldval if it was replaced or newval if it was not
*/
*/
...
...
src/util.c
View file @
eb63fda2
...
@@ -103,7 +103,7 @@ int git_libgit2_opts(int key, ...)
...
@@ -103,7 +103,7 @@ int git_libgit2_opts(int key, ...)
}
}
case
GIT_OPT_SET_CACHE_MAX_SIZE
:
case
GIT_OPT_SET_CACHE_MAX_SIZE
:
git_cache__max_storage
=
va_arg
(
ap
,
int64
_t
);
git_cache__max_storage
=
va_arg
(
ap
,
ssize
_t
);
break
;
break
;
case
GIT_OPT_ENABLE_CACHING
:
case
GIT_OPT_ENABLE_CACHING
:
...
@@ -111,8 +111,8 @@ int git_libgit2_opts(int key, ...)
...
@@ -111,8 +111,8 @@ int git_libgit2_opts(int key, ...)
break
;
break
;
case
GIT_OPT_GET_CACHED_MEMORY
:
case
GIT_OPT_GET_CACHED_MEMORY
:
*
(
va_arg
(
ap
,
int64
_t
*
))
=
git_cache__current_storage
.
val
;
*
(
va_arg
(
ap
,
ssize
_t
*
))
=
git_cache__current_storage
.
val
;
*
(
va_arg
(
ap
,
int64
_t
*
))
=
git_cache__max_storage
;
*
(
va_arg
(
ap
,
ssize
_t
*
))
=
git_cache__max_storage
;
break
;
break
;
}
}
...
...
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