gf: github.com/gogf/gf/g/os/gflock Index | Files

package gflock

import "github.com/gogf/gf/g/os/gflock"

Package gflock implements a concurrent-safe sync.Locker interface for file locking.

Index

Package Files

gflock.go

type Locker Uses

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

File locker.

func New Uses

func New(file string) *Locker

New creates and returns a new file locker with given <file>. The parameter <file> usually is a absolute file path.

func (*Locker) IsLocked Uses

func (l *Locker) IsLocked() bool

IsLocked returns whether the locker is locked.

func (*Locker) IsRLocked Uses

func (l *Locker) IsRLocked() bool

IsRLocked returns whether the locker is rlocked.

func (*Locker) Lock Uses

func (l *Locker) Lock() (err error)

Lock is a blocking call to try and take an exclusive file lock. It will wait until it is able to obtain the exclusive file lock. It's recommended that TryLock() be used over this function. This function may block the ability to query the current Locked() or RLocked() status due to a RW-mutex lock.

If we are already exclusive-locked, this function short-circuits and returns immediately assuming it can take the mutex lock.

If the *Flock has a shared lock (RLock), this may transparently replace the shared lock with an exclusive lock on some UNIX-like operating systems. Be careful when using exclusive locks in conjunction with shared locks (RLock()), because calling Unlock() may accidentally release the exclusive lock that was once a shared lock.

func (*Locker) Path Uses

func (l *Locker) Path() string

Path returns the file path of the locker.

func (*Locker) RLock Uses

func (l *Locker) RLock() (err error)

RLock is a blocking call to try and take a ahred file lock. It will wait until it is able to obtain the shared file lock. It's recommended that TryRLock() be used over this function. This function may block the ability to query the current Locked() or RLocked() status due to a RW-mutex lock.

If we are already shared-locked, this function short-circuits and returns immediately assuming it can take the mutex lock.

func (*Locker) RUnlock Uses

func (l *Locker) RUnlock() (err error)

Unlock is a function to unlock the file. This file takes a RW-mutex lock, so while it is running the Locked() and RLocked() functions will be blocked.

This function short-circuits if we are unlocked already. If not, it calls syscall.LOCK_UN on the file and closes the file descriptor. It does not remove the file from disk. It's up to your application to do.

Please note, if your shared lock became an exclusive lock this may unintentionally drop the exclusive lock if called by the consumer that believes they have a shared lock. Please see Lock() for more details.

func (*Locker) TryLock Uses

func (l *Locker) TryLock() bool

TryLock tries get the writing lock of the locker. It returns true if success, or else returns false immediately.

func (*Locker) TryRLock Uses

func (l *Locker) TryRLock() bool

TryRLock tries get the reading lock of the locker. It returns true if success, or else returns false immediately.

func (*Locker) Unlock Uses

func (l *Locker) Unlock() (err error)

Unlock is a function to unlock the file. This file takes a RW-mutex lock, so while it is running the Locked() and RLocked() functions will be blocked.

This function short-circuits if we are unlocked already. If not, it calls syscall.LOCK_UN on the file and closes the file descriptor. It does not remove the file from disk. It's up to your application to do.

Please note, if your shared lock became an exclusive lock this may unintentionally drop the exclusive lock if called by the consumer that believes they have a shared lock. Please see Lock() for more details.

Package gflock imports 2 packages (graph). Updated 2019-06-25. Refresh now. Tools for package owners.