HasUniqueRef returns true if all pages in the given range have exactly one reference. A return value of false is inherently racy, but if the caller holds a reference on the given range and is preventing other goroutines from copying it, then a return value of true is not racy. Preconditions: At lea
(fr memmap.FileRange)
| 1147 | // |
| 1148 | // Preconditions: At least one reference must be held on all pages in fr. |
| 1149 | func (f *MemoryFile) HasUniqueRef(fr memmap.FileRange) bool { |
| 1150 | hasUniqueRef := true |
| 1151 | f.mu.Lock() |
| 1152 | defer f.mu.Unlock() |
| 1153 | f.forEachChunk(fr, func(chunk *chunkInfo, chunkFR memmap.FileRange) bool { |
| 1154 | unfree := &f.unfreeSmall |
| 1155 | if chunk.huge { |
| 1156 | unfree = &f.unfreeHuge |
| 1157 | } |
| 1158 | unfree.VisitFullRange(fr, func(ufseg unfreeIterator) bool { |
| 1159 | if ufseg.ValuePtr().refs != 1 { |
| 1160 | hasUniqueRef = false |
| 1161 | return false |
| 1162 | } |
| 1163 | return true |
| 1164 | }) |
| 1165 | return hasUniqueRef |
| 1166 | }) |
| 1167 | return hasUniqueRef |
| 1168 | } |
| 1169 | |
| 1170 | // IncRef implements memmap.File.IncRef. |
| 1171 | func (f *MemoryFile) IncRef(fr memmap.FileRange, memCgID uint32) { |
no test coverage detected