pgraph: semaphore: Add lock around semaphore map

I forgot about the `concurrent map write` race, but now it's fixed. I
suppose we could probably pre-create all semaphores in the graph at once
before Start, and remove this lock, but that's an optimization for a
later day.
This commit is contained in:
James Shubin
2017-03-11 09:06:18 -05:00
parent b740e0b78a
commit 6d9be15035
2 changed files with 5 additions and 0 deletions

View File

@@ -61,6 +61,7 @@ type Graph struct {
mutex *sync.Mutex // used when modifying graph State variable
wg *sync.WaitGroup
semas map[string]*semaphore.Semaphore
slock *sync.Mutex // semaphore mutex
prometheus *prometheus.Prometheus // the prometheus instance
}
@@ -89,6 +90,7 @@ func NewGraph(name string) *Graph {
mutex: &sync.Mutex{},
wg: &sync.WaitGroup{},
semas: make(map[string]*semaphore.Semaphore),
slock: &sync.Mutex{},
}
}
@@ -126,6 +128,7 @@ func (g *Graph) Copy() *Graph {
mutex: g.mutex,
wg: g.wg,
semas: g.semas,
slock: g.slock,
prometheus: g.prometheus,
}