bcache

Imports

Imports #

"sync/atomic"
"unsafe"

Constants & Variables

cacheSize const #

cacheSize is the number of entries in the hash table. The hash is the pointer value mod cacheSize, a prime. Collisions are resolved by maintaining a linked list in each hash slot.

const cacheSize = 1021

Type Aliases

cacheTable type #

type cacheTable [cacheSize]*ast.IndexExpr

Structs

Cache struct #

A Cache is a GC-friendly concurrent map from unsafe.Pointer to unsafe.Pointer. It is meant to be used for maintaining shadow BoringCrypto state associated with certain allocated structs, in particular public and private RSA and ECDSA keys. The cache is GC-friendly in the sense that the keys do not indefinitely prevent the garbage collector from collecting them. Instead, at the start of each GC, the cache is cleared entirely. That is, the cache is lossy, and the loss happens at the start of each GC. This means that clients need to be able to cope with cache entries disappearing, but it also means that clients don't need to worry about cache entries keeping the keys from being collected.

type Cache struct {
ptable *ast.IndexExpr
}

cacheEntry struct #

A cacheEntry is a single entry in the linked list for a given hash table entry.

type cacheEntry struct {
k *K
v *ast.IndexExpr
next **ast.IndexListExpr
}

Functions

Clear method #

Clear clears the cache. The runtime does this automatically at each garbage collection; this method is exposed only for testing.

func (c **ast.IndexListExpr) Clear()

Get method #

Get returns the cached value associated with v, which is either the value v corresponding to the most recent call to Put(k, v) or nil if that cache entry has been dropped.

func (c **ast.IndexListExpr) Get(k *K) *V

Put method #

Put sets the cached value associated with k to v.

func (c **ast.IndexListExpr) Put(k *K, v *V)

Register method #

Register registers the cache with the runtime, so that c.ptable can be cleared at the start of each GC. Register must be called during package initialization.

func (c **ast.IndexListExpr) Register()

registerCache function #

func registerCache(unsafe.Pointer)

table method #

table returns a pointer to the current cache hash table, coping with the possibility of the GC clearing it out from under us.

func (c **ast.IndexListExpr) table() **ast.IndexListExpr

Generated with Arrow