Skip to content
Myr

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 file

Take 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 back
1package util
2

Update AtomicBool to use atomic memory operation (#1939)Alexandrbefore adoptiona6a732e

lines 3–5why, one step back
3import (
4 "sync/atomic"5)

Add preview-fg and preview-bg for --colorJunegunn Choibefore adoption3db6b88

line 6why, one step back
6

Update AtomicBool to use atomic memory operation (#1939)Alexandrbefore adoptiona6a732e

lines 7–13why, one step back
7func convertBoolToInt32(b bool) int32 {
8 if b {9 return 110 }11 return 012}13

Add preview-fg and preview-bg for --colorJunegunn Choibefore adoption3db6b88

lines 14–16why, one step back
14// AtomicBool is a boxed-class that provides synchronized access to the
15// underlying boolean value16type AtomicBool struct {

Update AtomicBool to use atomic memory operation (#1939)Alexandrbefore adoptiona6a732e

line 17why, one step back
17 state int32 // "1" is true, "0" is false

Add preview-fg and preview-bg for --colorJunegunn Choibefore adoption3db6b88

lines 18–21why, one step back
18}
1920// NewAtomicBool returns a new AtomicBool21func NewAtomicBool(initialState bool) *AtomicBool {

Update AtomicBool to use atomic memory operation (#1939)Alexandrbefore adoptiona6a732e

line 22why, one step back
22 return &AtomicBool{state: convertBoolToInt32(initialState)}

Add preview-fg and preview-bg for --colorJunegunn Choibefore adoption3db6b88

lines 23–26why, one step back
23}
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 back
27 return atomic.LoadInt32(&a.state) == 1

Add preview-fg and preview-bg for --colorJunegunn Choibefore adoption3db6b88

lines 28–31why, one step back
28}
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 back
32 atomic.StoreInt32(&a.state, convertBoolToInt32(newState))
33 return newState

Add preview-fg and preview-bg for --colorJunegunn Choibefore adoption3db6b88

line 34why, one step back
34}