diff --git a/atomicflag/atomicflag.go b/atomicflag/atomicflag.go new file mode 100644 index 0000000..6460365 --- /dev/null +++ b/atomicflag/atomicflag.go @@ -0,0 +1,27 @@ +package atomicflag + +import ( + "sync" +) + + +type atomicflag struct { + value bool + mutex sync.RWMutex +} + +func New(value bool) *atomicflag { + return &atomicflag{value: value} +} + +func (f* atomicflag) Get() bool { + f.mutex.RLock() + defer f.mutex.RUnlock() + return f.value +} + +func (f* atomicflag) Set(value bool) { + f.mutex.Lock() + defer f.mutex.Unlock() + f.value = value +}