TODO(bnoordhuis) teach libuv how to cancel file operations * that go through io_uring instead of the thread pool. */
| 279 | * that go through io_uring instead of the thread pool. |
| 280 | */ |
| 281 | static int uv__work_cancel(uv_loop_t* loop, uv_req_t* req, struct uv__work* w) { |
| 282 | int cancelled; |
| 283 | |
| 284 | uv_once(&once, init_once); /* Ensure |mutex| is initialized. */ |
| 285 | uv_mutex_lock(&mutex); |
| 286 | uv_mutex_lock(&w->loop->wq_mutex); |
| 287 | |
| 288 | cancelled = !uv__queue_empty(&w->wq) && w->work != NULL; |
| 289 | if (cancelled) |
| 290 | uv__queue_remove(&w->wq); |
| 291 | |
| 292 | uv_mutex_unlock(&w->loop->wq_mutex); |
| 293 | uv_mutex_unlock(&mutex); |
| 294 | |
| 295 | if (!cancelled) |
| 296 | return UV_EBUSY; |
| 297 | |
| 298 | w->work = uv__cancelled; |
| 299 | uv_mutex_lock(&loop->wq_mutex); |
| 300 | uv__queue_insert_tail(&loop->wq, &w->wq); |
| 301 | uv_async_send(&loop->wq_async); |
| 302 | uv_mutex_unlock(&loop->wq_mutex); |
| 303 | |
| 304 | return 0; |
| 305 | } |
| 306 | |
| 307 | |
| 308 | void uv__work_done(uv_async_t* handle) { |
no test coverage detected