MCPcopy Index your code
hub / github.com/subtrace/subtrace / decRef

Method decRef

cmd/run/fd/fd.go:95–120  ·  view source on GitHub ↗
(internal bool)

Source from the content-addressed store, hash-verified

93}
94
95func (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//

Callers 2

IncRefMethod · 0.95
DecRefMethod · 0.95

Calls 2

StringMethod · 0.95
semreleaseFunction · 0.85

Tested by

no test coverage detected