Skip to content
Snippets Groups Projects
Unverified Commit 6d129c7f authored by Angelo Capossele's avatar Angelo Capossele Committed by GitHub
Browse files

Make gossip mutex RW (#649)

* :zap: Make gossip mutex RW

* :zap: Make getNeighborsByID to use mutex in read mode
parent 4554a1ff
Branches
Tags
No related merge requests found
...@@ -32,7 +32,7 @@ type Manager struct { ...@@ -32,7 +32,7 @@ type Manager struct {
wg sync.WaitGroup wg sync.WaitGroup
mu sync.Mutex mu sync.RWMutex
srv *server.TCP srv *server.TCP
neighbors map[identity.ID]*Neighbor neighbors map[identity.ID]*Neighbor
...@@ -149,8 +149,8 @@ func (m *Manager) SendMessage(msgData []byte, to ...identity.ID) { ...@@ -149,8 +149,8 @@ func (m *Manager) SendMessage(msgData []byte, to ...identity.ID) {
// AllNeighbors returns all the neighbors that are currently connected. // AllNeighbors returns all the neighbors that are currently connected.
func (m *Manager) AllNeighbors() []*Neighbor { func (m *Manager) AllNeighbors() []*Neighbor {
m.mu.Lock() m.mu.RLock()
defer m.mu.Unlock() defer m.mu.RUnlock()
result := make([]*Neighbor, 0, len(m.neighbors)) result := make([]*Neighbor, 0, len(m.neighbors))
for _, n := range m.neighbors { for _, n := range m.neighbors {
...@@ -169,8 +169,8 @@ func (m *Manager) getNeighbors(ids ...identity.ID) []*Neighbor { ...@@ -169,8 +169,8 @@ func (m *Manager) getNeighbors(ids ...identity.ID) []*Neighbor {
func (m *Manager) getNeighborsByID(ids []identity.ID) []*Neighbor { func (m *Manager) getNeighborsByID(ids []identity.ID) []*Neighbor {
result := make([]*Neighbor, 0, len(ids)) result := make([]*Neighbor, 0, len(ids))
m.mu.Lock() m.mu.RLock()
defer m.mu.Unlock() defer m.mu.RUnlock()
for _, id := range ids { for _, id := range ids {
if n, ok := m.neighbors[id]; ok { if n, ok := m.neighbors[id]; ok {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment