forked from cory/tildefriends
libuv 1.45.0, #include cleanup, probably something else.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4308 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
27
deps/libuv/src/threadpool.c
vendored
27
deps/libuv/src/threadpool.c
vendored
@ -191,6 +191,7 @@ void uv__threadpool_cleanup(void) {
|
||||
|
||||
|
||||
static void init_threads(void) {
|
||||
uv_thread_options_t config;
|
||||
unsigned int i;
|
||||
const char* val;
|
||||
uv_sem_t sem;
|
||||
@ -226,8 +227,11 @@ static void init_threads(void) {
|
||||
if (uv_sem_init(&sem, 0))
|
||||
abort();
|
||||
|
||||
config.flags = UV_THREAD_HAS_STACK_SIZE;
|
||||
config.stack_size = 8u << 20; /* 8 MB */
|
||||
|
||||
for (i = 0; i < nthreads; i++)
|
||||
if (uv_thread_create(threads + i, worker, &sem))
|
||||
if (uv_thread_create_ex(threads + i, &config, worker, &sem))
|
||||
abort();
|
||||
|
||||
for (i = 0; i < nthreads; i++)
|
||||
@ -271,9 +275,13 @@ void uv__work_submit(uv_loop_t* loop,
|
||||
}
|
||||
|
||||
|
||||
/* TODO(bnoordhuis) teach libuv how to cancel file operations
|
||||
* that go through io_uring instead of the thread pool.
|
||||
*/
|
||||
static int uv__work_cancel(uv_loop_t* loop, uv_req_t* req, struct uv__work* w) {
|
||||
int cancelled;
|
||||
|
||||
uv_once(&once, init_once); /* Ensure |mutex| is initialized. */
|
||||
uv_mutex_lock(&mutex);
|
||||
uv_mutex_lock(&w->loop->wq_mutex);
|
||||
|
||||
@ -303,12 +311,15 @@ void uv__work_done(uv_async_t* handle) {
|
||||
QUEUE* q;
|
||||
QUEUE wq;
|
||||
int err;
|
||||
int nevents;
|
||||
|
||||
loop = container_of(handle, uv_loop_t, wq_async);
|
||||
uv_mutex_lock(&loop->wq_mutex);
|
||||
QUEUE_MOVE(&loop->wq, &wq);
|
||||
uv_mutex_unlock(&loop->wq_mutex);
|
||||
|
||||
nevents = 0;
|
||||
|
||||
while (!QUEUE_EMPTY(&wq)) {
|
||||
q = QUEUE_HEAD(&wq);
|
||||
QUEUE_REMOVE(q);
|
||||
@ -316,6 +327,20 @@ void uv__work_done(uv_async_t* handle) {
|
||||
w = container_of(q, struct uv__work, wq);
|
||||
err = (w->work == uv__cancelled) ? UV_ECANCELED : 0;
|
||||
w->done(w, err);
|
||||
nevents++;
|
||||
}
|
||||
|
||||
/* This check accomplishes 2 things:
|
||||
* 1. Even if the queue was empty, the call to uv__work_done() should count
|
||||
* as an event. Which will have been added by the event loop when
|
||||
* calling this callback.
|
||||
* 2. Prevents accidental wrap around in case nevents == 0 events == 0.
|
||||
*/
|
||||
if (nevents > 1) {
|
||||
/* Subtract 1 to counter the call to uv__work_done(). */
|
||||
uv__metrics_inc_events(loop, nevents - 1);
|
||||
if (uv__get_internal_fields(loop)->current_timeout == 0)
|
||||
uv__metrics_inc_events_waiting(loop, nevents - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user