MCPcopy Create free account
hub / github.com/cloudwego/netpoll / Pick

Method Pick

poll_manager.go:130–152  ·  view source on GitHub ↗

Pick will select the poller for use each time based on the LoadBalance.

()

Source from the content-addressed store, hash-verified

128
129// Pick will select the poller for use each time based on the LoadBalance.
130func (m *manager) Pick() Poll {
131START:
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}

Callers

nothing calls this directly

Calls 2

RunMethod · 0.95
PickMethod · 0.65

Tested by

no test coverage detected