Skip to content

Commit

Permalink
lockfile: merge Seek+Read/Write into Pread/Pwrite
Browse files Browse the repository at this point in the history
drop a call to Seek and use the Pread and Pwrite syscalls instead that
already accept an offset.

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Jun 9, 2021
1 parent 39e7061 commit 10afc92
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions pkg/lockfile/lockfile_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,7 @@ func (l *lockfile) Touch() error {
defer l.stateMutex.Unlock()
l.lw = stringid.GenerateRandomID()
id := []byte(l.lw)
_, err := unix.Seek(int(l.fd), 0, os.SEEK_SET)
if err != nil {
return err
}
n, err := unix.Write(int(l.fd), id)
n, err := unix.Pwrite(int(l.fd), id, 0)
if err != nil {
return err
}
Expand All @@ -217,11 +213,7 @@ func (l *lockfile) Modified() (bool, error) {
panic("attempted to check last-writer in lockfile without locking it first")
}
defer l.stateMutex.Unlock()
_, err := unix.Seek(int(l.fd), 0, os.SEEK_SET)
if err != nil {
return true, err
}
n, err := unix.Read(int(l.fd), id)
n, err := unix.Pread(int(l.fd), id, 0)
if err != nil {
return true, err
}
Expand Down

0 comments on commit 10afc92

Please sign in to comment.