|
|
@ -96,7 +96,8 @@ static grpc_fd *alloc_fd(int fd) { |
|
|
|
gpr_atm_rel_store(&r->writest, NOT_READY); |
|
|
|
gpr_atm_rel_store(&r->writest, NOT_READY); |
|
|
|
gpr_atm_rel_store(&r->shutdown, 0); |
|
|
|
gpr_atm_rel_store(&r->shutdown, 0); |
|
|
|
r->fd = fd; |
|
|
|
r->fd = fd; |
|
|
|
r->inactive_watcher_root.next = r->inactive_watcher_root.prev = &r->inactive_watcher_root; |
|
|
|
r->inactive_watcher_root.next = r->inactive_watcher_root.prev = |
|
|
|
|
|
|
|
&r->inactive_watcher_root; |
|
|
|
r->freelist_next = NULL; |
|
|
|
r->freelist_next = NULL; |
|
|
|
r->read_watcher = r->write_watcher = NULL; |
|
|
|
r->read_watcher = r->write_watcher = NULL; |
|
|
|
return r; |
|
|
|
return r; |
|
|
@ -166,8 +167,8 @@ static void maybe_wake_one_watcher(grpc_fd *fd) { |
|
|
|
|
|
|
|
|
|
|
|
static void wake_all_watchers(grpc_fd *fd) { |
|
|
|
static void wake_all_watchers(grpc_fd *fd) { |
|
|
|
grpc_fd_watcher *watcher; |
|
|
|
grpc_fd_watcher *watcher; |
|
|
|
for (watcher = fd->inactive_watcher_root.next; watcher != &fd->inactive_watcher_root; |
|
|
|
for (watcher = fd->inactive_watcher_root.next; |
|
|
|
watcher = watcher->next) { |
|
|
|
watcher != &fd->inactive_watcher_root; watcher = watcher->next) { |
|
|
|
grpc_pollset_force_kick(watcher->pollset); |
|
|
|
grpc_pollset_force_kick(watcher->pollset); |
|
|
|
} |
|
|
|
} |
|
|
|
if (fd->read_watcher) { |
|
|
|
if (fd->read_watcher) { |
|
|
@ -322,7 +323,8 @@ gpr_uint32 grpc_fd_begin_poll(grpc_fd *fd, grpc_pollset *pollset, |
|
|
|
fd->read_watcher = watcher; |
|
|
|
fd->read_watcher = watcher; |
|
|
|
mask |= read_mask; |
|
|
|
mask |= read_mask; |
|
|
|
} |
|
|
|
} |
|
|
|
/* if there is nobody polling for write, but we need to, then start doing so */ |
|
|
|
/* if there is nobody polling for write, but we need to, then start doing so
|
|
|
|
|
|
|
|
*/ |
|
|
|
if (!fd->write_watcher && gpr_atm_acq_load(&fd->writest) > READY) { |
|
|
|
if (!fd->write_watcher && gpr_atm_acq_load(&fd->writest) > READY) { |
|
|
|
fd->write_watcher = watcher; |
|
|
|
fd->write_watcher = watcher; |
|
|
|
mask |= write_mask; |
|
|
|
mask |= write_mask; |
|
|
@ -349,13 +351,13 @@ void grpc_fd_end_poll(grpc_fd_watcher *watcher, int got_read, int got_write) { |
|
|
|
if (watcher == fd->read_watcher) { |
|
|
|
if (watcher == fd->read_watcher) { |
|
|
|
/* remove read watcher, kick if we still need a read */ |
|
|
|
/* remove read watcher, kick if we still need a read */ |
|
|
|
was_polling = 1; |
|
|
|
was_polling = 1; |
|
|
|
kick |= !got_read; |
|
|
|
kick = kick || !got_read; |
|
|
|
fd->read_watcher = NULL; |
|
|
|
fd->read_watcher = NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
if (watcher == fd->write_watcher) { |
|
|
|
if (watcher == fd->write_watcher) { |
|
|
|
/* remove write watcher, kick if we still need a write */ |
|
|
|
/* remove write watcher, kick if we still need a write */ |
|
|
|
was_polling = 1; |
|
|
|
was_polling = 1; |
|
|
|
kick |= !got_write; |
|
|
|
kick = kick || !got_write; |
|
|
|
fd->write_watcher = NULL; |
|
|
|
fd->write_watcher = NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!was_polling) { |
|
|
|
if (!was_polling) { |
|
|
|