atomicbool.go
This file
Path
src/util/atomicbool.go
34 lines · 748 bytes · Go
Last changed by
Update AtomicBool to use atomic memory operation (#1939)Alexandrbefore adoptiona6a732e
History of this fileTake it
The walk stopped after 200 commits: lines older than 3db6b88 point at it.
Add preview-fg and preview-bg for --colorJunegunn Choibefore adoption3db6b88
lines 1–2why, one step back1package util2Update AtomicBool to use atomic memory operation (#1939)Alexandrbefore adoptiona6a732e
lines 3–5why, one step back3import (4 "sync/atomic"5)Add preview-fg and preview-bg for --colorJunegunn Choibefore adoption3db6b88
line 6why, one step back6Update AtomicBool to use atomic memory operation (#1939)Alexandrbefore adoptiona6a732e
lines 7–13why, one step back7func convertBoolToInt32(b bool) int32 {8 if b {9 return 110 }11 return 012}13Add preview-fg and preview-bg for --colorJunegunn Choibefore adoption3db6b88
lines 14–16why, one step back14// AtomicBool is a boxed-class that provides synchronized access to the15// underlying boolean value16type AtomicBool struct {Update AtomicBool to use atomic memory operation (#1939)Alexandrbefore adoptiona6a732e
line 17why, one step back17 state int32 // "1" is true, "0" is falseAdd preview-fg and preview-bg for --colorJunegunn Choibefore adoption3db6b88
lines 18–21why, one step back18}1920// NewAtomicBool returns a new AtomicBool21func NewAtomicBool(initialState bool) *AtomicBool {Update AtomicBool to use atomic memory operation (#1939)Alexandrbefore adoptiona6a732e
line 22why, one step back22 return &AtomicBool{state: convertBoolToInt32(initialState)}Add preview-fg and preview-bg for --colorJunegunn Choibefore adoption3db6b88
lines 23–26why, one step back23}2425// Get returns the current boolean value synchronously26func (a *AtomicBool) Get() bool {Update AtomicBool to use atomic memory operation (#1939)Alexandrbefore adoptiona6a732e
line 27why, one step back27 return atomic.LoadInt32(&a.state) == 1Add preview-fg and preview-bg for --colorJunegunn Choibefore adoption3db6b88
lines 28–31why, one step back28}2930// Set updates the boolean value synchronously31func (a *AtomicBool) Set(newState bool) bool {Update AtomicBool to use atomic memory operation (#1939)Alexandrbefore adoptiona6a732e
lines 32–33why, one step back32 atomic.StoreInt32(&a.state, convertBoolToInt32(newState))33 return newStateAdd preview-fg and preview-bg for --colorJunegunn Choibefore adoption3db6b88
line 34why, one step back34}