/
githubmirror
/
fzf
Обзор
Документация
Войти
/
githubmirror
/
fzf
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/util/atomicbool.go
34 строки
748 B
Alexandr
Update AtomicBool to use atomic memory operation (#1939)
29 мар 2020, 19:42
Не верифицирован
29 мар 2020, 19:42
a6a732e
Код
Авторство
О чём код?
package util import ( "sync/atomic" ) func convertBoolToInt32(b bool) int32 { if b { return 1 } return 0 } // AtomicBool is a boxed-class that provides synchronized access to the // underlying boolean value type AtomicBool struct { state int32 // "1" is true, "0" is false } // NewAtomicBool returns a new AtomicBool func NewAtomicBool(initialState bool) *AtomicBool { return &AtomicBool{state: convertBoolToInt32(initialState)} } // Get returns the current boolean value synchronously func (a *AtomicBool) Get() bool { return atomic.LoadInt32(&a.state) == 1 } // Set updates the boolean value synchronously func (a *AtomicBool) Set(newState bool) bool { atomic.StoreInt32(&a.state, convertBoolToInt32(newState)) return newState }