Sha256: 6a3cb13eda99760e04a6030c252c02a7b5807afd03726c6a8dae14b1946b0ed6

Contents?: true

Size: 748 Bytes

Versions: 87

Compression:

Stored size: 748 Bytes

Contents

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
}

Version data entries

87 entries across 87 versions & 1 rubygems

Version Path
doing-2.1.88 lib/helpers/fzf/src/util/atomicbool.go
doing-2.1.87 lib/helpers/fzf/src/util/atomicbool.go
doing-2.1.86 lib/helpers/fzf/src/util/atomicbool.go
doing-2.1.85 lib/helpers/fzf/src/util/atomicbool.go
doing-2.1.84 lib/helpers/fzf/src/util/atomicbool.go
doing-2.1.83 lib/helpers/fzf/src/util/atomicbool.go
doing-2.1.82 lib/helpers/fzf/src/util/atomicbool.go
doing-2.1.81 lib/helpers/fzf/src/util/atomicbool.go
doing-2.1.80 lib/helpers/fzf/src/util/atomicbool.go
doing-2.1.79 lib/helpers/fzf/src/util/atomicbool.go
doing-2.1.78 lib/helpers/fzf/src/util/atomicbool.go
doing-2.1.77 lib/helpers/fzf/src/util/atomicbool.go
doing-2.1.76 lib/helpers/fzf/src/util/atomicbool.go
doing-2.1.75 lib/helpers/fzf/src/util/atomicbool.go
doing-2.1.74 lib/helpers/fzf/src/util/atomicbool.go
doing-2.1.73 lib/helpers/fzf/src/util/atomicbool.go
doing-2.1.72 lib/helpers/fzf/src/util/atomicbool.go
doing-2.1.69 lib/helpers/fzf/src/util/atomicbool.go
doing-2.1.68 lib/helpers/fzf/src/util/atomicbool.go
doing-2.1.66 lib/helpers/fzf/src/util/atomicbool.go