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
03c0938f
Commit
03c0938f
authored
Aug 25, 2020
by
lhchavez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid using atomics in pool.c
Instead, globally initialize the system page size.
parent
cc1d7f5c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
17 deletions
+27
-17
src/global.c
+3
-1
src/pool.c
+15
-14
src/pool.h
+8
-0
src/thread-utils.h
+1
-2
No files found.
src/global.c
View file @
03c0938f
...
...
@@ -12,6 +12,7 @@
#include "sysdir.h"
#include "filter.h"
#include "merge_driver.h"
#include "pool.h"
#include "streams/registry.h"
#include "streams/mbedtls.h"
#include "streams/openssl.h"
...
...
@@ -38,7 +39,8 @@ static git_global_init_fn git__init_callbacks[] = {
git_stream_registry_global_init
,
git_openssl_stream_global_init
,
git_mbedtls_stream_global_init
,
git_mwindow_global_init
git_mwindow_global_init
,
git_pool_global_init
};
static
git_global_shutdown_fn
git__shutdown_callbacks
[
ARRAY_SIZE
(
git__init_callbacks
)];
...
...
src/pool.c
View file @
03c0938f
...
...
@@ -21,23 +21,19 @@ struct git_pool_page {
static
void
*
pool_alloc_page
(
git_pool
*
pool
,
size_t
size
);
static
size_t
pool_system_page_size
(
void
)
{
static
git_atomic_ssize
cached_size
=
{
0
};
size_t
page_size
=
0
;
#ifndef GIT_DEBUG_POOL
if
((
page_size
=
(
size_t
)
git_atomic_ssize_get
(
&
cached_size
))
==
0
)
{
if
(
git__page_size
(
&
page_size
)
<
0
)
page_size
=
4096
;
/* allow space for malloc overhead */
page_size
-=
(
2
*
sizeof
(
void
*
))
+
sizeof
(
git_pool_page
);
git_atomic_ssize_set
(
&
cached_size
,
(
int64_t
)
page_size
);
}
static
size_t
system_page_size
=
0
;
return
page_size
;
int
git_pool_global_init
(
void
)
{
if
(
git__page_size
(
&
system_page_size
)
<
0
)
system_page_size
=
4096
;
/* allow space for malloc overhead */
system_page_size
-=
(
2
*
sizeof
(
void
*
))
+
sizeof
(
git_pool_page
);
return
0
;
}
#ifndef GIT_DEBUG_POOL
int
git_pool_init
(
git_pool
*
pool
,
size_t
item_size
)
{
assert
(
pool
);
...
...
@@ -45,7 +41,7 @@ int git_pool_init(git_pool *pool, size_t item_size)
memset
(
pool
,
0
,
sizeof
(
git_pool
));
pool
->
item_size
=
item_size
;
pool
->
page_size
=
pool_system_page_size
()
;
pool
->
page_size
=
system_page_size
;
return
0
;
}
...
...
@@ -115,6 +111,11 @@ bool git_pool__ptr_in_pool(git_pool *pool, void *ptr)
#else
int
git_pool_global_init
(
void
)
{
return
0
;
}
static
int
git_pool__ptr_cmp
(
const
void
*
a
,
const
void
*
b
)
{
if
(
a
>
b
)
{
...
...
src/pool.h
View file @
03c0938f
...
...
@@ -135,4 +135,12 @@ extern uint32_t git_pool__open_pages(git_pool *pool);
#endif
extern
bool
git_pool__ptr_in_pool
(
git_pool
*
pool
,
void
*
ptr
);
/**
* This function is being called by our global setup routines to
* initialize the system pool size.
*
* @return 0 on success, <0 on failure
*/
extern
int
git_pool_global_init
(
void
);
#endif
src/thread-utils.h
View file @
03c0938f
...
...
@@ -21,8 +21,7 @@
# if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 1))
# error Atomic primitives do not exist on this version of gcc; configure libgit2 with -DTHREADSAFE=OFF
# endif
# if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))
# elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))
# define GIT_BUILTIN_ATOMIC
# else
# define GIT_BUILTIN_SYNC
...
...
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