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
d54c3e6b
Commit
d54c3e6b
authored
9 years ago
by
Vijay Pai
Browse files
Options
Downloads
Patches
Plain Diff
clang-format changed files
parent
d6cc1814
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/core/support/stack_lockfree.c
+4
-6
4 additions, 6 deletions
src/core/support/stack_lockfree.c
src/core/support/stack_lockfree.h
+2
-2
2 additions, 2 deletions
src/core/support/stack_lockfree.h
test/core/support/stack_lockfree_test.c
+14
-14
14 additions, 14 deletions
test/core/support/stack_lockfree_test.c
with
20 additions
and
22 deletions
src/core/support/stack_lockfree.c
+
4
−
6
View file @
d54c3e6b
...
...
@@ -65,7 +65,8 @@ typedef union lockfree_node {
}
lockfree_node
;
#define ENTRY_ALIGNMENT_BITS 3
/* make sure that entries aligned to 8-bytes */
#define INVALID_ENTRY_INDEX ((1<<16)-1)
/* reserve this entry as invalid */
#define INVALID_ENTRY_INDEX ((1 << 16) - 1)
/* reserve this entry as invalid \
*/
struct
gpr_stack_lockfree
{
lockfree_node
*
entries
;
...
...
@@ -109,8 +110,7 @@ void gpr_stack_lockfree_push(gpr_stack_lockfree *stack, int entry) {
head
.
atm
=
gpr_atm_no_barrier_load
(
&
(
stack
->
head
.
atm
));
/* Point to it */
stack
->
entries
[
entry
].
contents
.
index
=
head
.
contents
.
index
;
}
while
(
!
gpr_atm_rel_cas
(
&
(
stack
->
head
.
atm
),
head
.
atm
,
newhead
.
atm
));
}
while
(
!
gpr_atm_rel_cas
(
&
(
stack
->
head
.
atm
),
head
.
atm
,
newhead
.
atm
));
/* Use rel_cas above to make sure that entry index is set properly */
}
...
...
@@ -125,8 +125,6 @@ int gpr_stack_lockfree_pop(gpr_stack_lockfree *stack) {
newhead
.
atm
=
gpr_atm_no_barrier_load
(
&
(
stack
->
entries
[
head
.
contents
.
index
].
atm
));
}
while
(
!
gpr_atm_no_barrier_cas
(
&
(
stack
->
head
.
atm
),
head
.
atm
,
newhead
.
atm
));
}
while
(
!
gpr_atm_no_barrier_cas
(
&
(
stack
->
head
.
atm
),
head
.
atm
,
newhead
.
atm
));
return
head
.
contents
.
index
;
}
This diff is collapsed.
Click to expand it.
src/core/support/stack_lockfree.h
+
2
−
2
View file @
d54c3e6b
...
...
@@ -38,7 +38,7 @@ typedef struct gpr_stack_lockfree gpr_stack_lockfree;
/* This stack must specify the maximum number of entries to track.
The current implementation only allows up to 65534 entries */
gpr_stack_lockfree
*
gpr_stack_lockfree_create
(
int
entries
);
gpr_stack_lockfree
*
gpr_stack_lockfree_create
(
int
entries
);
void
gpr_stack_lockfree_destroy
(
gpr_stack_lockfree
*
stack
);
/* Pass in a valid entry number for the next stack entry */
...
...
@@ -47,4 +47,4 @@ void gpr_stack_lockfree_push(gpr_stack_lockfree* stack, int entry);
/* Returns -1 on empty or the actual entry number */
int
gpr_stack_lockfree_pop
(
gpr_stack_lockfree
*
stack
);
#endif
/* GRPC_INTERNAL_CORE_SUPPORT_STACK_LOCKFREE_H */
#endif
/* GRPC_INTERNAL_CORE_SUPPORT_STACK_LOCKFREE_H */
This diff is collapsed.
Click to expand it.
test/core/support/stack_lockfree_test.c
+
14
−
14
View file @
d54c3e6b
...
...
@@ -59,13 +59,13 @@ static void test_serial_sized(int size) {
GPR_ASSERT
(
gpr_stack_lockfree_pop
(
stack
)
==
-
1
);
/* Now add repeatedly more items and check them */
for
(
i
=
1
;
i
<
size
;
i
*=
2
)
{
for
(
i
=
1
;
i
<
size
;
i
*=
2
)
{
int
j
;
for
(
j
=
0
;
j
<=
i
;
j
++
)
{
for
(
j
=
0
;
j
<=
i
;
j
++
)
{
gpr_stack_lockfree_push
(
stack
,
j
);
}
for
(
j
=
0
;
j
<=
i
;
j
++
)
{
GPR_ASSERT
(
gpr_stack_lockfree_pop
(
stack
)
==
i
-
j
);
for
(
j
=
0
;
j
<=
i
;
j
++
)
{
GPR_ASSERT
(
gpr_stack_lockfree_pop
(
stack
)
==
i
-
j
);
}
GPR_ASSERT
(
gpr_stack_lockfree_pop
(
stack
)
==
-
1
);
}
...
...
@@ -75,7 +75,7 @@ static void test_serial_sized(int size) {
static
void
test_serial
()
{
int
i
;
for
(
i
=
128
;
i
<
MAX_STACK_SIZE
;
i
*=
2
)
{
for
(
i
=
128
;
i
<
MAX_STACK_SIZE
;
i
*=
2
)
{
test_serial_sized
(
i
);
}
test_serial_sized
(
MAX_STACK_SIZE
);
...
...
@@ -94,9 +94,9 @@ static void test_mt_body(void *v) {
int
lo
,
hi
;
int
i
;
int
res
;
lo
=
arg
->
rank
*
arg
->
stack_size
/
arg
->
nthreads
;
hi
=
(
arg
->
rank
+
1
)
*
arg
->
stack_size
/
arg
->
nthreads
;
for
(
i
=
lo
;
i
<
hi
;
i
++
)
{
lo
=
arg
->
rank
*
arg
->
stack_size
/
arg
->
nthreads
;
hi
=
(
arg
->
rank
+
1
)
*
arg
->
stack_size
/
arg
->
nthreads
;
for
(
i
=
lo
;
i
<
hi
;
i
++
)
{
gpr_stack_lockfree_push
(
arg
->
stack
,
i
);
if
((
res
=
gpr_stack_lockfree_pop
(
arg
->
stack
))
!=
-
1
)
{
arg
->
sum
+=
res
;
...
...
@@ -116,7 +116,7 @@ static void test_mt_sized(int size, int nth) {
gpr_thd_options
options
=
gpr_thd_options_default
();
stack
=
gpr_stack_lockfree_create
(
size
);
for
(
i
=
0
;
i
<
nth
;
i
++
)
{
for
(
i
=
0
;
i
<
nth
;
i
++
)
{
args
[
i
].
stack
=
stack
;
args
[
i
].
stack_size
=
size
;
args
[
i
].
nthreads
=
nth
;
...
...
@@ -132,17 +132,17 @@ static void test_mt_sized(int size, int nth) {
gpr_thd_join
(
thds
[
i
]);
sum
=
sum
+
args
[
i
].
sum
;
}
GPR_ASSERT
((
unsigned
)
sum
==
((
unsigned
)
size
*
(
size
-
1
))
/
2
);
GPR_ASSERT
((
unsigned
)
sum
==
((
unsigned
)
size
*
(
size
-
1
))
/
2
);
gpr_stack_lockfree_destroy
(
stack
);
}
static
void
test_mt
()
{
int
size
,
nth
;
for
(
nth
=
1
;
nth
<
MAX_THREADS
;
nth
++
)
{
for
(
size
=
128
;
size
<
MAX_STACK_SIZE
;
size
*=
2
)
{
test_mt_sized
(
size
,
nth
);
for
(
nth
=
1
;
nth
<
MAX_THREADS
;
nth
++
)
{
for
(
size
=
128
;
size
<
MAX_STACK_SIZE
;
size
*=
2
)
{
test_mt_sized
(
size
,
nth
);
}
test_mt_sized
(
MAX_STACK_SIZE
,
nth
);
test_mt_sized
(
MAX_STACK_SIZE
,
nth
);
}
}
...
...
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