From bfb44f885468839259bc2ead999953cdd85654e1 Mon Sep 17 00:00:00 2001 From: Ethan Koenig Date: Wed, 31 May 2017 04:57:17 -0400 Subject: Fix status table race condition (#1835) --- modules/sync/status_pool.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'modules/sync/status_pool.go') diff --git a/modules/sync/status_pool.go b/modules/sync/status_pool.go index 46d15aa08c..acbd93ab17 100644 --- a/modules/sync/status_pool.go +++ b/modules/sync/status_pool.go @@ -24,6 +24,18 @@ func NewStatusTable() *StatusTable { } } +// StartIfNotRunning sets value of given name to true if not already in pool. +// Returns whether set value was set to true +func (p *StatusTable) StartIfNotRunning(name string) bool { + p.lock.Lock() + _, ok := p.pool[name] + if !ok { + p.pool[name] = struct{}{} + } + p.lock.Unlock() + return !ok +} + // Start sets value of given name to true in the pool. func (p *StatusTable) Start(name string) { p.lock.Lock() -- cgit v1.2.3