Skip to content

Commit

Permalink
added Flag, a simple atomic "bool"
Browse files Browse the repository at this point in the history
  • Loading branch information
OneOfOne committed Sep 12, 2014
1 parent 4de148b commit f94073d
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions sync/flag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package sync

import "sync/atomic"

type Flag struct {
f uint32
}

func (a *Flag) Set() {
atomic.StoreUint32(&a.f, 1)
}

func (a *Flag) Clear() {
atomic.StoreUint32(&a.f, 0)
}

func (a *Flag) IsSet() bool {
return atomic.LoadUint32(&a.f) == 1
}

func (a *Flag) String() string {
if a.IsSet() {
return "true"
}
return "false"
}

0 comments on commit f94073d

Please sign in to comment.