diff options
author | Michael Pratt <mpratt@google.com> | 2019-06-21 12:25:24 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2019-06-21 12:26:42 -0700 |
commit | c0317b28cb3f8346ee81564ee477aafdf6283f45 (patch) | |
tree | bb91240172a173aba9ed799deab7026d8e197ee1 /pkg/p9/server.go | |
parent | f94653b3dea629f365ce5742b99bbcaa7673ded2 (diff) |
Update pathNode documentation to reflect reality
Neither fidRefs or children are (directly) synchronized by mu. Remove
the preconditions that say so.
That said, the surrounding does enforce some synchronization guarantees
(e.g., fidRef.renameChildTo does not atomically replace the child in the
maps). I've tried to note the need for callers to do this
synchronization.
I've also renamed the maps to what are (IMO) clearer names. As is, it is
not obvious that pathNode.fidRefs is a map of *child* fidRefs rather
than self fidRefs.
PiperOrigin-RevId: 254446965
Diffstat (limited to 'pkg/p9/server.go')
-rw-r--r-- | pkg/p9/server.go | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/pkg/p9/server.go b/pkg/p9/server.go index bdeb495c2..c56b8e439 100644 --- a/pkg/p9/server.go +++ b/pkg/p9/server.go @@ -201,17 +201,17 @@ func (f *fidRef) maybeParent() *fidRef { // notifyDelete marks all fidRefs as deleted. // -// Precondition: the write lock must be held on the given pathNode. +// Precondition: this must be called via safelyWrite or safelyGlobal. func notifyDelete(pn *pathNode) { // Call on all local references. - pn.fidRefs.Range(func(key, _ interface{}) bool { + pn.fidRefNames.Range(func(key, _ interface{}) bool { ref := key.(*fidRef) atomic.StoreUint32(&ref.deleted, 1) return true }) // Call on all subtrees. - pn.children.Range(func(_, value interface{}) bool { + pn.childNodes.Range(func(_, value interface{}) bool { notifyDelete(value.(*pathNode)) return true }) @@ -233,10 +233,10 @@ func (f *fidRef) markChildDeleted(name string) { // recursively. Note that this applies only for subtrees, as these // notifications do not apply to the actual file whose name has changed. // -// Precondition: the write lock must be held on the given pathNode. +// Precondition: this must be called via safelyGlobal. func notifyNameChange(pn *pathNode) { // Call on all local references. - pn.fidRefs.Range(func(key, value interface{}) bool { + pn.fidRefNames.Range(func(key, value interface{}) bool { ref := key.(*fidRef) name := value.(string) ref.file.Renamed(ref.parent.file, name) @@ -244,7 +244,7 @@ func notifyNameChange(pn *pathNode) { }) // Call on all subtrees. - pn.children.Range(func(_, value interface{}) bool { + pn.childNodes.Range(func(name, value interface{}) bool { notifyNameChange(value.(*pathNode)) return true }) @@ -264,7 +264,7 @@ func (f *fidRef) renameChildTo(oldName string, target *fidRef, newName string) { }) // Replace the previous (now deleted) path node. - target.pathNode.children.Store(newName, origPathNode) + target.pathNode.childNodes.Store(newName, origPathNode) // Call Renamed on everything above. notifyNameChange(origPathNode) |