Document variable usage in fd_posix

Update some code based on that documentation
pull/1608/head
Craig Tiller 10 years ago
parent 609fa1da4c
commit 354bf6d77b
  1. 20
      src/core/iomgr/fd_posix.c
  2. 24
      src/core/iomgr/fd_posix.h

@ -96,7 +96,7 @@ static grpc_fd *alloc_fd(int fd) {
gpr_atm_rel_store(&r->writest, NOT_READY);
gpr_atm_rel_store(&r->shutdown, 0);
r->fd = fd;
r->watcher_root.next = r->watcher_root.prev = &r->watcher_root;
r->inactive_watcher_root.next = r->inactive_watcher_root.prev = &r->inactive_watcher_root;
r->freelist_next = NULL;
r->read_watcher = r->write_watcher = NULL;
return r;
@ -149,8 +149,12 @@ int grpc_fd_is_orphaned(grpc_fd *fd) {
}
static void maybe_wake_one_watcher_locked(grpc_fd *fd) {
if (fd->watcher_root.next != &fd->watcher_root) {
grpc_pollset_force_kick(fd->watcher_root.next->pollset);
if (fd->inactive_watcher_root.next != &fd->inactive_watcher_root) {
grpc_pollset_force_kick(fd->inactive_watcher_root.next->pollset);
} else if (fd->read_watcher) {
grpc_pollset_force_kick(fd->read_watcher->pollset);
} else if (fd->write_watcher) {
grpc_pollset_force_kick(fd->write_watcher->pollset);
}
}
@ -162,10 +166,16 @@ static void maybe_wake_one_watcher(grpc_fd *fd) {
static void wake_all_watchers(grpc_fd *fd) {
grpc_fd_watcher *watcher;
for (watcher = fd->watcher_root.next; watcher != &fd->watcher_root;
for (watcher = fd->inactive_watcher_root.next; watcher != &fd->inactive_watcher_root;
watcher = watcher->next) {
grpc_pollset_force_kick(watcher->pollset);
}
if (fd->read_watcher) {
grpc_pollset_force_kick(fd->read_watcher->pollset);
}
if (fd->write_watcher && fd->write_watcher != fd->read_watcher) {
grpc_pollset_force_kick(fd->write_watcher->pollset);
}
}
void grpc_fd_orphan(grpc_fd *fd, grpc_iomgr_cb_func on_done, void *user_data) {
@ -319,7 +329,7 @@ gpr_uint32 grpc_fd_begin_poll(grpc_fd *fd, grpc_pollset *pollset,
}
/* if not polling, remember this watcher in case we need someone to later */
if (mask == 0) {
watcher->next = &fd->watcher_root;
watcher->next = &fd->inactive_watcher_root;
watcher->prev = watcher->next->prev;
watcher->next->prev = watcher->prev->next = watcher;
}

@ -66,8 +66,30 @@ struct grpc_fd {
gpr_mu set_state_mu;
gpr_atm shutdown;
/* The watcher list.
The following watcher related fields are protected by watcher_mu.
An fd_watcher is an ephemeral object created when an fd wants to
begin polling, and destroyed after the poll.
It denotes the fd's interest in whether to read poll or write poll
or both or neither on this fd.
If a watcher is asked to poll for reads or writes, the read_watcher
or write_watcher fields are set respectively. A watcher may be asked
to poll for both, in which case both fields will be set.
read_watcher and write_watcher may be NULL if no watcher has been
asked to poll for reads or writes.
If an fd_watcher is not asked to poll for reads or writes, it's added
to a linked list of inactive watchers, rooted at inactive_watcher_root.
If at a later time there becomes need of a poller to poll, one of
the inactive pollers may be kicked out of their poll loops to take
that responsibility. */
gpr_mu watcher_mu;
grpc_fd_watcher watcher_root;
grpc_fd_watcher inactive_watcher_root;
grpc_fd_watcher *read_watcher;
grpc_fd_watcher *write_watcher;

Loading…
Cancel
Save