* This functions runs in infinite blocking loop until there is no fd in * pfdset. It calls corresponding r/w handler if there is event on the fd. * * Before the callback is called, we set the flag to busy status; If other * thread(now rte_vhost_driver_unregister) calls fdset_del concurrently, it * will wait until the flag is reset to zero(which indicates the callback is * finished), then it
| 213 | * finished), then it could free the context after fdset_del. |
| 214 | */ |
| 215 | uint32_t |
| 216 | fdset_event_dispatch(void *arg) |
| 217 | { |
| 218 | int i; |
| 219 | struct pollfd *pfd; |
| 220 | struct fdentry *pfdentry; |
| 221 | fd_cb rcb, wcb; |
| 222 | void *dat; |
| 223 | int fd, numfds; |
| 224 | int remove1, remove2; |
| 225 | int need_shrink; |
| 226 | struct fdset *pfdset = arg; |
| 227 | int val; |
| 228 | |
| 229 | if (pfdset == NULL) |
| 230 | return 0; |
| 231 | |
| 232 | while (1) { |
| 233 | |
| 234 | /* |
| 235 | * When poll is blocked, other threads might unregister |
| 236 | * listenfds from and register new listenfds into fdset. |
| 237 | * When poll returns, the entries for listenfds in the fdset |
| 238 | * might have been updated. It is ok if there is unwanted call |
| 239 | * for new listenfds. |
| 240 | */ |
| 241 | pthread_mutex_lock(&pfdset->fd_mutex); |
| 242 | numfds = pfdset->num; |
| 243 | pthread_mutex_unlock(&pfdset->fd_mutex); |
| 244 | |
| 245 | pthread_mutex_lock(&pfdset->fd_pooling_mutex); |
| 246 | val = poll(pfdset->rwfds, numfds, 1000 /* millisecs */); |
| 247 | pthread_mutex_unlock(&pfdset->fd_pooling_mutex); |
| 248 | if (val < 0) |
| 249 | continue; |
| 250 | |
| 251 | need_shrink = 0; |
| 252 | for (i = 0; i < numfds; i++) { |
| 253 | pthread_mutex_lock(&pfdset->fd_mutex); |
| 254 | |
| 255 | pfdentry = &pfdset->fd[i]; |
| 256 | fd = pfdentry->fd; |
| 257 | pfd = &pfdset->rwfds[i]; |
| 258 | |
| 259 | if (fd < 0) { |
| 260 | need_shrink = 1; |
| 261 | pthread_mutex_unlock(&pfdset->fd_mutex); |
| 262 | continue; |
| 263 | } |
| 264 | |
| 265 | if (!pfd->revents) { |
| 266 | pthread_mutex_unlock(&pfdset->fd_mutex); |
| 267 | continue; |
| 268 | } |
| 269 | |
| 270 | remove1 = remove2 = 0; |
| 271 | |
| 272 | rcb = pfdentry->rcb; |
nothing calls this directly
no test coverage detected