As far as I can tell this is not actually needed, as we decrement
it right away, but it prevents TSAN from reporting a race when the
UDP response comes very fast, is truncated, and the query is then
passed to a TCP worker. TSAN seems to think that the thread is still
sending the UDP query when we touch it again in the TCP worker, which
does not really make sense to me.
My guess is that the memory barrier needed to update the ref counter
makes TSAN happy, but I might be missing something.
static void sendDoHUnitToTheMainThread(std::unique_ptr<DOHUnit, void(*)(DOHUnit*)>&& du, const char* description)
{
auto ptr = du.release();
+ ptr->get();
static_assert(sizeof(ptr) <= PIPE_BUF, "Writes up to PIPE_BUF are guaranteed not to be interleaved and to either fully succeed or fail");
ssize_t sent = write(ptr->rsock, &ptr, sizeof(ptr));
ptr->release();
}
+ ptr->release();
}
/* This function is called from other threads than the main DoH one,