| 306 | |
| 307 | |
| 308 | void uv__work_done(uv_async_t* handle) { |
| 309 | struct uv__work* w; |
| 310 | uv_loop_t* loop; |
| 311 | struct uv__queue* q; |
| 312 | struct uv__queue wq; |
| 313 | int err; |
| 314 | int nevents; |
| 315 | |
| 316 | loop = container_of(handle, uv_loop_t, wq_async); |
| 317 | uv_mutex_lock(&loop->wq_mutex); |
| 318 | uv__queue_move(&loop->wq, &wq); |
| 319 | uv_mutex_unlock(&loop->wq_mutex); |
| 320 | |
| 321 | nevents = 0; |
| 322 | |
| 323 | while (!uv__queue_empty(&wq)) { |
| 324 | q = uv__queue_head(&wq); |
| 325 | uv__queue_remove(q); |
| 326 | |
| 327 | w = container_of(q, struct uv__work, wq); |
| 328 | err = (w->work == uv__cancelled) ? UV_ECANCELED : 0; |
| 329 | w->done(w, err); |
| 330 | nevents++; |
| 331 | } |
| 332 | |
| 333 | /* This check accomplishes 2 things: |
| 334 | * 1. Even if the queue was empty, the call to uv__work_done() should count |
| 335 | * as an event. Which will have been added by the event loop when |
| 336 | * calling this callback. |
| 337 | * 2. Prevents accidental wrap around in case nevents == 0 events == 0. |
| 338 | */ |
| 339 | if (nevents > 1) { |
| 340 | /* Subtract 1 to counter the call to uv__work_done(). */ |
| 341 | uv__metrics_inc_events(loop, nevents - 1); |
| 342 | if (uv__get_internal_fields(loop)->current_timeout == 0) |
| 343 | uv__metrics_inc_events_waiting(loop, nevents - 1); |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | |
| 348 | static void uv__queue_work(struct uv__work* w) { |
nothing calls this directly
no test coverage detected