| // Copyright 2014 The Go Authors. |
| // See https://code.google.com/p/go/source/browse/CONTRIBUTORS |
| // Licensed under the same terms as Go itself: |
| // https://code.google.com/p/go/source/browse/LICENSE |
| // flow is the flow control window's counting semaphore. |
| c *sync.Cond // protects size |
| func newFlow(n int32) *flow { |
| c: sync.NewCond(new(sync.Mutex)), |
| // acquire decrements the flow control window by n bytes, blocking |
| // until they're available in the window. |
| // The return value is only interesting for tests. |
| func (f *flow) acquire(n int32) (waited int) { |
| panic("negative acquire") |
| // add adds n bytes (positive or negative) to the flow control window. |
| // It returns false if the sum would exceed 2^31-1. |
| func (f *flow) add(n int32) bool { |
| remain := (1<<31 - 1) - f.size |