aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Craig Tiller <craig.tiller@gmail.com>2015-06-01 08:24:35 -0700
committerGravatar Craig Tiller <craig.tiller@gmail.com>2015-06-01 08:24:35 -0700
commit5ef27545e9f36a3d0a9117b07cb371624826f18f (patch)
treead6890d2cdd825c3ad1c59c9efe6e981b40d5bac /src/core
parent9ae769724578d5eb5fba916eb92cc7e8e0e0854b (diff)
Release all fd refs before signalling shutdown
Diffstat (limited to 'src/core')
-rw-r--r--src/core/iomgr/fd_posix.h2
-rw-r--r--src/core/iomgr/pollset_multipoller_with_poll_posix.c11
-rw-r--r--src/core/iomgr/pollset_posix.c18
-rw-r--r--src/core/iomgr/pollset_posix.h1
4 files changed, 20 insertions, 12 deletions
diff --git a/src/core/iomgr/fd_posix.h b/src/core/iomgr/fd_posix.h
index eb3c959cc1..7873ce6128 100644
--- a/src/core/iomgr/fd_posix.h
+++ b/src/core/iomgr/fd_posix.h
@@ -161,8 +161,6 @@ void grpc_fd_become_readable(grpc_fd *fd, int allow_synchronous_callback);
void grpc_fd_become_writable(grpc_fd *fd, int allow_synchronous_callback);
/* Reference counting for fds */
-#define GRPC_FD_REF_COUNT_DEBUG
-
#ifdef GRPC_FD_REF_COUNT_DEBUG
void grpc_fd_ref(grpc_fd *fd, const char *reason, const char *file, int line);
void grpc_fd_unref(grpc_fd *fd, const char *reason, const char *file, int line);
diff --git a/src/core/iomgr/pollset_multipoller_with_poll_posix.c b/src/core/iomgr/pollset_multipoller_with_poll_posix.c
index 7f7d851148..afce5f65db 100644
--- a/src/core/iomgr/pollset_multipoller_with_poll_posix.c
+++ b/src/core/iomgr/pollset_multipoller_with_poll_posix.c
@@ -206,7 +206,7 @@ static void multipoll_with_poll_pollset_kick(grpc_pollset *p) {
grpc_pollset_force_kick(p);
}
-static void multipoll_with_poll_pollset_destroy(grpc_pollset *pollset) {
+static void multipoll_with_poll_pollset_finish_shutdown(grpc_pollset *pollset) {
size_t i;
pollset_hdr *h = pollset->data.ptr;
GPR_ASSERT(pollset->counter == 0);
@@ -216,6 +216,13 @@ static void multipoll_with_poll_pollset_destroy(grpc_pollset *pollset) {
for (i = 0; i < h->del_count; i++) {
GRPC_FD_UNREF(h->dels[i], "multipoller_del");
}
+ h->fd_count = 0;
+ h->del_count = 0;
+}
+
+static void multipoll_with_poll_pollset_destroy(grpc_pollset *pollset) {
+ pollset_hdr *h = pollset->data.ptr;
+ multipoll_with_poll_pollset_finish_shutdown(pollset);
gpr_free(h->pfds);
gpr_free(h->watchers);
gpr_free(h->fds);
@@ -226,7 +233,7 @@ static void multipoll_with_poll_pollset_destroy(grpc_pollset *pollset) {
static const grpc_pollset_vtable multipoll_with_poll_pollset = {
multipoll_with_poll_pollset_add_fd, multipoll_with_poll_pollset_del_fd,
multipoll_with_poll_pollset_maybe_work, multipoll_with_poll_pollset_kick,
- multipoll_with_poll_pollset_destroy};
+ multipoll_with_poll_pollset_finish_shutdown, multipoll_with_poll_pollset_destroy};
void grpc_poll_become_multipoller(grpc_pollset *pollset, grpc_fd **fds,
size_t nfds) {
diff --git a/src/core/iomgr/pollset_posix.c b/src/core/iomgr/pollset_posix.c
index 9aa481831e..96f8acfd7e 100644
--- a/src/core/iomgr/pollset_posix.c
+++ b/src/core/iomgr/pollset_posix.c
@@ -114,24 +114,25 @@ void grpc_pollset_del_fd(grpc_pollset *pollset, grpc_fd *fd) {
gpr_mu_unlock(&pollset->mu);
}
+static void finish_shutdown(grpc_pollset *pollset) {
+ pollset->vtable->finish_shutdown(pollset);
+ pollset->shutdown_done_cb(pollset->shutdown_done_arg);
+}
+
int grpc_pollset_work(grpc_pollset *pollset, gpr_timespec deadline) {
/* pollset->mu already held */
gpr_timespec now = gpr_now();
int r;
if (gpr_time_cmp(now, deadline) > 0) {
- gpr_log(GPR_DEBUG, "out of time %p", pollset);
return 0;
}
if (grpc_maybe_call_delayed_callbacks(&pollset->mu, 1)) {
- gpr_log(GPR_DEBUG, "delayed calls %p", pollset);
return 1;
}
if (grpc_alarm_check(&pollset->mu, now, &deadline)) {
- gpr_log(GPR_DEBUG, "alarms %p", pollset);
return 1;
}
if (pollset->shutting_down) {
- gpr_log(GPR_DEBUG, "shutting down %p counter=%d", pollset, pollset->counter);
return 1;
}
gpr_tls_set(&g_current_thread_poller, (gpr_intptr)pollset);
@@ -142,7 +143,7 @@ int grpc_pollset_work(grpc_pollset *pollset, gpr_timespec deadline) {
grpc_pollset_kick(pollset);
} else if (pollset->in_flight_cbs == 0) {
gpr_mu_unlock(&pollset->mu);
- pollset->shutdown_done_cb(pollset->shutdown_done_arg);
+ finish_shutdown(pollset);
/* Continuing to access pollset here is safe -- it is the caller's
* responsibility to not destroy when it has outstanding calls to
* grpc_pollset_work.
@@ -171,7 +172,7 @@ void grpc_pollset_shutdown(grpc_pollset *pollset,
gpr_mu_unlock(&pollset->mu);
if (in_flight_cbs == 0 && counter == 0) {
- shutdown_done(shutdown_done_arg);
+ finish_shutdown(pollset);
}
}
@@ -402,14 +403,15 @@ static int basic_pollset_maybe_work(grpc_pollset *pollset,
static void basic_pollset_destroy(grpc_pollset *pollset) {
GPR_ASSERT(pollset->counter == 0);
- if (pollset->data.ptr) {
+ if (pollset->data.ptr != NULL) {
GRPC_FD_UNREF(pollset->data.ptr, "basicpoll");
+ pollset->data.ptr = NULL;
}
}
static const grpc_pollset_vtable basic_pollset = {
basic_pollset_add_fd, basic_pollset_del_fd, basic_pollset_maybe_work,
- kick_using_pollset_kick, basic_pollset_destroy};
+ kick_using_pollset_kick, basic_pollset_destroy, basic_pollset_destroy};
static void become_basic_pollset(grpc_pollset *pollset, grpc_fd *fd_or_null) {
pollset->vtable = &basic_pollset;
diff --git a/src/core/iomgr/pollset_posix.h b/src/core/iomgr/pollset_posix.h
index 58c7b3ea1a..2b897caa4b 100644
--- a/src/core/iomgr/pollset_posix.h
+++ b/src/core/iomgr/pollset_posix.h
@@ -70,6 +70,7 @@ struct grpc_pollset_vtable {
int (*maybe_work)(grpc_pollset *pollset, gpr_timespec deadline,
gpr_timespec now, int allow_synchronous_callback);
void (*kick)(grpc_pollset *pollset);
+ void (*finish_shutdown)(grpc_pollset *pollset);
void (*destroy)(grpc_pollset *pollset);
};