styx: aqwari.net/net/styx/internal/threadsafe Index | Files

package threadsafe

import "aqwari.net/net/styx/internal/threadsafe"

Package threadsafe implements data structures that are safe for use from multiple goroutines.

Index

Package Files

map.go

type Map Uses

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

A Map is a map that is safe for concurrent access and updates. A Map must be created with NewMap.

func NewMap Uses

func NewMap() *Map

func (*Map) Add Uses

func (m *Map) Add(key, val interface{}) bool

Add stores a value in the map under key. If there is already a value in the map for key, Add does not replace it, and returns false.

func (*Map) Del Uses

func (m *Map) Del(key interface{})

Del deletes a value from a map. Subsequent Gets on the map will turn up empty.

func (*Map) Do Uses

func (m *Map) Do(f func(map[interface{}]interface{}))

Do calls f while holding the write lock for a Map.

func (*Map) Fetch Uses

func (m *Map) Fetch(key, v interface{}) bool

Fetch stores the value corresponding with key in the Map into v. v must be a pointer to the value's type, or a run-time panic will occur. If the key is not present in the Map, v is untouched and Fetch returns false.

func (*Map) Get Uses

func (m *Map) Get(key interface{}) (val interface{}, ok bool)

Get retrieves a value from the Map. If the value is not present, ok will be false.

func (*Map) Put Uses

func (m *Map) Put(key, val interface{})

Put stores a value in the map, overwriting any previous values stored under the key.

func (*Map) Update Uses

func (m *Map) Update(key, v interface{}, fn func()) bool

Update stores the Map value corresponding with key into v, and then calls fn. Once fn is returned, v is copied back into the Map under key. All other access to the Map is blocked until Update returns. If there is no value in the Map associated with key, fn is not called and Update returns false.

v must be a pointer to the same type as the item retrieved from the Map, or a run-time panic will occur.

Package threadsafe imports 2 packages (graph) and is imported by 4 packages. Updated 2018-06-12. Refresh now. Tools for package owners.