Fix more data races in shm debug messages.

PiperOrigin-RevId: 241630409
Change-Id: Ie0df5f5a2f20c2d32e615f16e2ba43c88f963181
This commit is contained in:
Rahat Mahmood
2019-04-02 16:46:32 -07:00
committed by Shentubot
parent 1fcd40719d
commit d14a7de658
+9 -3
View File
@@ -286,7 +286,7 @@ func (r *Registry) remove(s *Shm) {
defer s.mu.Unlock()
if s.key != linux.IPC_PRIVATE {
panic(fmt.Sprintf("Attempted to remove shm segment %d (key=%d) from the registry whose key is still associated", s.ID, s.key))
panic(fmt.Sprintf("Attempted to remove %s from the registry whose key is still associated", s.debugLocked()))
}
delete(r.shms, s.ID)
@@ -370,6 +370,12 @@ type Shm struct {
pendingDestruction bool
}
// Precondition: Caller must hold s.mu.
func (s *Shm) debugLocked() string {
return fmt.Sprintf("Shm{id: %d, key: %d, size: %d bytes, refs: %d, destroyed: %v}",
s.ID, s.key, s.size, s.ReadRefs(), s.pendingDestruction)
}
// MappedName implements memmap.MappingIdentity.MappedName.
func (s *Shm) MappedName(ctx context.Context) string {
s.mu.Lock()
@@ -412,7 +418,7 @@ func (s *Shm) AddMapping(ctx context.Context, _ memmap.MappingSpace, _ usermem.A
} else {
// AddMapping is called during a syscall, so ctx should always be a task
// context.
log.Warningf("Adding mapping to shm %+v but couldn't get the current pid; not updating the last attach pid", s)
log.Warningf("Adding mapping to %s but couldn't get the current pid; not updating the last attach pid", s.debugLocked())
}
return nil
}
@@ -434,7 +440,7 @@ func (s *Shm) RemoveMapping(ctx context.Context, _ memmap.MappingSpace, _ userme
if pid, ok := context.ThreadGroupIDFromContext(ctx); ok {
s.lastAttachDetachPID = pid
} else {
log.Debugf("Couldn't obtain pid when removing mapping to shm %+v, not updating the last detach pid.", s)
log.Debugf("Couldn't obtain pid when removing mapping to %s, not updating the last detach pid.", s.debugLocked())
}
}