Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
37723c9e
Commit
37723c9e
authored
8 years ago
by
Craig Tiller
Browse files
Options
Downloads
Patches
Plain Diff
Fix race condition
parent
0dd81003
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/core/lib/support/arena.c
+7
-4
7 additions, 4 deletions
src/core/lib/support/arena.c
test/core/support/arena_test.c
+6
-1
6 additions, 1 deletion
test/core/support/arena_test.c
with
13 additions
and
5 deletions
src/core/lib/support/arena.c
+
7
−
4
View file @
37723c9e
...
@@ -34,6 +34,7 @@
...
@@ -34,6 +34,7 @@
#include
"src/core/lib/support/arena.h"
#include
"src/core/lib/support/arena.h"
#include
<grpc/support/alloc.h>
#include
<grpc/support/alloc.h>
#include
<grpc/support/atm.h>
#include
<grpc/support/atm.h>
#include
<grpc/support/log.h>
#include
<grpc/support/useful.h>
#include
<grpc/support/useful.h>
#define ROUND_UP_TO_ALIGNMENT_SIZE(x) \
#define ROUND_UP_TO_ALIGNMENT_SIZE(x) \
...
@@ -74,16 +75,16 @@ void *gpr_arena_alloc(gpr_arena *arena, size_t size) {
...
@@ -74,16 +75,16 @@ void *gpr_arena_alloc(gpr_arena *arena, size_t size) {
size_t
start
=
size_t
start
=
(
size_t
)
gpr_atm_no_barrier_fetch_add
(
&
arena
->
size_so_far
,
size
);
(
size_t
)
gpr_atm_no_barrier_fetch_add
(
&
arena
->
size_so_far
,
size
);
zone
*
z
=
&
arena
->
initial_zone
;
zone
*
z
=
&
arena
->
initial_zone
;
while
(
start
>
z
->
size_
begin
)
{
while
(
start
>
z
->
size_
end
)
{
zone
*
next_z
=
(
zone
*
)
gpr_atm_acq_load
(
&
z
->
next_atm
);
zone
*
next_z
=
(
zone
*
)
gpr_atm_acq_load
(
&
z
->
next_atm
);
while
(
next_z
==
NULL
)
{
if
(
next_z
==
NULL
)
{
size_t
next_z_size
=
GPR_MAX
(
2
*
start
,
size
);
size_t
next_z_size
=
GPR_MAX
(
(
size_t
)
gpr_atm_no_barrier_load
(
&
arena
->
size_so_far
)
,
size
);
next_z
=
gpr_zalloc
(
sizeof
(
zone
)
+
next_z_size
);
next_z
=
gpr_zalloc
(
sizeof
(
zone
)
+
next_z_size
);
next_z
->
size_begin
=
z
->
size_end
;
next_z
->
size_begin
=
z
->
size_end
;
next_z
->
size_end
=
z
->
size_end
+
next_z_size
;
next_z
->
size_end
=
z
->
size_end
+
next_z_size
;
if
(
!
gpr_atm_rel_cas
(
&
z
->
next_atm
,
(
gpr_atm
)
NULL
,
(
gpr_atm
)
next_z
))
{
if
(
!
gpr_atm_rel_cas
(
&
z
->
next_atm
,
(
gpr_atm
)
NULL
,
(
gpr_atm
)
next_z
))
{
gpr_free
(
next_z
);
gpr_free
(
next_z
);
next_z
=
NULL
;
next_z
=
(
zone
*
)
gpr_atm_acq_load
(
&
z
->
next_atm
);
}
}
}
}
z
=
next_z
;
z
=
next_z
;
...
@@ -91,5 +92,7 @@ void *gpr_arena_alloc(gpr_arena *arena, size_t size) {
...
@@ -91,5 +92,7 @@ void *gpr_arena_alloc(gpr_arena *arena, size_t size) {
if
(
start
+
size
>
z
->
size_end
)
{
if
(
start
+
size
>
z
->
size_end
)
{
return
gpr_arena_alloc
(
arena
,
size
);
return
gpr_arena_alloc
(
arena
,
size
);
}
}
GPR_ASSERT
(
start
>=
z
->
size_begin
);
GPR_ASSERT
(
start
+
size
<=
z
->
size_end
);
return
((
char
*
)(
z
+
1
))
+
start
-
z
->
size_begin
;
return
((
char
*
)(
z
+
1
))
+
start
-
z
->
size_begin
;
}
}
This diff is collapsed.
Click to expand it.
test/core/support/arena_test.c
+
6
−
1
View file @
37723c9e
...
@@ -76,6 +76,7 @@ static void test(const char *name, size_t init_size, const size_t *allocs,
...
@@ -76,6 +76,7 @@ static void test(const char *name, size_t init_size, const size_t *allocs,
memset
(
ps
[
i
],
1
,
allocs
[
i
]);
memset
(
ps
[
i
],
1
,
allocs
[
i
]);
}
}
gpr_arena_destroy
(
a
);
gpr_arena_destroy
(
a
);
gpr_free
(
ps
);
}
}
#define TEST(name, init_size, ...) \
#define TEST(name, init_size, ...) \
...
@@ -99,6 +100,8 @@ static void concurrent_test_body(void *arg) {
...
@@ -99,6 +100,8 @@ static void concurrent_test_body(void *arg) {
}
}
static
void
concurrent_test
(
void
)
{
static
void
concurrent_test
(
void
)
{
gpr_log
(
GPR_DEBUG
,
"concurrent_test"
);
concurrent_test_args
args
;
concurrent_test_args
args
;
gpr_event_init
(
&
args
.
ev_start
);
gpr_event_init
(
&
args
.
ev_start
);
args
.
arena
=
gpr_arena_create
(
1024
);
args
.
arena
=
gpr_arena_create
(
1024
);
...
@@ -107,7 +110,7 @@ static void concurrent_test(void) {
...
@@ -107,7 +110,7 @@ static void concurrent_test(void) {
for
(
int
i
=
0
;
i
<
CONCURRENT_TEST_THREADS
;
i
++
)
{
for
(
int
i
=
0
;
i
<
CONCURRENT_TEST_THREADS
;
i
++
)
{
gpr_thd_options
opt
=
gpr_thd_options_default
();
gpr_thd_options
opt
=
gpr_thd_options_default
();
gpr_thd_options_
i
s_joinable
(
&
opt
);
gpr_thd_options_s
et
_joinable
(
&
opt
);
gpr_thd_new
(
&
thds
[
i
],
concurrent_test_body
,
&
args
,
&
opt
);
gpr_thd_new
(
&
thds
[
i
],
concurrent_test_body
,
&
args
,
&
opt
);
}
}
...
@@ -116,6 +119,8 @@ static void concurrent_test(void) {
...
@@ -116,6 +119,8 @@ static void concurrent_test(void) {
for
(
int
i
=
0
;
i
<
CONCURRENT_TEST_THREADS
;
i
++
)
{
for
(
int
i
=
0
;
i
<
CONCURRENT_TEST_THREADS
;
i
++
)
{
gpr_thd_join
(
thds
[
i
]);
gpr_thd_join
(
thds
[
i
]);
}
}
gpr_arena_destroy
(
args
.
arena
);
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment