diff options
author | Brad King <brad.king@kitware.com> | 2018-01-19 18:03:04 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2018-01-19 18:03:04 (GMT) |
commit | b58d48c15f9ee18015960e2eed7410f5166c855f (patch) | |
tree | 640add606d5ca6c0a03f58589a7528eaa9511428 /Utilities/cmlibuv/src/threadpool.c | |
parent | e8b57c2283f731f42b4c7eece0531dab67df3d41 (diff) | |
parent | f4a26c748b5ea2cafecdf5490b744a2b167c01ae (diff) | |
download | CMake-b58d48c15f9ee18015960e2eed7410f5166c855f.zip CMake-b58d48c15f9ee18015960e2eed7410f5166c855f.tar.gz CMake-b58d48c15f9ee18015960e2eed7410f5166c855f.tar.bz2 |
Merge branch 'upstream-libuv' into update-libuv
* upstream-libuv:
libuv 2018-01-19 (63de1eca)
Diffstat (limited to 'Utilities/cmlibuv/src/threadpool.c')
-rw-r--r-- | Utilities/cmlibuv/src/threadpool.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/Utilities/cmlibuv/src/threadpool.c b/Utilities/cmlibuv/src/threadpool.c index 1089341..413d1c2 100644 --- a/Utilities/cmlibuv/src/threadpool.c +++ b/Utilities/cmlibuv/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); } |