(internal bool)
| 93 | } |
| 94 | |
| 95 | func (fd *FD) decRef(internal bool) { |
| 96 | refs := atomic.AddUint32(&fd.refs, ^uint32(0)) |
| 97 | left := refs &^ uint32(flagClosed) |
| 98 | if DEBUG { |
| 99 | fmt.Printf("%p: %s: DecRef: left=%d, closed=%v\n", fd, fd.String(), left, refs&flagClosed) |
| 100 | } |
| 101 | if left >= maxRefs { |
| 102 | panic(fmt.Sprintf("ref counter underflow: %08x", left)) |
| 103 | } |
| 104 | if refs&flagClosed != 0 { |
| 105 | switch left { |
| 106 | case 1: |
| 107 | // If this is the last non-closing DecRef, do a semrelease so that a |
| 108 | // pending semacquire call (if any) can wake up. |
| 109 | semrelease(&fd.sema, false, 0) |
| 110 | case 0: |
| 111 | // If we decremented the counter to zero, this is the closing DecRef. |
| 112 | val := atomic.SwapUint32(&fd.fd, ^uint32(0)) |
| 113 | if val == ^uint32(0) { |
| 114 | if !internal { |
| 115 | panic("invalid closed file descriptor state: found fd=-1 in DecRef to zero") |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | // DecRef decrements the ref counter. |
| 123 | // |
no test coverage detected