mutex

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsEmpty

func IsEmpty() bool

func Lock

func Lock(s string)

Lock locks a mutex in the mutexMap. If the mutex is already in the map, it locks the current call. After it another call unlocks the mutex (and deletes it from the mutexMap) the mutex written again into the mutexMap. If the mutex was not in the mutexMap before, a new mutext is created and locked and written into the mutexMap.

func LockWithContext

func LockWithContext(ctx context.Context, s string)

LockWithContext locks a mutex only if it hasn't been locked before in a context. LockWithContext should be used to lock objects like faucets etc. The context carries a uid that is unique the each request (message, button press, etc.). If the uid has a lock already *for a certain object*, it increments the nLocks in the mutexMap. If not, it locks the object. This is supposed to lock only if nLock == 0.

func ServeHTTP

func ServeHTTP(w http.ResponseWriter, r *http.Request)

func Unlock

func Unlock(s string)

Unlock unlocks a mutex in the mutexMap.

func UnlockHTTP

func UnlockHTTP(w http.ResponseWriter, r *http.Request)

func UnlockWithContext

func UnlockWithContext(ctx context.Context, s string)

UnlockWithContext unlock a mutex only if it has been locked once within a context. If it has been locked more than once it only decrements nLocks and skips the unlock of the mutex. This is supposed to unlock only for nLocks == 1

Types

This section is empty.

Jump to

Keyboard shortcuts

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