Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
5d0512d3
Unverified
Commit
5d0512d3
authored
Jul 21, 2020
by
jamesge
Committed by
GitHub
Jul 21, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1156 from zyearn/fix_share_tls_block
fix_share_tls_block
parents
b7b79824
65dfdd87
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
4 deletions
+34
-4
iobuf.cpp
src/butil/iobuf.cpp
+8
-4
iobuf_unittest.cpp
test/iobuf_unittest.cpp
+26
-0
No files found.
src/butil/iobuf.cpp
View file @
5d0512d3
...
...
@@ -358,7 +358,7 @@ void remove_tls_block_chain() {
// Get a (non-full) block from TLS.
// Notice that the block is not removed from TLS.
inline
IOBuf
::
Block
*
share_tls_block
()
{
IOBuf
::
Block
*
share_tls_block
()
{
TLSData
&
tls_data
=
g_tls_data
;
IOBuf
::
Block
*
const
b
=
tls_data
.
block_head
;
if
(
b
!=
NULL
&&
!
b
->
full
())
{
...
...
@@ -366,9 +366,13 @@ inline IOBuf::Block* share_tls_block() {
}
IOBuf
::
Block
*
new_block
=
NULL
;
if
(
b
)
{
new_block
=
b
->
portal_next
;
b
->
dec_ref
();
--
tls_data
.
num_blocks
;
new_block
=
b
;
while
(
new_block
&&
new_block
->
full
())
{
IOBuf
::
Block
*
const
saved_next
=
new_block
->
portal_next
;
new_block
->
dec_ref
();
--
tls_data
.
num_blocks
;
new_block
=
saved_next
;
}
}
else
if
(
!
tls_data
.
registered
)
{
tls_data
.
registered
=
true
;
// Only register atexit at the first time
...
...
test/iobuf_unittest.cpp
View file @
5d0512d3
...
...
@@ -47,6 +47,7 @@ extern IOBuf::Block* get_tls_block_head();
extern
int
get_tls_block_count
();
extern
void
remove_tls_block_chain
();
extern
IOBuf
::
Block
*
acquire_tls_block
();
extern
IOBuf
::
Block
*
share_tls_block
();
extern
void
release_tls_block_chain
(
IOBuf
::
Block
*
b
);
extern
uint32_t
block_cap
(
IOBuf
::
Block
const
*
b
);
extern
uint32_t
block_size
(
IOBuf
::
Block
const
*
b
);
...
...
@@ -1656,6 +1657,31 @@ TEST_F(IOBufTest, append_user_data_and_share) {
ASSERT_EQ
(
data
,
my_free_params
);
}
TEST_F
(
IOBufTest
,
share_tls_block
)
{
butil
::
iobuf
::
remove_tls_block_chain
();
butil
::
IOBuf
::
Block
*
b
=
butil
::
iobuf
::
acquire_tls_block
();
ASSERT_EQ
(
0
,
butil
::
iobuf
::
block_size
(
b
));
butil
::
IOBuf
::
Block
*
b2
=
butil
::
iobuf
::
share_tls_block
();
butil
::
IOBuf
buf
;
for
(
size_t
i
=
0
;
i
<
butil
::
iobuf
::
block_cap
(
b2
);
i
++
)
{
buf
.
push_back
(
'x'
);
}
// after pushing to b2, b2 is full but it is still head of tls block.
ASSERT_NE
(
b
,
b2
);
butil
::
iobuf
::
release_tls_block_chain
(
b
);
ASSERT_EQ
(
b
,
butil
::
iobuf
::
share_tls_block
());
// After releasing b, now tls block is b(not full) -> b2(full) -> NULL
for
(
size_t
i
=
0
;
i
<
butil
::
iobuf
::
block_cap
(
b
);
i
++
)
{
buf
.
push_back
(
'x'
);
}
// now tls block is b(full) -> b2(full) -> NULL
butil
::
IOBuf
::
Block
*
head_block
=
butil
::
iobuf
::
share_tls_block
();
ASSERT_EQ
(
0
,
butil
::
iobuf
::
block_size
(
head_block
));
ASSERT_NE
(
b
,
head_block
);
ASSERT_NE
(
b2
,
head_block
);
}
TEST_F
(
IOBufTest
,
acquire_tls_block
)
{
butil
::
iobuf
::
remove_tls_block_chain
();
butil
::
IOBuf
::
Block
*
b
=
butil
::
iobuf
::
acquire_tls_block
();
...
...
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