lock

package
v0.0.0-...-f382dc8 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2022 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package lock wraps the sync.Mutex and sync.RWMutex to log messages on deadlocks.

Index

Constants

View Source
const (
	OpMutexLock    = "Mutex.Lock"
	OpRWMutexLock  = "RWMutex.Lock"
	OpRWMutexRLock = "RWMutex.RLock"
)

Constants of operations.

Variables

View Source
var DefaultLogFunc = func(m MutexWrapper, op string) {
	l.Errorf(
		"Timeout! Wait %dms to acquire lock %s, blocked operation is %s, callers stack:\n%s",
		int(m.Timeout().Nanoseconds()/1000000),
		m.Name(), op, debug.Stack(),
	)
}

DefaultLogFunc Default log function

Functions

func LogFunc

func LogFunc(fn func(m MutexWrapper, op string))

Register a global error logger.

Types

type Mutex

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

Mutex is the wrapper around sync.Mutex.

func NewMutex

func NewMutex(name string, timeout time.Duration) *Mutex

NewMutex constructs a new mutex.

func (*Mutex) Lock

func (m *Mutex) Lock()

Lock wraps sync.Mutex.Lock().

func (*Mutex) Name

func (m *Mutex) Name() string

Name implements MutexWrapper.Name().

func (*Mutex) Timeout

func (m *Mutex) Timeout() time.Duration

Timeout implements Mutex.Wrapper.Timeout().

func (*Mutex) Unlock

func (m *Mutex) Unlock()

Unlock wraps sync.Mutex.Unlock().

type MutexWrapper

type MutexWrapper interface {
	// Name returns the name of this mutex wrapper.
	Name() string
	// Timeout returns the timeout value of this mutex wrapper.
	Timeout() time.Duration
}

MutexWrapper is an interface implemented by Mutex and RWMutex.

type RWMutex

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

RWMutex is the wrapper around sync.RWMutex

func NewRWMutex

func NewRWMutex(name string, timeout time.Duration) *RWMutex

NewRWMutex constructs a new rwmutex.

func (*RWMutex) Lock

func (m *RWMutex) Lock()

Lock wraps sync.RWMutex.Lock().

func (*RWMutex) Name

func (m *RWMutex) Name() string

Name implements MutexWrapper.Name().

func (*RWMutex) RLock

func (m *RWMutex) RLock()

RLock wraps sync.RWMutex.RLock().

func (*RWMutex) RUnlock

func (m *RWMutex) RUnlock()

RUnlock wraps sync.RWMutex.RUnlock().

func (*RWMutex) Timeout

func (m *RWMutex) Timeout() time.Duration

Timeout implements Mutex.Wrapper.Timeout().

func (*RWMutex) Unlock

func (m *RWMutex) Unlock()

Unlock wraps sync.RWMutex.Unlock().

Jump to

Keyboard shortcuts

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