Lock waits until there is exactly one pending ref (the caller's). It panics if the *fd.FD isn't already in the closed state. In most situations, Lock should be called after the ClosingIncRef and before the close(2) syscall.
()
| 150 | // if the *fd.FD isn't already in the closed state. In most situations, Lock |
| 151 | // should be called after the ClosingIncRef and before the close(2) syscall. |
| 152 | func (fd *FD) Lock() { |
| 153 | refs := atomic.LoadUint32(&fd.refs) |
| 154 | left := refs &^ uint32(flagClosed) |
| 155 | if refs&flagClosed == 0 { |
| 156 | panic("Lock called without marking file as closed") |
| 157 | } |
| 158 | if DEBUG { |
| 159 | fmt.Printf("%p: %s: Lock: left=%d, closed=%v\n", fd, fd.String(), left, refs&flagClosed) |
| 160 | } |
| 161 | if left > 1 { |
| 162 | // The last non-closing DecRef will do a semrelease. |
| 163 | semacquire(&fd.sema) |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | //go:linkname semacquire sync.runtime_Semacquire |
| 168 | func semacquire(addr *uint32) |
no test coverage detected