refutils

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2023 License: MIT Imports: 3 Imported by: 1

README

RefUtils Go Library

Collection of utility interfaces for use with referencing of objects. Used heavily in go-v8.

Documentation

Documentation is available on Godoc.

Usage

import (
  refutils "github.com/grexie/refutils"
)

RefMutex

Offers a mutual exclusion lock with two sync.Locker interfaces. The master lock takes a global lock on the RefMutex, whereas RefLocker (and corresponding RefLock and RefUnlock methods) allow for multiple locks even when the global lock has been requested. This differs from sync.RWLock in that once a ref-lock has been obtained, further ref-locks are guaranteed until all ref-locks have been released. Consequently, once a ref-lock has been obtained, no master-locks can be obtained until all ref-locks have been released. Finally, only one master-lock may exist at any one time. If a master-lock is obtained then ref-locks will block until the master-lock is released.

RefMap

Provides a thread-safe strong and weak reference map for objects implementing Ref (GetID and SetID for uint32 IDs). The RefObject struct can be inherited by your structs to implement the required maps and mechanisms for RefMap to work. RefObject implemented the Ref interface.

RefMap will set a monotonically increasing identifier in the Ref that it is provided by Ref and Unref. Once an object is referenced using Ref, it will remain referenced within the map until it is dereferenced using Unref.

Documentation

Overview

Package refutils provides a collection of utility interfaces for use with referencing of objects. Used throughout https://github.com/behrsin/go-v8 for reference tracking and reference-based mutex locking.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ID

type ID uint64

type Ref

type Ref interface {
	// contains filtered or unexported methods
}

type RefHolder

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

type RefMap

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

RefMap provides a thread-safe strong and weak reference map for objects implementing Ref (GetID and SetID for uint64 IDs). The RefObject struct can be inherited by your structs to implement the required maps and mechanisms for RefMap to work. RefObject implemented the Ref interface.

RefMap will set a monotonically increasing identifier in the Ref that it is provided by Ref and Unref. Once an object is referenced using Ref, it will remain referenced within the map until it is dereferenced using Unref.

func NewRefMap

func NewRefMap(name string) *RefMap

func NewWeakRefMap

func NewWeakRefMap(name string) *RefMap

func (*RefMap) Get

func (rm *RefMap) Get(id ID) Ref

func (*RefMap) GetID

func (rm *RefMap) GetID(r Ref) ID

func (*RefMap) Length

func (rm *RefMap) Length() int

func (*RefMap) Ref

func (rm *RefMap) Ref(r Ref) ID

func (*RefMap) Refs

func (rm *RefMap) Refs() map[ID]Ref

func (*RefMap) Release

func (rm *RefMap) Release(r Ref)

func (*RefMap) ReleaseAll

func (rm *RefMap) ReleaseAll()

func (*RefMap) Unref

func (rm *RefMap) Unref(r Ref)

type RefMutex

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

RefMutex provides a mutual exclusion lock with two sync.Locker interfaces. The master lock takes a global lock on the RefMutex, whereas RefLocker (and corresponding RefLock and RefUnlock methods) allow for multiple locks even when the global lock has been requested.

This differs from sync.RWLock in that once a ref-lock has been obtained, further ref-locks are guaranteed until all ref-locks have been released. Consequently, once a ref-lock has been obtained, no master-locks can be obtained until all ref-locks have been released. Finally, only one master-lock may exist at any one time. If a master-lock is obtained then ref-locks will block until the master-lock is released.

func (*RefMutex) Lock

func (rm *RefMutex) Lock()

func (*RefMutex) RefLock

func (rm *RefMutex) RefLock()

func (*RefMutex) RefLocker

func (rm *RefMutex) RefLocker() sync.Locker

func (*RefMutex) RefUnlock

func (rm *RefMutex) RefUnlock()

func (*RefMutex) Unlock

func (rm *RefMutex) Unlock()

Jump to

Keyboard shortcuts

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