grpc_handshake is renamed to GrpcHandshake, using C++ class definitions
instead of C-style vtable classes. Update callers to use new interfaces.
We use RefCountedPtr to simplify reference tracking.
This was originally done for ExcCtx in
https://github.com/grpc/grpc/pull/15825. This avoids a hang in our
pre-fork handler, where grpc_core::Executor::RunClosures attempts to
increment the thread count from an invocation of grpc_prefork():
Masking a value and comparing to one will only work if the mask itself
is equal to one (which is not the case here). Comparing to zero works
for any mask.
Each pollset in pollex has a lock, grabbed upon adding an FD
to the pollset. Since this is called on a per-call basis,
there is a flat array caching the FDs of the pollset, to
avoid unnecessarily calling epoll_ctl multiple times for
the same FD.
This has two problems:
1) When multiple threads add FDs to the same pollset,
we will have contention on the pollset lock.
2) When we have many FDs we simply run out of cache storage,
and call epoll_ctl().
This commit changes the caching strategy by simply storing
the epfd of pollsets of an FD inside that FD, when we are in
PO_MULTI mode. This results in address in both (1) and (2).
Moreover, this commit fixes another performance bug.
When we have a release FD callback, we do not call close().
That FD will remain in our epollset, until the new owner of
the FD actually call close(). This results in a lot of spurious
wake ups when we simply hand off gRPC FDs to other FDs.
Note that this is a revision on the reverted commit
e83e463b5a (PR #17823).
The main change is to track the epfd of the pollset
instead of the pollset pointer, so that if the pollset
is deleted we can still access the FD. It also halves
the size of the cache vector for 64-bit machines.
Each pollset in pollex has a lock, grabbed upon adding an FD
to the pollset. Since this is called on a per-call basis,
there is a flat array caching the FDs of the pollset, to
avoid unnecessarily calling epoll_ctl multiple times for
the same FD.
This has two problems:
1) When multiple threads add FDs to the same pollset,
we will have contention on the pollset lock.
2) When we have many FDs we simply run out of cache storage,
and call epoll_ctl().
This commit changes the caching strategy by simply storing
the pollsets of an FD inside that FD, when we are in PO_MULTI
mode. This results in address in both (1) and (2).
Moreover, this commit fixes another performance bug.
When we have a release FD callback, we do not call close().
That FD will remain in our epollset, until the new owner of
the FD actually call close(). This results in a lot of spurious
wake ups when we simply hand off gRPC FDs to other FDs.