Pick will select the poller for use each time based on the LoadBalance.
()
| 128 | |
| 129 | // Pick will select the poller for use each time based on the LoadBalance. |
| 130 | func (m *manager) Pick() Poll { |
| 131 | START: |
| 132 | // fast path |
| 133 | if atomic.LoadInt32(&m.status) == managerInitialized { |
| 134 | return m.balance.Pick() |
| 135 | } |
| 136 | // slow path |
| 137 | // try to get initializing lock failed, wait others finished the init work, and try again |
| 138 | if !atomic.CompareAndSwapInt32(&m.status, managerUninitialized, managerInitializing) { |
| 139 | runtime.Gosched() |
| 140 | goto START |
| 141 | } |
| 142 | // adjust polls |
| 143 | // m.Run() will finish very quickly, so will not many goroutines block on Pick. |
| 144 | _ = m.Run() |
| 145 | |
| 146 | //nolint:staticcheck // SA9003: empty branch |
| 147 | if !atomic.CompareAndSwapInt32(&m.status, managerInitializing, managerInitialized) { |
| 148 | // SetNumLoops called during m.Run() which cause CAS failed |
| 149 | // The polls will be adjusted next Pick |
| 150 | } |
| 151 | return m.balance.Pick() |
| 152 | } |