void uv__worker_thread_loop(void *ptr) { uv__worker_thread_t *worker_thread = (uv__worker_thread_t *)ptr; uv_worker_t *worker = worker_thread->worker; #ifdef __APPLE__ if (worker->name) { pthread_setname_np(worker->name); } #endif uv__worker_item_t *item = NULL; while ((item = (uv__worker_item_t *)uv_chan_receive(&worker->chan)) != NULL) { assert(item->work_cb); item->work_cb(item->data); // Trigger the after callback in the main thread. uv_messenger_send(worker->msgr, item); } // Make sure to close all other workers too. uv_chan_send(&worker->chan, NULL); // Create a new worker item that acts as a terminate flag for this thread. item = (uv__worker_item_t *)malloc(sizeof(uv__worker_item_t)); item->data = worker_thread; item->work_cb = NULL; item->after_work_cb = NULL; uv_messenger_send(worker->msgr, item); }
void CachingHTTPFileSource::prepare(std::function<void()> fn) { if (thread_id == std::this_thread::get_id()) { fn(); } else { uv_messenger_send(queue, new std::function<void()>(std::move(fn))); } }