Skip to content

Commit d78239b

Browse files
committed
More EINTR.
1 parent 4985273 commit d78239b

File tree

6 files changed

+48
-24
lines changed

6 files changed

+48
-24
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ This module behaves similarly to SQLite in [multi-thread](https://sqlite.org/thr
9999
it is goroutine-safe, provided that no single database connection, or object derived from it,
100100
is used concurrently by multiple goroutines.
101101

102-
The [`database/sql`](https://pkg.go.dev/database/sql) driver is safe to use concurrently,
102+
The [`database/sql`](https://pkg.go.dev/database/sql) API is safe to use concurrently,
103103
according to its documentation.
104104

105105
### FAQ, issues, new features

func.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (c *Conn) CreateAggregateFunction(name string, nArg int, flag FunctionFlag,
114114
}
115115

116116
// AggregateSeqFunction is the type of an aggregate SQL function.
117-
// Implementations must not retain the slices produced by seq.
117+
// Implementations must not retain the slices yielded by seq.
118118
type AggregateSeqFunction func(ctx *Context, seq iter.Seq[[]Value])
119119

120120
// CreateWindowFunction defines a new aggregate or aggregate window SQL function.

vfs/os_bsd.go

+18-9
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,15 @@ func osDowngradeLock(file *os.File, _ LockLevel) _ErrorCode {
5050
}
5151

5252
func osReleaseLock(file *os.File, _ LockLevel) _ErrorCode {
53-
err := unix.Flock(int(file.Fd()), unix.LOCK_UN)
54-
if err != nil {
55-
return _IOERR_UNLOCK
53+
for {
54+
err := unix.Flock(int(file.Fd()), unix.LOCK_UN)
55+
if err == nil {
56+
return _OK
57+
}
58+
if err != unix.EINTR {
59+
return _IOERR_UNLOCK
60+
}
5661
}
57-
return _OK
5862
}
5963

6064
func osCheckReservedLock(file *os.File) (bool, _ErrorCode) {
@@ -89,13 +93,18 @@ func osLock(file *os.File, typ int16, start, len int64, def _ErrorCode) _ErrorCo
8993
}
9094

9195
func osUnlock(file *os.File, start, len int64) _ErrorCode {
92-
err := unix.FcntlFlock(file.Fd(), unix.F_SETLK, &unix.Flock_t{
96+
lock := unix.Flock_t{
9397
Type: unix.F_UNLCK,
9498
Start: start,
9599
Len: len,
96-
})
97-
if err != nil {
98-
return _IOERR_UNLOCK
99100
}
100-
return _OK
101+
for {
102+
err := unix.FcntlFlock(file.Fd(), unix.F_SETLK, &lock)
103+
if err == nil {
104+
return _OK
105+
}
106+
if err != unix.EINTR {
107+
return _IOERR_UNLOCK
108+
}
109+
}
101110
}

vfs/os_darwin.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,18 @@ func osLock(file *os.File, typ int16, start, len int64, timeout time.Duration, d
9090
}
9191

9292
func osUnlock(file *os.File, start, len int64) _ErrorCode {
93-
err := unix.FcntlFlock(file.Fd(), _F_OFD_SETLK, &unix.Flock_t{
93+
lock := unix.Flock_t{
9494
Type: unix.F_UNLCK,
9595
Start: start,
9696
Len: len,
97-
})
98-
if err != nil {
99-
return _IOERR_UNLOCK
10097
}
101-
return _OK
98+
for {
99+
err := unix.FcntlFlock(file.Fd(), _F_OFD_SETLK, &lock)
100+
if err == nil {
101+
return _OK
102+
}
103+
if err != unix.EINTR {
104+
return _IOERR_UNLOCK
105+
}
106+
}
102107
}

vfs/os_linux.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,18 @@ func osLock(file *os.File, typ int16, start, len int64, timeout time.Duration, d
6969
}
7070

7171
func osUnlock(file *os.File, start, len int64) _ErrorCode {
72-
err := unix.FcntlFlock(file.Fd(), unix.F_OFD_SETLK, &unix.Flock_t{
72+
lock := unix.Flock_t{
7373
Type: unix.F_UNLCK,
7474
Start: start,
7575
Len: len,
76-
})
77-
if err != nil {
78-
return _IOERR_UNLOCK
7976
}
80-
return _OK
77+
for {
78+
err := unix.FcntlFlock(file.Fd(), unix.F_OFD_SETLK, &lock)
79+
if err == nil {
80+
return _OK
81+
}
82+
if err != unix.EINTR {
83+
return _IOERR_UNLOCK
84+
}
85+
}
8186
}

vfs/os_unix.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,15 @@ func osTestLock(file *os.File, start, len int64) (int16, _ErrorCode) {
6565
Start: start,
6666
Len: len,
6767
}
68-
if unix.FcntlFlock(file.Fd(), unix.F_GETLK, &lock) != nil {
69-
return 0, _IOERR_CHECKRESERVEDLOCK
68+
for {
69+
err := unix.FcntlFlock(file.Fd(), unix.F_GETLK, &lock)
70+
if err == nil {
71+
return lock.Type, _OK
72+
}
73+
if err != unix.EINTR {
74+
return 0, _IOERR_CHECKRESERVEDLOCK
75+
}
7076
}
71-
return lock.Type, _OK
7277
}
7378

7479
func osLockErrorCode(err error, def _ErrorCode) _ErrorCode {

0 commit comments

Comments
 (0)