当前位置: 首页>>代码示例>>Golang>>正文


Golang Flock_t.Type方法代码示例

本文整理汇总了Golang中syscall.Flock_t.Type方法的典型用法代码示例。如果您正苦于以下问题:Golang Flock_t.Type方法的具体用法?Golang Flock_t.Type怎么用?Golang Flock_t.Type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在syscall.Flock_t的用法示例。


在下文中一共展示了Flock_t.Type方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: flock

// flock acquires an advisory lock on a file descriptor.
func flock(f *os.File, exclusive bool, timeout time.Duration) error {
	var t time.Time
	for {
		// If we're beyond our timeout then return an error.
		// This can only occur after we've attempted a flock once.
		if t.IsZero() {
			t = time.Now()
		} else if timeout > 0 && time.Since(t) > timeout {
			return ErrTimeout
		}
		var lock syscall.Flock_t
		lock.Start = 0
		lock.Len = 0
		lock.Pid = 0
		lock.Whence = 0
		lock.Pid = 0
		if exclusive {
			lock.Type = syscall.F_WRLCK
		} else {
			lock.Type = syscall.F_RDLCK
		}
		err := syscall.FcntlFlock(f.Fd(), syscall.F_SETLK, &lock)
		if err == nil {
			return nil
		} else if err != syscall.EAGAIN {
			return err
		}

		// Wait for a bit and try again.
		time.Sleep(50 * time.Millisecond)
	}
}
开发者ID:cdupuis,项目名称:strava,代码行数:33,代码来源:bolt_unix_solaris.go

示例2: setFileLock

func setFileLock(f *os.File, readOnly, lock bool) error {
	flock := syscall.Flock_t{
		Type:   syscall.F_UNLCK,
		Start:  0,
		Len:    0,
		Whence: 1,
	}
	if lock {
		if readOnly {
			flock.Type = syscall.F_RDLCK
		} else {
			flock.Type = syscall.F_WRLCK
		}
	}
	return syscall.FcntlFlock(f.Fd(), syscall.F_SETLK, &flock)
}
开发者ID:RMeharg,项目名称:prometheus,代码行数:16,代码来源:file_storage_solaris.go

示例3: funlock

// funlock releases an advisory lock on a file descriptor.
func funlock(f *os.File) error {
	var lock syscall.Flock_t
	lock.Start = 0
	lock.Len = 0
	lock.Type = syscall.F_UNLCK
	lock.Whence = 0
	return syscall.FcntlFlock(uintptr(f.Fd()), syscall.F_SETLK, &lock)
}
开发者ID:cdupuis,项目名称:strava,代码行数:9,代码来源:bolt_unix_solaris.go

示例4: Unlock

// Unlock an open file. Unlocking errors are ignored.
func Unlock(file *os.File, lk *syscall.Flock_t) error {
	if lk == nil || file == nil {
		return fmt.Errorf("file or lock are nil file: %s lk: %v", file.Name(), lk)
	}

	lk.Type = syscall.F_UNLCK
	return syscall.FcntlFlock(file.Fd(), syscall.F_SETLK, lk)
}
开发者ID:HarryBird,项目名称:go-gnulib,代码行数:9,代码来源:safe_freebsd.go

示例5: Lock

// Lock acquires exclusivity on the lock without blocking
func (l *lock) Lock() error {
	var lock syscall.Flock_t
	lock.Start = 0
	lock.Len = 0
	lock.Type = syscall.F_WRLCK
	lock.Whence = 0
	lock.Pid = 0
	return syscall.FcntlFlock(uintptr(l.fd), syscall.F_SETLK, &lock)
}
开发者ID:CNDonny,项目名称:scope,代码行数:10,代码来源:lock_solaris.go

示例6: set

func (l *unixLock) set(lock bool) error {
	flock := syscall.Flock_t{
		Type:   syscall.F_UNLCK,
		Start:  0,
		Len:    0,
		Whence: 1,
	}
	if lock {
		flock.Type = syscall.F_WRLCK
	}
	return syscall.FcntlFlock(l.f.Fd(), syscall.F_SETLK, &flock)
}
开发者ID:hvnsweeting,项目名称:prometheus,代码行数:12,代码来源:flock_solaris.go

示例7: Unlock

// Unlock unlocks the lock
func (l *lock) Unlock() error {
	var lock syscall.Flock_t
	lock.Start = 0
	lock.Len = 0
	lock.Type = syscall.F_UNLCK
	lock.Whence = 0
	err := syscall.FcntlFlock(uintptr(l.fd), syscall.F_SETLK, &lock)
	if err != nil && err == syscall.EAGAIN {
		return ErrLocked
	}
	return err
}
开发者ID:CNDonny,项目名称:scope,代码行数:13,代码来源:lock_solaris.go

示例8: LockFile

func LockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) {
	var lock syscall.Flock_t
	lock.Start = 0
	lock.Len = 0
	lock.Pid = 0
	lock.Type = syscall.F_WRLCK
	lock.Whence = 0
	f, err := os.OpenFile(path, flag, perm)
	if err != nil {
		return nil, err
	}
	if err = syscall.FcntlFlock(f.Fd(), syscall.F_SETLKW, &lock); err != nil {
		f.Close()
		return nil, err
	}
	return &LockedFile{f}, nil
}
开发者ID:CliffYuan,项目名称:etcd,代码行数:17,代码来源:lock_solaris.go


注:本文中的syscall.Flock_t.Type方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。