Skip to content

Commit

Permalink
Fix POSIX locks.
Browse files Browse the repository at this point in the history
  • Loading branch information
ncruces committed Dec 18, 2024
1 parent 9bc39c5 commit e0c6086
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions vfs/shm_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type vfsShmParent struct {

refs int // +checklocks:vfsShmListMtx

lock [_SHM_NLOCK]int16 // +checklocks:Mutex
lock [_SHM_NLOCK]int8 // +checklocks:Mutex
sync.Mutex
}

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

// Obtain/release the appropriate file lock.
// Obtain/release the appropriate file locks.
switch {
case flags&_SHM_UNLOCK != 0:
return osUnlock(s.File, _SHM_BASE+int64(offset), int64(n))
begin, end := offset, offset+n
for i := begin; i < end; i++ {
if s.vfsShmParent.lock[i] != 0 {
if i > begin {
rc |= osUnlock(s.File, _SHM_BASE+int64(begin), int64(i-begin))
}
begin = i + 1
}
}
if end > begin {
rc |= osUnlock(s.File, _SHM_BASE+int64(begin), int64(end-begin))
}
return rc
case flags&_SHM_SHARED != 0:
rc = osReadLock(s.File, _SHM_BASE+int64(offset), int64(n))
case flags&_SHM_EXCLUSIVE != 0:
Expand All @@ -196,7 +208,7 @@ func (s *vfsShm) shmLock(offset, n int32, flags _ShmFlag) _ErrorCode {
panic(util.AssertErr())
}

// Release the local lock.
// Reacquire the local lock.
if rc != _OK {
s.shmMemLock(offset, n, flags^(_SHM_UNLOCK|_SHM_LOCK))
}
Expand Down
2 changes: 1 addition & 1 deletion vfs/shm_dotlk.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type vfsShmParent struct {
shared [][_WALINDEX_PGSZ]byte
refs int // +checklocks:vfsShmListMtx

lock [_SHM_NLOCK]int16 // +checklocks:Mutex
lock [_SHM_NLOCK]int8 // +checklocks:Mutex
sync.Mutex
}

Expand Down

0 comments on commit e0c6086

Please sign in to comment.