diff options
author | libuv upstream <libuv@googlegroups.com> | 2018-01-19 16:57:06 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2018-01-19 18:03:03 (GMT) |
commit | f4a26c748b5ea2cafecdf5490b744a2b167c01ae (patch) | |
tree | f59656c8a8c55c9e5482185a827f24457f1f9ae3 /src/threadpool.c | |
parent | 362435f02a52008a90a1c19862f09b01f1b5bd7f (diff) | |
download | CMake-f4a26c748b5ea2cafecdf5490b744a2b167c01ae.zip CMake-f4a26c748b5ea2cafecdf5490b744a2b167c01ae.tar.gz CMake-f4a26c748b5ea2cafecdf5490b744a2b167c01ae.tar.bz2 |
libuv 2018-01-19 (63de1eca)
Code extracted from:
https://github.com/libuv/libuv.git
at commit 63de1ecad3252d3e9ed2fe960c21d9387615fa45 (v1.x).
Diffstat (limited to 'src/threadpool.c')
-rw-r--r-- | src/threadpool.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/threadpool.c b/src/threadpool.c index 1089341..413d1c2 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -38,7 +38,6 @@ static uv_thread_t* threads; static uv_thread_t default_threads[4]; static QUEUE exit_message; static QUEUE wq; -static volatile int initialized; static void uv__cancelled(struct uv__work* w) { @@ -53,7 +52,8 @@ static void worker(void* arg) { struct uv__work* w; QUEUE* q; - (void) arg; + uv_sem_post((uv_sem_t*) arg); + arg = NULL; for (;;) { uv_mutex_lock(&mutex); @@ -105,7 +105,7 @@ static void post(QUEUE* q) { UV_DESTRUCTOR(static void cleanup(void)) { unsigned int i; - if (initialized == 0) + if (nthreads == 0) return; post(&exit_message); @@ -122,7 +122,6 @@ UV_DESTRUCTOR(static void cleanup(void)) { threads = NULL; nthreads = 0; - initialized = 0; } #endif @@ -130,6 +129,7 @@ UV_DESTRUCTOR(static void cleanup(void)) { static void init_threads(void) { unsigned int i; const char* val; + uv_sem_t sem; nthreads = ARRAY_SIZE(default_threads); val = getenv("UV_THREADPOOL_SIZE"); @@ -157,11 +157,17 @@ static void init_threads(void) { QUEUE_INIT(&wq); + if (uv_sem_init(&sem, 0)) + abort(); + for (i = 0; i < nthreads; i++) - if (uv_thread_create(threads + i, worker, NULL)) + if (uv_thread_create(threads + i, worker, &sem)) abort(); - initialized = 1; + for (i = 0; i < nthreads; i++) + uv_sem_wait(&sem); + + uv_sem_destroy(&sem); } |