Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
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
张蕾
Geth-Modification
Commits
d04bde0a
Unverified
Commit
d04bde0a
authored
Aug 01, 2023
by
ucwong
Committed by
GitHub
Aug 01, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
p2p: use atomic types (#27764)
Co-authored-by:
Felix Lange
<
fjl@twurst.com
>
parent
ff97b4cc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
6 deletions
+5
-6
message.go
p2p/message.go
+5
-6
No files found.
p2p/message.go
View file @
d04bde0a
...
...
@@ -156,7 +156,7 @@ func MsgPipe() (*MsgPipeRW, *MsgPipeRW) {
var
(
c1
,
c2
=
make
(
chan
Msg
),
make
(
chan
Msg
)
closing
=
make
(
chan
struct
{})
closed
=
new
(
int32
)
closed
=
new
(
atomic
.
Bool
)
rw1
=
&
MsgPipeRW
{
c1
,
c2
,
closing
,
closed
}
rw2
=
&
MsgPipeRW
{
c2
,
c1
,
closing
,
closed
}
)
...
...
@@ -172,13 +172,13 @@ type MsgPipeRW struct {
w
chan
<-
Msg
r
<-
chan
Msg
closing
chan
struct
{}
closed
*
int32
closed
*
atomic
.
Bool
}
// WriteMsg sends a message on the pipe.
// It blocks until the receiver has consumed the message payload.
func
(
p
*
MsgPipeRW
)
WriteMsg
(
msg
Msg
)
error
{
if
atomic
.
LoadInt32
(
p
.
closed
)
==
0
{
if
!
p
.
closed
.
Load
()
{
consumed
:=
make
(
chan
struct
{},
1
)
msg
.
Payload
=
&
eofSignal
{
msg
.
Payload
,
msg
.
Size
,
consumed
}
select
{
...
...
@@ -199,7 +199,7 @@ func (p *MsgPipeRW) WriteMsg(msg Msg) error {
// ReadMsg returns a message sent on the other end of the pipe.
func
(
p
*
MsgPipeRW
)
ReadMsg
()
(
Msg
,
error
)
{
if
atomic
.
LoadInt32
(
p
.
closed
)
==
0
{
if
!
p
.
closed
.
Load
()
{
select
{
case
msg
:=
<-
p
.
r
:
return
msg
,
nil
...
...
@@ -213,9 +213,8 @@ func (p *MsgPipeRW) ReadMsg() (Msg, error) {
// of the pipe. They will return ErrPipeClosed. Close also
// interrupts any reads from a message payload.
func
(
p
*
MsgPipeRW
)
Close
()
error
{
if
atomic
.
AddInt32
(
p
.
closed
,
1
)
!=
1
{
if
p
.
closed
.
Swap
(
true
)
{
// someone else is already closing
atomic
.
StoreInt32
(
p
.
closed
,
1
)
// avoid overflow
return
nil
}
close
(
p
.
closing
)
...
...
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