File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -67,7 +67,11 @@ func (s *Weighted) Acquire(ctx context.Context, n int64) error {
6767// fix up the queue, just pretend we didn't notice the cancelation.
6868err = nil
6969default :
70+ isFront := s .waiters .Front () == elem
7071s .waiters .Remove (elem )
72+ if isFront && s .size > s .cur {
73+ s .notifyWaiters ()
74+ }
7175}
7276s .mu .Unlock ()
7377return err
@@ -97,6 +101,11 @@ func (s *Weighted) Release(n int64) {
97101s .mu .Unlock ()
98102panic ("semaphore: released more than held" )
99103}
104+ s .notifyWaiters ()
105+ s .mu .Unlock ()
106+ }
107+
108+ func (s * Weighted ) notifyWaiters () {
100109for {
101110next := s .waiters .Front ()
102111if next == nil {
@@ -123,5 +132,4 @@ func (s *Weighted) Release(n int64) {
123132s .waiters .Remove (next )
124133close (w .ready )
125134}
126- s .mu .Unlock ()
127135}
You can’t perform that action at this time.
0 commit comments