utils

package
v0.0.0-...-3a65784 Latest Latest
Warning

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

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

Documentation

Overview

https://github.com/platinummonkey/priority-lock

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BinaryReverse

func BinaryReverse(x int, maxBits int) int

func ConvertInt32SliceToIntSlice

func ConvertInt32SliceToIntSlice(int32Slice []int32) []int

func ConvertIntSliceToInt32Slice

func ConvertIntSliceToInt32Slice(intSlice []int) []int32

func InitLogging

func InitLogging(isLogEnabled bool, logPath string)

Types

type Hasher

type Hasher struct {
	KnownHashes map[string]uint32
	// contains filtered or unexported fields
}

Hahsher is thread-safe. If you see contention on the mutex, you may want to consider a sync.Map. Since we only write to the map once per key, and read from it many times, it might make sense.

func (*Hasher) Hash

func (h *Hasher) Hash(s string) uint32

It calculates hash of a string. If the hash is already known it uses KnownHashes.

type PriorityLock

type PriorityLock interface {
	Lock()
	Unlock()
	HighPriorityLock()
	HighPriorityUnlock()
}

type PriorityPreferenceLock

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

PriorityPreferenceLock implements a simple triple-mutex priority lock patterns are like:

Low Priority would do: lock lowPriorityMutex, wait for high priority groups, lock nextToAccess, lock dataMutex, unlock nextToAccess, do stuff, unlock dataMutex, unlock lowPriorityMutex
High Priority would do: increment high priority waiting, lock nextToAccess, lock dataMutex, unlock nextToAccess, do stuff, unlock dataMutex, decrement high priority waiting

func NewPriorityPreferenceLock

func NewPriorityPreferenceLock() *PriorityPreferenceLock

func (*PriorityPreferenceLock) HighPriorityLock

func (lock *PriorityPreferenceLock) HighPriorityLock()

HighPriorityLock will acquire a high-priority lock it must still wait until a low-priority lock has been released and then potentially other high priority lock contenders.

func (*PriorityPreferenceLock) HighPriorityUnlock

func (lock *PriorityPreferenceLock) HighPriorityUnlock()

HighPriorityUnlock will unlock the high-priority lock

func (*PriorityPreferenceLock) Lock

func (lock *PriorityPreferenceLock) Lock()

Lock will acquire a low-priority lock it must wait until both low priority and all high priority lock holders are released.

func (*PriorityPreferenceLock) Unlock

func (lock *PriorityPreferenceLock) Unlock()

Unlock will unlock the low-priority lock

Jump to

Keyboard shortcuts

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