atomic

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2022 License: Apache-2.0 Imports: 5 Imported by: 1

README

atomic

Provides simple wrappers for sync/atomic to enforce atomic access.

Install

go get github.com/go-spring/spring-base@v1.1.0-rc2 

Import

import "github.com/go-spring/spring-base/atomic"

Example

var i atomic.Int64
i.Add(1)
i.Store(2)
_ = i.Load()

Documentation

Overview

Package atomic provides simple wrappers for `sync/atomic` to enforce atomic access.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

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

A Bool is an atomic bool value.

func (*Bool) CompareAndSwap

func (x *Bool) CompareAndSwap(old, new bool) (swapped bool)

CompareAndSwap executes the compare-and-swap operation for x.

func (*Bool) Load

func (x *Bool) Load() (val bool)

Load atomically loads and returns the value stored in x.

func (*Bool) MarshalJSON added in v1.1.2

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

MarshalJSON returns the JSON encoding of x.

func (*Bool) Store

func (x *Bool) Store(val bool)

Store atomically stores val into x.

func (*Bool) Swap

func (x *Bool) Swap(new bool) (old bool)

Swap atomically stores new into x and returns the old value.

type Duration

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

A Duration is an atomic time.Duration value.

func (*Duration) Add

func (x *Duration) Add(delta time.Duration) time.Duration

Add atomically adds delta to x and returns the new value.

func (*Duration) CompareAndSwap

func (x *Duration) CompareAndSwap(old, new time.Duration) bool

CompareAndSwap executes the compare-and-swap operation for x.

func (*Duration) Load

func (x *Duration) Load() time.Duration

Load atomically loads and returns the value stored in x.

func (*Duration) MarshalJSON added in v1.1.2

func (x *Duration) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of x.

func (*Duration) Store

func (x *Duration) Store(val time.Duration)

Store atomically stores val into x.

func (*Duration) Swap

func (x *Duration) Swap(new time.Duration) time.Duration

Swap atomically stores new into x and returns the old value.

type Float32

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

A Float32 is an atomic float32 value.

func (*Float32) Add

func (x *Float32) Add(delta float32) (new float32)

Add atomically adds delta to x and returns the new value.

func (*Float32) CompareAndSwap

func (x *Float32) CompareAndSwap(old, new float32) (swapped bool)

CompareAndSwap executes the compare-and-swap operation for x.

func (*Float32) Load

func (x *Float32) Load() (val float32)

Load atomically loads and returns the value stored in x.

func (*Float32) MarshalJSON added in v1.1.2

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

MarshalJSON returns the JSON encoding of x.

func (*Float32) Store

func (x *Float32) Store(val float32)

Store atomically stores val into x.

func (*Float32) Swap

func (x *Float32) Swap(new float32) (old float32)

Swap atomically stores new into x and returns the old value.

type Float64

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

A Float64 is an atomic float64 value.

func (*Float64) Add

func (x *Float64) Add(delta float64) (new float64)

Add atomically adds delta to x and returns the new value.

func (*Float64) CompareAndSwap

func (x *Float64) CompareAndSwap(old, new float64) (swapped bool)

CompareAndSwap executes the compare-and-swap operation for x.

func (*Float64) Load

func (x *Float64) Load() (val float64)

Load atomically loads and returns the value stored in x.

func (*Float64) MarshalJSON added in v1.1.2

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

MarshalJSON returns the JSON encoding of x.

func (*Float64) Store

func (x *Float64) Store(val float64)

Store atomically stores val into x.

func (*Float64) Swap

func (x *Float64) Swap(new float64) (old float64)

Swap atomically stores new into x and returns the old value.

type Int32

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

An Int32 is an atomic int32 value.

func (*Int32) Add

func (x *Int32) Add(delta int32) (new int32)

Add atomically adds delta to x and returns the new value.

func (*Int32) CompareAndSwap

func (x *Int32) CompareAndSwap(old, new int32) (swapped bool)

CompareAndSwap executes the compare-and-swap operation for x.

func (*Int32) Load

func (x *Int32) Load() (val int32)

Load atomically loads and returns the value stored in x.

func (*Int32) MarshalJSON added in v1.1.2

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

MarshalJSON returns the JSON encoding of x.

func (*Int32) Store

func (x *Int32) Store(val int32)

Store atomically stores val into x.

func (*Int32) Swap

func (x *Int32) Swap(new int32) (old int32)

Swap atomically stores new into x and returns the old value.

type Int64

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

An Int64 is an atomic int64 value.

func (*Int64) Add

func (x *Int64) Add(delta int64) int64

Add atomically adds delta to x and returns the new value.

func (*Int64) CompareAndSwap

func (x *Int64) CompareAndSwap(old, new int64) bool

CompareAndSwap executes the compare-and-swap operation for x.

func (*Int64) Load

func (x *Int64) Load() int64

Load atomically loads and returns the value stored in x.

func (*Int64) MarshalJSON added in v1.1.2

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

MarshalJSON returns the JSON encoding of x.

func (*Int64) Store

func (x *Int64) Store(val int64)

Store atomically stores val into x.

func (*Int64) Swap

func (x *Int64) Swap(new int64) int64

Swap atomically stores new into x and returns the old value.

type MarshalPointer added in v1.1.3

