sync

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2016 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package sync implements primitives for syncronization between processes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DestroyEventMutex

func DestroyEventMutex(name string) error

DestroyEventMutex is a no-op on windows, as the mutex is destroyed, when its last handle is closed.

func DestroyMutex

func DestroyMutex(name string) error

DestroyMutex permanently removes mutex with the given name.

func DestroySpinMutex

func DestroySpinMutex(name string) error

DestroySpinMutex removes a mutex object with the given name

Types

type EventMutex

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

EventMutex is a mutex built on named windows events. It is not possible to use native windows named mutex, because goroutines migrate between threads, and windows mutex must be released by the same thread it was locked.

func NewEventMutex

func NewEventMutex(name string, flag int, perm os.FileMode) (*EventMutex, error)

NewEventMutex creates a new event-basedmutex.

name - object name.
flag - flag is a combination of open flags from 'os' package
perm - object's permission bits.

func (*EventMutex) Close

func (m *EventMutex) Close() error

Close closes event's handle.

func (*EventMutex) Lock

func (m *EventMutex) Lock()

Lock locks the mutex. It panics on an error.

func (*EventMutex) LockTimeout

func (m *EventMutex) LockTimeout(timeout time.Duration) bool

LockTimeout tries to lock the locker, waiting for not more, than timeout.

func (*EventMutex) Unlock

func (m *EventMutex) Unlock()

Unlock releases the mutex. It panics on an error.

type IPCLocker

type IPCLocker interface {
	sync.Locker
	io.Closer
}

IPCLocker is a minimal interface, which must be satisfied by any synchronization primitive on any platform.

func NewMutex

func NewMutex(name string, flag int, perm os.FileMode) (IPCLocker, error)

NewMutex creates a new interprocess mutex. It uses the default implementation on the current platform.

name - object name.
flag - flag is a combination of open flags from 'os' package.
perm - object's permission bits.

type SpinMutex

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

SpinMutex is a synchronization object which performs busy wait loop.

func NewSpinMutex

func NewSpinMutex(name string, flag int, perm os.FileMode) (*SpinMutex, error)

NewSpinMutex creates a new spin mutex.

name - object name.
flag - flag is a combination of open flags from 'os' package.
perm - object's permission bits.

func (*SpinMutex) Close

func (spin *SpinMutex) Close() error

Close indicates, that the object is no longer in use, and that the underlying resources can be freed.

func (*SpinMutex) Destroy

func (spin *SpinMutex) Destroy() error

Destroy removes the mutex object.

func (SpinMutex) Lock

func (spin SpinMutex) Lock()

Lock locks the mutex waiting in a busy loop if needed.

func (SpinMutex) TryLock

func (spin SpinMutex) TryLock() bool

TryLock makes one attempt to lock the mutex. It return true on succeess and false otherwise.

func (SpinMutex) Unlock

func (spin SpinMutex) Unlock()

Unlock releases the mutex.

type TimedIPCLocker

type TimedIPCLocker interface {
	IPCLocker
	// LockTimeout tries to lock the locker, waiting for not more, than timeout
	LockTimeout(timeout time.Duration) bool
}

TimedIPCLocker is a locker, whose lock operation can be limited with duration.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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