atomic

package
v0.0.0-...-29c100b Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2017 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Example
package main

import (
	"fmt"

	"github.com/zxfonline/atomic"
)

func main() {
	// Uint32 is a thin wrapper around the primitive uint32 type.
	var atom atomic.Uint32

	// The wrapper ensures that all operations are atomic.
	atom.Store(42)
	fmt.Println(atom.Inc())
	fmt.Println(atom.CAS(43, 0))
	bb, _ := atom.MarshalBinary()
	atom.UnmarshalBinary(bb)
	fmt.Println(atom.Load())

}
Output:

43
true
0

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultEndian = binary.BigEndian

默认字节序 大端法

Functions

This section is empty.

Types

type Bool

type Bool struct {
	// contains filtered or unexported fields
}

Bool is an atomic Boolean.

func NewBool

func NewBool(initial bool) *Bool

NewBool creates a Bool.

func (*Bool) GobDecode

func (b *Bool) GobDecode(data []byte) error

func (*Bool) GobEncode

func (b *Bool) GobEncode() ([]byte, error)

func (*Bool) Load

func (b *Bool) Load() bool

Load atomically loads the Boolean.

func (*Bool) MarshalBinary

func (b *Bool) MarshalBinary() ([]byte, error)

func (*Bool) MarshalJSON

func (b *Bool) MarshalJSON() ([]byte, error)

func (*Bool) MarshalText

func (b *Bool) MarshalText() ([]byte, error)

func (*Bool) Store

func (b *Bool) Store(newz bool)

Store atomically stores the passed value.

func (*Bool) Swap

func (b *Bool) Swap(newz bool) bool

Swap sets the given value and returns the previous value.

func (*Bool) Toggle

func (b *Bool) Toggle() bool

Toggle atomically negates the Boolean and returns the previous value.

func (*Bool) UnmarshalBinary

func (b *Bool) UnmarshalBinary(data []byte) error

func (*Bool) UnmarshalJSON

func (b *Bool) UnmarshalJSON(data []byte) error

func (*Bool) UnmarshalText

func (b *Bool) UnmarshalText(data []byte) error

type Float32

type Float32 struct {
	// contains filtered or unexported fields
}

Float32 is an atomic wrapper around float32.

func NewFloat32

func NewFloat32(f float32) *Float32

NewFloat32 creates a Float32.

func (*Float32) CAS

func (f *Float32) CAS(old, newz float32) bool

CAS is an atomic compare-and-swap.

func (*Float32) GobDecode

func (f *Float32) GobDecode(data []byte) error

func (*Float32) GobEncode

func (f *Float32) GobEncode() ([]byte, error)

func (*Float32) Load

func (f *Float32) Load() float32

Load atomically loads the wrapped value.

func (*Float32) MarshalBinary

func (f *Float32) MarshalBinary() ([]byte, error)

func (*Float32) MarshalJSON

func (f *Float32) MarshalJSON() ([]byte, error)

func (*Float32) MarshalText

func (f *Float32) MarshalText() ([]byte, error)

func (*Float32) Store

func (f *Float32) Store(s float32)

Store atomically stores the passed value.

func (*Float32) UnmarshalBinary

func (f *Float32) UnmarshalBinary(data []byte) error

func (*Float32) UnmarshalJSON

func (f *Float32) UnmarshalJSON(data []byte) error

func (*Float32) UnmarshalText

func (f *Float32) UnmarshalText(data []byte) error

type Float64

type Float64 struct {
	// contains filtered or unexported fields
}

Float64 is an atomic wrapper around float64.

func NewFloat64

func NewFloat64(f float64) *Float64

NewFloat64 creates a Float64.

func (*Float64) CAS

func (f *Float64) CAS(old, newz float64) bool

CAS is an atomic compare-and-swap.

func (*Float64) GobDecode

func (f *Float64) GobDecode(data []byte) error

func (*Float64) GobEncode

func (f *Float64) GobEncode() ([]byte, error)

func (*Float64) Load

func (f *Float64) Load() float64

Load atomically loads the wrapped value.

func (*Float64) MarshalBinary

func (f *Float64) MarshalBinary() ([]byte, error)

func (*Float64) MarshalJSON

func (f *Float64) MarshalJSON() ([]byte, error)

func (*Float64) MarshalText

func (f *Float64) MarshalText() ([]byte, error)

func (*Float64) Store

func (f *Float64) Store(s float64)

Store atomically stores the passed value.

func (*Float64) UnmarshalBinary

func (f *Float64) UnmarshalBinary(data []byte) error

func (*Float64) UnmarshalJSON

func (f *Float64) UnmarshalJSON(data []byte) error

func (*Float64) UnmarshalText

func (f *Float64) UnmarshalText(data []byte) error

type Int32

type Int32 struct {
	// contains filtered or unexported fields
}

Int32 is an atomic wrapper around an int32.

func NewInt32

func NewInt32(i int32) *Int32

NewInt32 creates an Int32.

func (*Int32) Add

func (i *Int32) Add(n int32) int32

Add atomically adds to the wrapped int32 and returns the new value.

func (*Int32) CAS

func (i *Int32) CAS(old, newz int32) bool

CAS is an atomic compare-and-swap.

func (*Int32) Dec

func (i *Int32) Dec() int32

Dec atomically decrements the wrapped int32 and returns the new value.

func (*Int32) GobDecode

func (i *Int32) GobDecode(data []byte) error

func (*Int32) GobEncode

func (i *Int32) GobEncode() ([]byte, error)

func (*Int32) Inc

func (i *Int32) Inc() int32

Inc atomically increments the wrapped int32 and returns the new value.

func (*Int32) Load

func (i *Int32) Load() int32

Load atomically loads the wrapped value.

func (*Int32) MarshalBinary

func (i *Int32) MarshalBinary() ([]byte, error)

func (*Int32) MarshalJSON

func (i *Int32) MarshalJSON() ([]byte, error)

func (*Int32) MarshalText

func (i *Int32) MarshalText() ([]byte, error)

func (*Int32) Store

func (i *Int32) Store(n int32)

Store atomically stores the passed value.

func (*Int32) Sub

func (i *Int32) Sub(n int32) int32

Sub atomically subtracts from the wrapped int32 and returns the new value.

func (*Int32) Swap

func (i *Int32) Swap(n int32) int32

Swap atomically swaps the wrapped int32 and returns the old value.

func (*Int32) UnmarshalBinary

func (i *Int32) UnmarshalBinary(data []byte) error

func (*Int32) UnmarshalJSON

func (i *Int32) UnmarshalJSON(data []byte) error

func (*Int32) UnmarshalText

func (i *Int32) UnmarshalText(data []byte) error

type Int64

type Int64 struct {
	// contains filtered or unexported fields
}

Int64 is an atomic wrapper around an int64.

func NewInt64

func NewInt64(i int64) *Int64

NewInt64 creates an Int64.

func (*Int64) Add

func (i *Int64) Add(n int64) int64

Add atomically adds to the wrapped int64 and returns the new value.

func (*Int64) CAS

func (i *Int64) CAS(old, newz int64) bool

CAS is an atomic compare-and-swap.

func (*Int64) Dec

func (i *Int64) Dec() int64

Dec atomically decrements the wrapped int64 and returns the new value.

func (*Int64) GobDecode

func (i *Int64) GobDecode(data []byte) error

func (*Int64) GobEncode

func (i *Int64) GobEncode() ([]byte, error)

func (*Int64) Inc

func (i *Int64) Inc() int64

Inc atomically increments the wrapped int64 and returns the new value.

func (*Int64) Load

func (i *Int64) Load() int64

Load atomically loads the wrapped value.

func (*Int64) MarshalBinary

func (i *Int64) MarshalBinary() ([]byte, error)

func (*Int64) MarshalJSON

func (i *Int64) MarshalJSON() ([]byte, error)

func (*Int64) MarshalText

func (i *Int64) MarshalText() ([]byte, error)

func (*Int64) Store

func (i *Int64) Store(n int64)

Store atomically stores the passed value.

func (*Int64) Sub

func (i *Int64) Sub(n int64) int64

Sub atomically subtracts from the wrapped int64 and returns the new value.

func (*Int64) Swap

func (i *Int64) Swap(n int64) int64

Swap atomically swaps the wrapped int64 and returns the old value.

func (*Int64) UnmarshalBinary

func (i *Int64) UnmarshalBinary(data []byte) error

func (*Int64) UnmarshalJSON

func (i *Int64) UnmarshalJSON(data []byte) error

func (*Int64) UnmarshalText

func (i *Int64) UnmarshalText(data []byte) error

type String

type String struct {
	// contains filtered or unexported fields
}

String is an atomic type-safe wrapper around atomic.Value for strings.

func NewString

func NewString(str string) *String

NewString creates a String.

func (*String) GobDecode

func (s *String) GobDecode(data []byte) error

func (*String) GobEncode

func (s *String) GobEncode() ([]byte, error)

func (*String) Load

func (s *String) Load() string

Load atomically loads the wrapped string.

func (*String) MarshalBinary

func (s *String) MarshalBinary() ([]byte, error)

func (*String) MarshalJSON

func (s *String) MarshalJSON() ([]byte, error)

func (*String) MarshalText

func (s *String) MarshalText() ([]byte, error)

func (*String) Store

func (s *String) Store(str string)

Store atomically stores the passed string. Note: Converting the string to an interface{} to store in the atomic.Value requires an allocation.

func (*String) UnmarshalBinary

func (s *String) UnmarshalBinary(data []byte) error

func (*String) UnmarshalJSON

func (s *String) UnmarshalJSON(data []byte) error

func (*String) UnmarshalText

func (s *String) UnmarshalText(data []byte) error

type Uint32

type Uint32 struct {
	// contains filtered or unexported fields
}

Uint32 is an atomic wrapper around an uint32.

func NewUint32

func NewUint32(i uint32) *Uint32

NewUint32 creates a Uint32.

func (*Uint32) Add

func (i *Uint32) Add(n uint32) uint32

Add atomically adds to the wrapped uint32 and returns the new value.

func (*Uint32) CAS

func (i *Uint32) CAS(old, newz uint32) bool

CAS is an atomic compare-and-swap.

func (*Uint32) Dec

func (i *Uint32) Dec() uint32

Dec atomically decrements the wrapped int32 and returns the new value.

func (*Uint32) GobDecode

func (i *Uint32) GobDecode(data []byte) error

func (*Uint32) GobEncode

func (i *Uint32) GobEncode() ([]byte, error)

func (*Uint32) Inc

func (i *Uint32) Inc() uint32

Inc atomically increments the wrapped uint32 and returns the new value.

func (*Uint32) Load

func (i *Uint32) Load() uint32

Load atomically loads the wrapped value.

func (*Uint32) MarshalBinary

func (i *Uint32) MarshalBinary() ([]byte, error)

func (*Uint32) MarshalJSON

func (i *Uint32) MarshalJSON() ([]byte, error)

func (*Uint32) MarshalText

func (i *Uint32) MarshalText() ([]byte, error)

func (*Uint32) Store

func (i *Uint32) Store(n uint32)

Store atomically stores the passed value.

func (*Uint32) Sub

func (i *Uint32) Sub(n uint32) uint32

Sub atomically subtracts from the wrapped uint32 and returns the new value.

func (*Uint32) Swap

func (i *Uint32) Swap(n uint32) uint32

Swap atomically swaps the wrapped uint32 and returns the old value.

func (*Uint32) UnmarshalBinary

func (i *Uint32) UnmarshalBinary(data []byte) error

func (*Uint32) UnmarshalJSON

func (i *Uint32) UnmarshalJSON(data []byte) error

func (*Uint32) UnmarshalText

func (i *Uint32) UnmarshalText(data []byte) error

type Uint64

type Uint64 struct {
	// contains filtered or unexported fields
}

Uint64 is an atomic wrapper around a uint64.

func NewUint64

func NewUint64(i uint64) *Uint64

NewUint64 creates a Uint64.

func (*Uint64) Add

func (i *Uint64) Add(n uint64) uint64

Add atomically adds to the wrapped uint64 and returns the new value.

func (*Uint64) CAS

func (i *Uint64) CAS(old, newz uint64) bool

CAS is an atomic compare-and-swap.

func (*Uint64) Dec

func (i *Uint64) Dec() uint64

Dec atomically decrements the wrapped uint64 and returns the new value.

func (*Uint64) GobDecode

func (i *Uint64) GobDecode(data []byte) error

func (*Uint64) GobEncode

func (i *Uint64) GobEncode() ([]byte, error)

func (*Uint64) Inc

func (i *Uint64) Inc() uint64

Inc atomically increments the wrapped uint64 and returns the new value.

func (*Uint64) Load

func (i *Uint64) Load() uint64

Load atomically loads the wrapped value.

func (*Uint64) MarshalBinary

func (i *Uint64) MarshalBinary() ([]byte, error)

func (*Uint64) MarshalJSON

func (i *Uint64) MarshalJSON() ([]byte, error)

func (*Uint64) MarshalText

func (i *Uint64) MarshalText() ([]byte, error)

func (*Uint64) Store

func (i *Uint64) Store(n uint64)

Store atomically stores the passed value.

func (*Uint64) Sub

func (i *Uint64) Sub(n uint64) uint64

Sub atomically subtracts from the wrapped uint64 and returns the new value.

func (*Uint64) Swap

func (i *Uint64) Swap(n uint64) uint64

Swap atomically swaps the wrapped uint64 and returns the old value.

func (*Uint64) UnmarshalBinary

func (i *Uint64) UnmarshalBinary(data []byte) error

func (*Uint64) UnmarshalJSON

func (i *Uint64) UnmarshalJSON(data []byte) error

func (*Uint64) UnmarshalText

func (i *Uint64) UnmarshalText(data []byte) error

Jump to

Keyboard shortcuts

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