atomicvar

package
v0.0.0-...-bb1a4e7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2020 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package atomicvar provides atomic Boolean type for cleaner code and better performance.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AtomicBoolInt32

type AtomicBoolInt32 int32

AtomicBoolInt32 is an atomic Boolean Its methods are all atomic, thus safe to be called by multiple goroutines simultaneously Note: When embedding into a struct, one should always use *AtomicBoolInt32 to avoid copy

Example
cond := New()    // default to false
cond.Set()       // set to true
cond.IsSet()     // returns true
cond.UnSet()     // set to false
cond.SetTo(true) // set to whatever you want
Output:

func New

func New() *AtomicBoolInt32

New creates an AtomicBoolInt32 with default to false

func NewBool

func NewBool(ok bool) *AtomicBoolInt32

NewBool creates an AtomicBoolInt32 with given default value

func (*AtomicBoolInt32) IsSet

func (ab *AtomicBoolInt32) IsSet() bool

IsTrue returns whether the Boolean is true

func (*AtomicBoolInt32) Set

func (ab *AtomicBoolInt32) Set()

Set sets the Boolean to true

func (*AtomicBoolInt32) SetTo

func (ab *AtomicBoolInt32) SetTo(yes bool)

SetTo sets the boolean with given Boolean

func (*AtomicBoolInt32) SetToIf

func (ab *AtomicBoolInt32) SetToIf(old, new bool) (set bool)

SetToIf sets the Boolean to new only if the Boolean matches the old Returns whether the set was done

func (*AtomicBoolInt32) UnSet

func (ab *AtomicBoolInt32) UnSet()

UnSet sets the Boolean to false

type AtomicBoolUint32

type AtomicBoolUint32 uint32

func (*AtomicBoolUint32) IsFalse

func (b *AtomicBoolUint32) IsFalse() bool

func (*AtomicBoolUint32) IsTrue

func (b *AtomicBoolUint32) IsTrue() bool

func (*AtomicBoolUint32) SetFalse

func (b *AtomicBoolUint32) SetFalse()

func (*AtomicBoolUint32) SetTrue

func (b *AtomicBoolUint32) SetTrue()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL