unix: fix race condition in uv_async_send()
unix: fix race condition in uv_async_send()

After inspection of the code, it seems like there is a race window
between the cmpxchgi() and uv__async_send() calls.

If the event loop thread is already busy looping over the async handles,
it can invoke the callback - which in turn can close the handle - before
the other thread reaches the uv__async_send() call. That's bad because
it accesses the handle that at that point might not be valid anymore.

Fix that by introducing an ad hoc spinlock that blocks the event loop
thread until the sending thread is done. It's not pretty or elegant
but it fixes the immediate bug and appears to have no measurable
impact on the async handle benchmarks.

Fixes: https://github.com/libuv/libuv/issues/2226
PR-URL: https://github.com/libuv/libuv/pull/2231
Reviewed-By: Santiago Gimeno <3f17e29e343c4cf8809fb0970d81d6d8ee88d6b3@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <8a7991f6950ea189abf159d6ec98d2fcc13dc5f6@gmail.com>

unknownbrackets/maxcso,unknownbrackets/maxcso,unknownbrackets/maxcso,unknownbrackets/maxcso,unknownbrackets/maxcso,unknownbrackets/maxcso,unknownbrackets/maxcso