aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/util
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2016-11-09 09:42:19 -0800
committerGravatar Craig Tiller <ctiller@google.com>2016-11-09 09:42:19 -0800
commit87a7e1fd114b571abc4644d6f1cddcaff3085df4 (patch)
tree7723d0cb27fb96fc315a85a013635c824e018d59 /test/core/util
parentbd1795ca8af6ea15c83ee0556b7a24add9464f00 (diff)
parentdb096f3dba94e11bd8f78ed1ed7ff15ea585cd4f (diff)
Merge github.com:grpc/grpc into slice_with_exec_ctx
Diffstat (limited to 'test/core/util')
-rw-r--r--test/core/util/mock_endpoint.c33
-rw-r--r--test/core/util/passthru_endpoint.c20
2 files changed, 16 insertions, 37 deletions
diff --git a/test/core/util/mock_endpoint.c b/test/core/util/mock_endpoint.c
index 1d33566221..28ff0642cc 100644
--- a/test/core/util/mock_endpoint.c
+++ b/test/core/util/mock_endpoint.c
@@ -41,12 +41,11 @@
typedef struct grpc_mock_endpoint {
grpc_endpoint base;
gpr_mu mu;
- int refs;
void (*on_write)(grpc_slice slice);
grpc_slice_buffer read_buffer;
grpc_slice_buffer *on_read_out;
grpc_closure *on_read;
- grpc_resource_user resource_user;
+ grpc_resource_user *resource_user;
} grpc_mock_endpoint;
static void me_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
@@ -78,24 +77,6 @@ static void me_add_to_pollset(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
static void me_add_to_pollset_set(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
grpc_pollset_set *pollset) {}
-static void unref(grpc_exec_ctx *exec_ctx, grpc_mock_endpoint *m) {
- gpr_mu_lock(&m->mu);
- if (0 == --m->refs) {
- gpr_mu_unlock(&m->mu);
- grpc_slice_buffer_destroy_internal(exec_ctx, &m->read_buffer);
- grpc_resource_user_destroy(exec_ctx, &m->resource_user);
- gpr_free(m);
- } else {
- gpr_mu_unlock(&m->mu);
- }
-}
-
-static void me_finish_shutdown(grpc_exec_ctx *exec_ctx, void *me,
- grpc_error *error) {
- grpc_mock_endpoint *m = me;
- unref(exec_ctx, m);
-}
-
static void me_shutdown(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) {
grpc_mock_endpoint *m = (grpc_mock_endpoint *)ep;
gpr_mu_lock(&m->mu);
@@ -104,14 +85,15 @@ static void me_shutdown(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) {
GRPC_ERROR_CREATE("Endpoint Shutdown"), NULL);
m->on_read = NULL;
}
- grpc_resource_user_shutdown(exec_ctx, &m->resource_user,
- grpc_closure_create(me_finish_shutdown, m));
gpr_mu_unlock(&m->mu);
+ grpc_resource_user_shutdown(exec_ctx, m->resource_user);
}
static void me_destroy(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) {
grpc_mock_endpoint *m = (grpc_mock_endpoint *)ep;
- unref(exec_ctx, m);
+ grpc_slice_buffer_destroy(&m->read_buffer);
+ grpc_resource_user_unref(exec_ctx, m->resource_user);
+ gpr_free(m);
}
static char *me_get_peer(grpc_endpoint *ep) {
@@ -120,7 +102,7 @@ static char *me_get_peer(grpc_endpoint *ep) {
static grpc_resource_user *me_get_resource_user(grpc_endpoint *ep) {
grpc_mock_endpoint *m = (grpc_mock_endpoint *)ep;
- return &m->resource_user;
+ return m->resource_user;
}
static grpc_workqueue *me_get_workqueue(grpc_endpoint *ep) { return NULL; }
@@ -141,10 +123,9 @@ grpc_endpoint *grpc_mock_endpoint_create(void (*on_write)(grpc_slice slice),
grpc_resource_quota *resource_quota) {
grpc_mock_endpoint *m = gpr_malloc(sizeof(*m));
m->base.vtable = &vtable;
- m->refs = 2;
char *name;
gpr_asprintf(&name, "mock_endpoint_%" PRIxPTR, (intptr_t)m);
- grpc_resource_user_init(&m->resource_user, resource_quota, name);
+ m->resource_user = grpc_resource_user_create(resource_quota, name);
gpr_free(name);
grpc_slice_buffer_init(&m->read_buffer);
gpr_mu_init(&m->mu);
diff --git a/test/core/util/passthru_endpoint.c b/test/core/util/passthru_endpoint.c
index db10de87d9..62d5f1c3db 100644
--- a/test/core/util/passthru_endpoint.c
+++ b/test/core/util/passthru_endpoint.c
@@ -38,6 +38,8 @@
#include <grpc/support/alloc.h>
#include <grpc/support/string_util.h>
+#include "src/core/lib/slice/slice_internal.h"
+
typedef struct passthru_endpoint passthru_endpoint;
typedef struct {
@@ -46,7 +48,7 @@ typedef struct {
grpc_slice_buffer read_buffer;
grpc_slice_buffer *on_read_out;
grpc_closure *on_read;
- grpc_resource_user resource_user;
+ grpc_resource_user *resource_user;
} half;
struct passthru_endpoint {
@@ -123,10 +125,10 @@ static void me_shutdown(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) {
m->on_read = NULL;
}
gpr_mu_unlock(&m->parent->mu);
+ grpc_resource_user_shutdown(exec_ctx, m->resource_user);
}
-static void me_really_destroy(grpc_exec_ctx *exec_ctx, void *ep,
- grpc_error *error) {
+static void me_destroy(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) {
passthru_endpoint *p = ((half *)ep)->parent;
gpr_mu_lock(&p->mu);
if (0 == --p->halves) {
@@ -134,18 +136,14 @@ static void me_really_destroy(grpc_exec_ctx *exec_ctx, void *ep,
gpr_mu_destroy(&p->mu);
grpc_slice_buffer_destroy_internal(exec_ctx, &p->client.read_buffer);
grpc_slice_buffer_destroy_internal(exec_ctx, &p->server.read_buffer);
+ grpc_resource_user_unref(exec_ctx, p->client.resource_user);
+ grpc_resource_user_unref(exec_ctx, p->server.resource_user);
gpr_free(p);
} else {
gpr_mu_unlock(&p->mu);
}
}
-static void me_destroy(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) {
- half *m = (half *)ep;
- grpc_resource_user_shutdown(exec_ctx, &m->resource_user,
- grpc_closure_create(me_really_destroy, m));
-}
-
static char *me_get_peer(grpc_endpoint *ep) {
return gpr_strdup("fake:mock_endpoint");
}
@@ -154,7 +152,7 @@ static grpc_workqueue *me_get_workqueue(grpc_endpoint *ep) { return NULL; }
static grpc_resource_user *me_get_resource_user(grpc_endpoint *ep) {
half *m = (half *)ep;
- return &m->resource_user;
+ return m->resource_user;
}
static const grpc_endpoint_vtable vtable = {
@@ -179,7 +177,7 @@ static void half_init(half *m, passthru_endpoint *parent,
char *name;
gpr_asprintf(&name, "passthru_endpoint_%s_%" PRIxPTR, half_name,
(intptr_t)parent);
- grpc_resource_user_init(&m->resource_user, resource_quota, name);
+ m->resource_user = grpc_resource_user_create(resource_quota, name);
gpr_free(name);
}