I'm writing a piece of C code for Node.js and want to distinguish synchroneous from asynchroneous calls. In other words, I want to detect whether my code is running on the V8 event dispatch thread, called from within the main event loop, or whether it's called from some separate worker thread. In the former case, I could call back to JavaScript immediately, while in the latter I'd have to use a more complicated async callback.
The libuv threading API provides uv_thread_self
to identify the current thread, and uv_thread_equal
to compare threads for equality. So all I need is find the uv_thread_t
of the main event loop.