Skip to content

Commit e0c6086

Browse files
committed
Fix POSIX locks.
1 parent 9bc39c5 commit e0c6086

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

vfs/shm_bsd.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type vfsShmParent struct {
2222

2323
refs int // +checklocks:vfsShmListMtx
2424

25-
lock [_SHM_NLOCK]int16 // +checklocks:Mutex
25+
lock [_SHM_NLOCK]int8 // +checklocks:Mutex
2626
sync.Mutex
2727
}
2828

@@ -184,10 +184,22 @@ func (s *vfsShm) shmLock(offset, n int32, flags _ShmFlag) _ErrorCode {
184184
return rc
185185
}
186186

187-
// Obtain/release the appropriate file lock.
187+
// Obtain/release the appropriate file locks.
188188
switch {
189189
case flags&_SHM_UNLOCK != 0:
190-
return osUnlock(s.File, _SHM_BASE+int64(offset), int64(n))
190+
begin, end := offset, offset+n
191+
for i := begin; i < end; i++ {
192+
if s.vfsShmParent.lock[i] != 0 {
193+
if i > begin {
194+
rc |= osUnlock(s.File, _SHM_BASE+int64(begin), int64(i-begin))
195+
}
196+
begin = i + 1
197+
}
198+
}
199+
if end > begin {
200+
rc |= osUnlock(s.File, _SHM_BASE+int64(begin), int64(end-begin))
201+
}
202+
return rc
191203
case flags&_SHM_SHARED != 0:
192204
rc = osReadLock(s.File, _SHM_BASE+int64(offset), int64(n))
193205
case flags&_SHM_EXCLUSIVE != 0:
@@ -196,7 +208,7 @@ func (s *vfsShm) shmLock(offset, n int32, flags _ShmFlag) _ErrorCode {
196208
panic(util.AssertErr())
197209
}
198210

199-
// Release the local lock.
211+
// Reacquire the local lock.
200212
if rc != _OK {
201213
s.shmMemLock(offset, n, flags^(_SHM_UNLOCK|_SHM_LOCK))
202214
}

vfs/shm_dotlk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type vfsShmParent struct {
1818
shared [][_WALINDEX_PGSZ]byte
1919
refs int // +checklocks:vfsShmListMtx
2020

21-
lock [_SHM_NLOCK]int16 // +checklocks:Mutex
21+
lock [_SHM_NLOCK]int8 // +checklocks:Mutex
2222
sync.Mutex
2323
}
2424

0 commit comments

Comments
 (0)