Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Clone

Read only, no credentials:

https://rodent.software/git/vole.git

Write over SSH with a registered key:

git clone ssh://git@0.0.0.0:2222/vole.git

A free and open-source forge that lives in your Git repo.

Blame · ci/cache/lock_unix.go

Line attribution on main · 37 line(s)

a29ce1f7
Keenan Nemetz
2d ago
1 //go:build unix
2
3 package cache
4
5 import (
6 "os"
7 "syscall"
8 )
9
10 // lockFile takes the lock f names. A shared lock is what a job holds while it has
11 // the namespace mounted; exclusive is what eviction takes. wait=false asks rather
12 // than waits: the caller has other namespaces it can try.
13 //
14 // A signal can interrupt the wait and the lock is not held when it does, so the
15 // call asks again rather than reporting a failure the caller cannot act on.
16 func lockFile(f *os.File, exclusive, wait bool) (func(), bool, error) {
17 how := syscall.LOCK_SH
18 if exclusive {
19 how = syscall.LOCK_EX
20 }
21 if !wait {
22 how |= syscall.LOCK_NB
23 }
24 for {
25 err := syscall.Flock(int(f.Fd()), how)
26 switch err {
27 case nil:
28 return func() { _ = syscall.Flock(int(f.Fd()), syscall.LOCK_UN) }, true, nil
29 case syscall.EINTR:
30 continue
31 case syscall.EWOULDBLOCK:
32 return nil, false, nil
33 default:
34 return nil, false, err
35 }
36 }
37 }