Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-bitswap
Commits
c26bd59d
Commit
c26bd59d
authored
Apr 17, 2020
by
Dirk McCormick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: perf improvement for connectEventManager
parent
c233956c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
5 deletions
+21
-5
network/connecteventmanager.go
network/connecteventmanager.go
+21
-5
No files found.
network/connecteventmanager.go
View file @
c26bd59d
...
...
@@ -13,7 +13,7 @@ type ConnectionListener interface {
type
connectEventManager
struct
{
connListener
ConnectionListener
lk
sync
.
Mutex
lk
sync
.
RW
Mutex
conns
map
[
peer
.
ID
]
*
connState
}
...
...
@@ -78,12 +78,28 @@ func (c *connectEventManager) MarkUnresponsive(p peer.ID) {
}
func
(
c
*
connectEventManager
)
OnMessage
(
p
peer
.
ID
)
{
// This is a frequent operation so to avoid different message arrivals
// getting blocked by a write lock, first take a read lock to check if
// we need to modify state
c
.
lk
.
RLock
()
state
,
ok
:=
c
.
conns
[
p
]
c
.
lk
.
RUnlock
()
if
!
ok
||
state
.
responsive
{
return
}
// We need to make a modification so now take a write lock
c
.
lk
.
Lock
()
defer
c
.
lk
.
Unlock
()
state
,
ok
:=
c
.
conns
[
p
]
if
ok
&&
!
state
.
responsive
{
state
.
responsive
=
true
c
.
connListener
.
PeerConnected
(
p
)
// Note: state may have changed in the time between when read lock
// was released and write lock taken, so check again
state
,
ok
=
c
.
conns
[
p
]
if
!
ok
||
state
.
responsive
{
return
}
state
.
responsive
=
true
c
.
connListener
.
PeerConnected
(
p
)
}
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