tests

package
v0.0.0-...-44c758a Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Code generated by generate_randomized_freepool.py. DO NOT EDIT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToint32s

func BytesToint32s(src []byte) (d []int32)

BytesToint32s casts []byte to []int32 without reallocating.

Types

type IntsFreePool

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

IntsFreePool is a variation of sync.Pool, specialized for a concrete type.

  • Put() performs power-of-two loadbalancing, and Get() looks only at the local queue. This improves the performance of Get() on many-core machines, at the cost of slightly more allocations.

- It assumes that GOMAXPROCS is fixed at boot.

  • It never frees objects accumulated in the pool. We could add this feature if needed.

func NewIntsFreePool

func NewIntsFreePool(new func() []int, maxSize int) *IntsFreePool

NewIntsFreePool creates a new free object pool. new should create a new object. It is called when the pool is empty on Get(). maxSize bounds the approx max number of objects that can be stored in the pool. Beyond this limit, Put() call will drop the objects.

func (*IntsFreePool) ApproxLen

func (p *IntsFreePool) ApproxLen() int

ApproxLen returns an approximate length of the pool. For unittesting only.

It returns an accurate value iff. no other thread is accessing the pool.

func (*IntsFreePool) Get

func (p *IntsFreePool) Get() []int

Get removes an object from the freepool. If pool is empty, it calls the callback passed to NewFreePool.

func (*IntsFreePool) Put

func (p *IntsFreePool) Put(x []int)

Put adds an object to the freepool. The caller shall not touch the object after the call.

type RCUTestMap

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

RCUTestMap is a concurrent map. A reader can access the map without lock, regardless of background updates. The writer side must coordinate using an external mutex if there are multiple writers. This map is linearizable.

Example:

m := NewRCUTestMap(10)
go func() {  // writer
  m.Store("foo", "bar")
}()
go func() {  // reader
  val, ok := m.Load("foo")
}

func NewRCUTestMap

func NewRCUTestMap(initialLenHint int) *RCUTestMap

NewRCUTestMap creates a new map. Arg initialLenHint suggests the the initial capacity. If you plan to store 100 keys, then pass 100 as the value. If you don't know the capacity, pass 0 as initialLenHint.

func (*RCUTestMap) Load

func (m *RCUTestMap) Load(key string) (uint64, bool)

Load finds a value with the given key. Returns false if not found.

func (*RCUTestMap) Store

func (m *RCUTestMap) Store(key string, value uint64)

Store stores the value for the given key. If the key is already in the map, it updates the mapping to the given value.

Caution: if Store() is going to be called concurrently, it must be serialized externally.

type StringsFreePool

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

StringsFreePool is a variation of sync.Pool, specialized for a concrete type.

  • Put() performs power-of-two loadbalancing, and Get() looks only at the local queue. This improves the performance of Get() on many-core machines, at the cost of slightly more allocations.

- It assumes that GOMAXPROCS is fixed at boot.

  • It never frees objects accumulated in the pool. We could add this feature if needed.

func NewStringsFreePool

func NewStringsFreePool(new func() []string, maxSize int) *StringsFreePool

NewStringsFreePool creates a new free object pool. new should create a new object. It is called when the pool is empty on Get(). maxSize bounds the approx max number of objects that can be stored in the pool. Beyond this limit, Put() call will drop the objects.

func (*StringsFreePool) ApproxLen

func (p *StringsFreePool) ApproxLen() int

ApproxLen returns an approximate length of the pool. For unittesting only.

It returns an accurate value iff. no other thread is accessing the pool.

func (*StringsFreePool) Get

func (p *StringsFreePool) Get() []string

Get removes an object from the freepool. If pool is empty, it calls the callback passed to NewFreePool.

func (*StringsFreePool) Put

func (p *StringsFreePool) Put(x []string)

Put adds an object to the freepool. The caller shall not touch the object after the call.

Jump to

Keyboard shortcuts

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