Skip to content

Commit

Permalink
fix lock bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
richard9219 committed Nov 7, 2018
1 parent 2470d24 commit 5055c5a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions protocol/block/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func (s *synchronizes) syncBlockNumberCheck() {

func (s *synchronizes) recordPeerSyncTimeout(index uint16) {
s.lock.Lock()
s.lock.Unlock()
defer s.lock.Unlock()

peer, ok := s.peers[index]
if ok {
Expand All @@ -427,7 +427,7 @@ func (s *synchronizes) recordPeerSyncTimeout(index uint16) {

func (s *synchronizes) resetPeerSyncTimeout() {
s.lock.Lock()
s.lock.Unlock()
defer s.lock.Unlock()

for _, info := range s.peers {
info.syncTimeoutCounter = 0
Expand All @@ -436,7 +436,7 @@ func (s *synchronizes) resetPeerSyncTimeout() {

func (s *synchronizes) getPeers() syncset {
s.lock.Lock()
s.lock.Unlock()
defer s.lock.Unlock()

var peerset syncset
for _, info := range s.peers {
Expand Down
6 changes: 3 additions & 3 deletions protocol/discover/pne.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func makeNeighbors() *neighbors {
//AddNeighbor add new neighbor
func (n *neighbors) addNeighbor(peers []p2p.PeerInfo) {
n.lock.Lock()
n.lock.Unlock()
defer n.lock.Unlock()

//filter neighbor which is exist
for j := range peers {
Expand Down Expand Up @@ -283,7 +283,7 @@ func (n *neighbors) addNeighbor(peers []p2p.PeerInfo) {
//DelNeighbor delete neighbor
func (n *neighbors) delNeighbor(peer p2p.PeerInfo) {
n.lock.Lock()
n.lock.Unlock()
defer n.lock.Unlock()

//find addr and remove
var count uint16
Expand All @@ -305,7 +305,7 @@ func (n *neighbors) delNeighbor(peer p2p.PeerInfo) {
//NextPneNeighbors get neighbors to discover
func (n *neighbors) nextPneNeighbors() []p2p.PeerInfo {
n.lock.Lock()
n.lock.Unlock()
defer n.lock.Unlock()

len := n.neighbor.Len()
if len <= 0 {
Expand Down

1 comment on commit 5055c5a

@richard9219
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixes #5

Please sign in to comment.