| 132 | } |
| 133 | |
| 134 | Worker* NetworkStack::get_worker() |
| 135 | { |
| 136 | ldout(cct, 30) << __func__ << dendl; |
| 137 | |
| 138 | // start with some reasonably large number |
| 139 | unsigned min_load = std::numeric_limits<int>::max(); |
| 140 | Worker* current_best = nullptr; |
| 141 | |
| 142 | pool_spin.lock(); |
| 143 | // find worker with least references |
| 144 | // tempting case is returning on references == 0, but in reality |
| 145 | // this will happen so rarely that there's no need for special case. |
| 146 | for (Worker* worker : workers) { |
| 147 | unsigned worker_load = worker->references.load(); |
| 148 | if (worker_load < min_load) { |
| 149 | current_best = worker; |
| 150 | min_load = worker_load; |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | pool_spin.unlock(); |
| 155 | ceph_assert(current_best); |
| 156 | ++current_best->references; |
| 157 | return current_best; |
| 158 | } |
| 159 | |
| 160 | void NetworkStack::stop() |
| 161 | { |
no test coverage detected