atomicx

package
v3.15.1 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2022 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package atomicx extends sync/atomic.

Sync/atomic fails when using int64 atomic operations on 32 bit platforms when the access is not aligned. As specified in the documentation, in fact, "it is the caller's responsibility to arrange for 64-bit alignment of 64-bit words accessed atomically". For more information on this issue, see https://golang.org/pkg/sync/atomic/#pkg-note-BUG.

As explained in CONTRIBUTING.md, probe-cli SHOULD use this package rather than sync/atomic to avoid these alignment issues on 32 bit.

It is of course possible to write atomic code using 64 bit variables on a 32 bit platform, but that's difficult to do correctly. This package provides an easier-to-use interface. We use allocated structures protected by a mutex that encapsulate a int64 value.

Example (TypicalUsage)
package main

import (
	"fmt"

	"github.com/ooni/probe-cli/v3/internal/atomicx"
)

func main() {
	v := &atomicx.Int64{}
	v.Add(1)
	fmt.Printf("%d\n", v.Load())
}
Output:

1

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Int64

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

Int64 is an int64 with atomic semantics.

func (*Int64) Add

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

Add behaves like atomic.AddInt64.

func (*Int64) Load

func (i64 *Int64) Load() (v int64)

Load behaves like atomic.LoadInt64.

Jump to

Keyboard shortcuts

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