Compare commits

...

2 Commits

Author SHA1 Message Date
Martin Geno
4628a8d5ab
correction + go deadlock 2017-05-22 12:22:44 +02:00
Martin Geno
34a920e01f
[BUGFIX] mutex like it should be 2017-05-22 12:22:44 +02:00
3 changed files with 12 additions and 8 deletions

View File

@ -50,7 +50,7 @@ func BuildGraph(nodes *runtime.Nodes) *Graph {
vpn: make(map[string]interface{}), vpn: make(map[string]interface{}),
} }
builder.readNodes(nodes.List) builder.readNodes(nodes)
graph := &Graph{Version: 1} graph := &Graph{Version: 1}
graph.Batadv.Directed = false graph.Batadv.Directed = false
@ -58,9 +58,12 @@ func BuildGraph(nodes *runtime.Nodes) *Graph {
return graph return graph
} }
func (builder *graphBuilder) readNodes(nodes map[string]*runtime.Node) { func (builder *graphBuilder) readNodes(nodes *runtime.Nodes) {
nodes.RLock()
defer nodes.RUnlock()
// Fill mac->id map // Fill mac->id map
for sourceID, node := range nodes { for sourceID, node := range nodes.List {
if nodeinfo := node.Nodeinfo; nodeinfo != nil { if nodeinfo := node.Nodeinfo; nodeinfo != nil {
// is VPN address? // is VPN address?
if nodeinfo.VPN { if nodeinfo.VPN {
@ -91,7 +94,7 @@ func (builder *graphBuilder) readNodes(nodes map[string]*runtime.Node) {
} }
// Add links // Add links
for sourceID, node := range nodes { for sourceID, node := range nodes.List {
if node.Online { if node.Online {
if neighbours := node.Neighbours; neighbours != nil { if neighbours := node.Neighbours; neighbours != nil {
// Batman neighbours // Batman neighbours

View File

@ -4,9 +4,10 @@ import (
"encoding/json" "encoding/json"
"log" "log"
"os" "os"
"sync"
"time" "time"
"github.com/sasha-s/go-deadlock"
"github.com/FreifunkBremen/yanic/data" "github.com/FreifunkBremen/yanic/data"
"github.com/FreifunkBremen/yanic/jsontime" "github.com/FreifunkBremen/yanic/jsontime"
) )
@ -15,7 +16,7 @@ import (
type Nodes struct { type Nodes struct {
List map[string]*Node `json:"nodes"` // the current nodemap, indexed by node ID List map[string]*Node `json:"nodes"` // the current nodemap, indexed by node ID
config *Config config *Config
sync.RWMutex deadlock.RWMutex
} }
// NewNodes create Nodes structs // NewNodes create Nodes structs

View File

@ -23,7 +23,7 @@ func NewGlobalStats(nodes *Nodes) (result *GlobalStats) {
Models: make(CounterMap), Models: make(CounterMap),
} }
nodes.Lock() nodes.RLock()
for _, node := range nodes.List { for _, node := range nodes.List {
if node.Online { if node.Online {
result.Nodes++ result.Nodes++
@ -42,7 +42,7 @@ func NewGlobalStats(nodes *Nodes) (result *GlobalStats) {
} }
} }
} }
nodes.Unlock() nodes.RUnlock()
return return
} }