mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-06-25 16:17:12 +08:00
Conflicts: Gopkg.lock pkg/appsrv/appsrv.go pkg/cloudcommon/options.go pkg/compute/models/hosts.go pkg/compute/models/quotas.go pkg/compute/service/service.go pkg/mcclient/mcclient.go
42 lines
753 B
Go
42 lines
753 B
Go
package missinggo
|
|
|
|
import "sync"
|
|
|
|
// Flag represents a boolean value, that signals sync.Cond's when it changes.
|
|
// It's not concurrent safe by intention.
|
|
type Flag struct {
|
|
Conds map[*sync.Cond]struct{}
|
|
value bool
|
|
}
|
|
|
|
func (me *Flag) Set(value bool) {
|
|
if value != me.value {
|
|
me.broadcastChange()
|
|
}
|
|
me.value = value
|
|
}
|
|
|
|
func (me *Flag) Get() bool {
|
|
return me.value
|
|
}
|
|
|
|
func (me *Flag) broadcastChange() {
|
|
for cond := range me.Conds {
|
|
cond.Broadcast()
|
|
}
|
|
}
|
|
|
|
func (me *Flag) addCond(c *sync.Cond) {
|
|
if me.Conds == nil {
|
|
me.Conds = make(map[*sync.Cond]struct{})
|
|
}
|
|
me.Conds[c] = struct{}{}
|
|
}
|
|
|
|
// Adds the sync.Cond to all the given Flag's.
|
|
func AddCondToFlags(cond *sync.Cond, flags ...*Flag) {
|
|
for _, f := range flags {
|
|
f.addCond(cond)
|
|
}
|
|
}
|