type MarshalPointer func(unsafe.Pointer) ([]byte, error)

type MarshalTime added in v1.1.3

type MarshalTime func(time.Time) ([]byte, error)

type MarshalValue added in v1.1.3

type MarshalValue func(interface{}) ([]byte, error)

type Pointer added in v1.1.2

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

A Pointer is an atomic pointer value.

func (*Pointer) CompareAndSwap added in v1.1.2

func (p *Pointer) CompareAndSwap(old, new unsafe.Pointer) (swapped bool)

CompareAndSwap executes the compare-and-swap operation for x.

func (*Pointer) Load added in v1.1.2

func (p *Pointer) Load() (val unsafe.Pointer)

Load atomically loads and returns the value stored in x.

func (*Pointer) MarshalJSON added in v1.1.3

func (p *Pointer) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of x.

func (*Pointer) SetMarshalJSON added in v1.1.3

func (p *Pointer) SetMarshalJSON(fn MarshalPointer)

SetMarshalJSON sets the JSON encoding handler for x.

func (*Pointer) Store added in v1.1.2

func (p *Pointer) Store(val unsafe.Pointer)

Store atomically stores val into x.

func (*Pointer) Swap added in v1.1.2

func (p *Pointer) Swap(new unsafe.Pointer) (old unsafe.Pointer)

Swap atomically stores new into x and returns the old value.

type String added in v1.1.2

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

A String is an atomic string value.

func (*String) Load added in v1.1.2

func (x *String) Load() string

Load atomically loads and returns the value stored in x.

func (*String) MarshalJSON added in v1.1.2

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

MarshalJSON returns the JSON encoding of x.

func (*String) Store added in v1.1.2

func (x *String) Store(val string)

Store atomically stores val into x.

type Time

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

A Time is an atomic time.Time value.

func (*Time) Load

func (x *Time) Load() time.Time

Load atomically loads and returns the value stored in x.

func (*Time) MarshalJSON added in v1.1.2

func (x *Time) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of x.

func (*Time) SetMarshalJSON added in v1.1.3

func (x *Time) SetMarshalJSON(fn MarshalTime)

SetMarshalJSON sets the JSON encoding handler for x.

func (*Time) Store

func (x *Time) Store(val time.Time)

Store atomically stores val into x.

type Uint32

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

An Uint32 is an atomic uint32 value.

func (*Uint32) Add

func (x *Uint32) Add(delta uint32) (new uint32)

Add atomically adds delta to x and returns the new value.

func (*Uint32) CompareAndSwap

func (x *Uint32) CompareAndSwap(old, new uint32) (swapped bool)

CompareAndSwap executes the compare-and-swap operation for x.

func (*Uint32) Load

func (x *Uint32) Load() (val uint32)

Load atomically loads and returns the value stored in x.

func (*Uint32) MarshalJSON added in v1.1.2

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

MarshalJSON returns the JSON encoding of x.

func (*Uint32) Store

func (x *Uint32) Store(val uint32)

Store atomically stores val into x.

func (*Uint32) Swap

func (x *Uint32) Swap(new uint32) (old uint32)

Swap atomically stores new into x and returns the old value.

type Uint64

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

An Uint64 is an atomic uint64 value.

func (*Uint64) Add

func (x *Uint64) Add(delta uint64) (new uint64)

Add atomically adds delta to x and returns the new value.

func (*Uint64) CompareAndSwap

func (x *Uint64) CompareAndSwap(old, new uint64) (swapped bool)

CompareAndSwap executes the compare-and-swap operation for x.

func (*Uint64) Load

func (x *Uint64) Load() (val uint64)

Load atomically loads and returns the value stored in x.

func (*Uint64) MarshalJSON added in v1.1.2

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

MarshalJSON returns the JSON encoding of x.

func (*Uint64) Store

func (x *Uint64) Store(val uint64)

Store atomically stores val into x.

func (*Uint64) Swap

func (x *Uint64) Swap(new uint64) (old uint64)

Swap atomically stores new into x and returns the old value.

type Uintptr

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

An Uintptr is an atomic uintptr value.

func (*Uintptr) Add

func (x *Uintptr) Add(delta uintptr) (new uintptr)

Add atomically adds delta to x and returns the new value.

func (*Uintptr) CompareAndSwap

func (x *Uintptr) CompareAndSwap(old, new uintptr) (swapped bool)

CompareAndSwap executes the compare-and-swap operation for x.

func (*Uintptr) Load

func (x *Uintptr) Load() (val uintptr)

Load atomically loads and returns the value stored in x.

func (*Uintptr) Store

func (x *Uintptr) Store(val uintptr)

Store atomically stores val into x.

func (*Uintptr) Swap

func (x *Uintptr) Swap(new uintptr) (old uintptr)

Swap atomically stores new into x and returns the old value.

type Value

type Value struct {
	atomic.Value
	// contains filtered or unexported fields
}

A Value provides an atomic load and store of a consistently typed value.

func (*Value) MarshalJSON added in v1.1.3

func (x *Value) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of x.

func (*Value) SetMarshalJSON added in v1.1.3

func (x *Value) SetMarshalJSON(fn MarshalValue)

SetMarshalJSON sets the JSON encoding handler for x.

Jump to

Keyboard shortcuts

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