aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lib')
-rw-r--r--src/core/lib/iomgr/pops.c42
-rw-r--r--src/core/lib/iomgr/pops.h14
-rw-r--r--src/core/lib/security/google_default_credentials.c15
-rw-r--r--src/core/lib/security/jwt_verifier.c7
-rw-r--r--src/core/lib/surface/call.c14
5 files changed, 43 insertions, 49 deletions
diff --git a/src/core/lib/iomgr/pops.c b/src/core/lib/iomgr/pops.c
index c2629f20aa..611a728b9e 100644
--- a/src/core/lib/iomgr/pops.c
+++ b/src/core/lib/iomgr/pops.c
@@ -36,50 +36,44 @@
#include "src/core/lib/iomgr/pops.h"
-struct grpc_pops {
- union {
- grpc_pollset *pollset;
- grpc_pollset_set *pollset_set;
- } pops;
- enum pops_tag { POLLSET, POLLSET_SET } tag;
-};
-
-grpc_pops *grpc_pops_create_from_pollset_set(grpc_pollset_set *pollset_set) {
- grpc_pops *pops = gpr_malloc(sizeof(grpc_pops));
- pops->pops.pollset_set = pollset_set;
- pops->tag = POLLSET_SET;
+grpc_pops grpc_pops_create_from_pollset_set(grpc_pollset_set *pollset_set) {
+ grpc_pops pops;
+ pops.pops.pollset_set = pollset_set;
+ pops.tag = POPS_POLLSET_SET;
return pops;
}
-grpc_pops *grpc_pops_create_from_pollset(grpc_pollset *pollset) {
- grpc_pops *pops = gpr_malloc(sizeof(grpc_pops));
- pops->pops.pollset = pollset;
- pops->tag = POLLSET;
+grpc_pops grpc_pops_create_from_pollset(grpc_pollset *pollset) {
+ grpc_pops pops;
+ pops.pops.pollset = pollset;
+ pops.tag = POPS_POLLSET;
return pops;
}
-void grpc_pops_destroy(grpc_pops *pops) { gpr_free(pops); }
-
grpc_pollset *grpc_pops_pollset(grpc_pops *pops) {
- if (pops->tag == POLLSET) {
+ if (pops->tag == POPS_POLLSET) {
return pops->pops.pollset;
}
return NULL;
}
grpc_pollset_set *grpc_pops_pollset_set(grpc_pops *pops) {
- if (pops->tag == POLLSET_SET) {
+ if (pops->tag == POPS_POLLSET_SET) {
return pops->pops.pollset_set;
}
return NULL;
}
+bool grpc_pops_is_empty(const grpc_pops *pops) {
+ return pops->tag == POPS_NONE;
+}
+
void grpc_pops_add_to_pollset_set(grpc_exec_ctx *exec_ctx, grpc_pops *pops,
grpc_pollset_set *pss_dst) {
- if (pops->tag == POLLSET) {
+ if (pops->tag == POPS_POLLSET) {
GPR_ASSERT(pops->pops.pollset != NULL);
grpc_pollset_set_add_pollset(exec_ctx, pss_dst, pops->pops.pollset);
- } else if (pops->tag == POLLSET_SET) {
+ } else if (pops->tag == POPS_POLLSET_SET) {
GPR_ASSERT(pops->pops.pollset_set != NULL);
grpc_pollset_set_add_pollset_set(exec_ctx, pss_dst, pops->pops.pollset_set);
} else {
@@ -90,10 +84,10 @@ void grpc_pops_add_to_pollset_set(grpc_exec_ctx *exec_ctx, grpc_pops *pops,
void grpc_pops_del_to_pollset_set(grpc_exec_ctx *exec_ctx, grpc_pops *pops,
grpc_pollset_set *pss_dst) {
- if (pops->tag == POLLSET) {
+ if (pops->tag == POPS_POLLSET) {
GPR_ASSERT(pops->pops.pollset != NULL);
grpc_pollset_set_del_pollset(exec_ctx, pss_dst, pops->pops.pollset);
- } else if (pops->tag == POLLSET_SET) {
+ } else if (pops->tag == POPS_POLLSET_SET) {
GPR_ASSERT(pops->pops.pollset_set != NULL);
grpc_pollset_set_del_pollset_set(exec_ctx, pss_dst, pops->pops.pollset_set);
} else {
diff --git a/src/core/lib/iomgr/pops.h b/src/core/lib/iomgr/pops.h
index 24ff85748b..6859427687 100644
--- a/src/core/lib/iomgr/pops.h
+++ b/src/core/lib/iomgr/pops.h
@@ -41,10 +41,16 @@
* accept a pollset XOR a pollset_set to do so through an abstract interface.
* No ownership is taken. */
-typedef struct grpc_pops grpc_pops;
+typedef struct grpc_pops {
+ union {
+ grpc_pollset *pollset;
+ grpc_pollset_set *pollset_set;
+ } pops;
+ enum pops_tag { POPS_NONE, POPS_POLLSET, POPS_POLLSET_SET } tag;
+} grpc_pops;
-grpc_pops *grpc_pops_create_from_pollset_set(grpc_pollset_set *pollset_set);
-grpc_pops *grpc_pops_create_from_pollset(grpc_pollset *pollset);
+grpc_pops grpc_pops_create_from_pollset_set(grpc_pollset_set *pollset_set);
+grpc_pops grpc_pops_create_from_pollset(grpc_pollset *pollset);
/** If \a pops contains a pollset, return it. Otherwise, return NULL */
grpc_pollset *grpc_pops_pollset(grpc_pops *pops);
@@ -52,7 +58,7 @@ grpc_pollset *grpc_pops_pollset(grpc_pops *pops);
/** If \a pops contains a pollset_set, return it. Otherwise, return NULL */
grpc_pollset_set *grpc_pops_pollset_set(grpc_pops *pops);
-void grpc_pops_destroy(grpc_pops *pops);
+bool grpc_pops_is_empty(const grpc_pops *pops);
/** Add the pollset or pollset_set in \a pops to the destination pollset_set \a
* pss_dst */
diff --git a/src/core/lib/security/google_default_credentials.c b/src/core/lib/security/google_default_credentials.c
index 29045f36eb..395a23b1a7 100644
--- a/src/core/lib/security/google_default_credentials.c
+++ b/src/core/lib/security/google_default_credentials.c
@@ -61,7 +61,7 @@ static gpr_once g_once = GPR_ONCE_INIT;
static void init_default_credentials(void) { gpr_mu_init(&g_state_mu); }
typedef struct {
- grpc_pops *pops;
+ grpc_pops pops;
int is_done;
int success;
} compute_engine_detector;
@@ -85,7 +85,7 @@ static void on_compute_engine_detection_http_response(
}
gpr_mu_lock(g_polling_mu);
detector->is_done = 1;
- grpc_pollset_kick(grpc_pops_pollset(detector->pops), NULL);
+ grpc_pollset_kick(grpc_pops_pollset(&detector->pops), NULL);
gpr_mu_unlock(g_polling_mu);
}
@@ -117,7 +117,7 @@ static int is_stack_running_on_compute_engine(void) {
grpc_httpcli_context_init(&context);
grpc_httpcli_get(
- &exec_ctx, &context, detector.pops, &request,
+ &exec_ctx, &context, &detector.pops, &request,
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), max_detection_delay),
on_compute_engine_detection_http_response, &detector);
@@ -128,7 +128,7 @@ static int is_stack_running_on_compute_engine(void) {
gpr_mu_lock(g_polling_mu);
while (!detector.is_done) {
grpc_pollset_worker *worker = NULL;
- grpc_pollset_work(&exec_ctx, grpc_pops_pollset(detector.pops), &worker,
+ grpc_pollset_work(&exec_ctx, grpc_pops_pollset(&detector.pops), &worker,
gpr_now(GPR_CLOCK_MONOTONIC),
gpr_inf_future(GPR_CLOCK_MONOTONIC));
}
@@ -136,14 +136,13 @@ static int is_stack_running_on_compute_engine(void) {
grpc_httpcli_context_destroy(&context);
grpc_closure_init(&destroy_closure, destroy_pollset,
- grpc_pops_pollset(detector.pops));
- grpc_pollset_shutdown(&exec_ctx, grpc_pops_pollset(detector.pops),
+ grpc_pops_pollset(&detector.pops));
+ grpc_pollset_shutdown(&exec_ctx, grpc_pops_pollset(&detector.pops),
&destroy_closure);
grpc_exec_ctx_finish(&exec_ctx);
g_polling_mu = NULL;
- gpr_free(grpc_pops_pollset(detector.pops));
- grpc_pops_destroy(detector.pops);
+ gpr_free(grpc_pops_pollset(&detector.pops));
return detector.success;
}
diff --git a/src/core/lib/security/jwt_verifier.c b/src/core/lib/security/jwt_verifier.c
index a5d200d7a3..1b6b7b175d 100644
--- a/src/core/lib/security/jwt_verifier.c
+++ b/src/core/lib/security/jwt_verifier.c
@@ -322,7 +322,7 @@ grpc_jwt_verifier_status grpc_jwt_claims_check(const grpc_jwt_claims *claims,
typedef struct {
grpc_jwt_verifier *verifier;
- grpc_pops *pops;
+ grpc_pops pops;
jose_header *header;
grpc_jwt_claims *claims;
char *audience;
@@ -360,7 +360,6 @@ void verifier_cb_ctx_destroy(verifier_cb_ctx *ctx) {
gpr_slice_unref(ctx->signature);
gpr_slice_unref(ctx->signed_data);
jose_header_destroy(ctx->header);
- grpc_pops_destroy(ctx->pops);
/* TODO: see what to do with claims... */
gpr_free(ctx);
}
@@ -646,7 +645,7 @@ static void on_openid_config_retrieved(grpc_exec_ctx *exec_ctx, void *user_data,
*(req.host + (req.http.path - jwks_uri)) = '\0';
}
grpc_httpcli_get(
- exec_ctx, &ctx->verifier->http_ctx, ctx->pops, &req,
+ exec_ctx, &ctx->verifier->http_ctx, &ctx->pops, &req,
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), grpc_jwt_verifier_max_delay),
on_keys_retrieved, ctx);
grpc_json_destroy(json);
@@ -749,7 +748,7 @@ static void retrieve_key_and_verify(grpc_exec_ctx *exec_ctx,
}
grpc_httpcli_get(
- exec_ctx, &ctx->verifier->http_ctx, ctx->pops, &req,
+ exec_ctx, &ctx->verifier->http_ctx, &ctx->pops, &req,
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), grpc_jwt_verifier_max_delay),
http_cb, ctx);
gpr_free(req.host);
diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c
index cd6c1585ec..c9e2d1d10f 100644
--- a/src/core/lib/surface/call.c
+++ b/src/core/lib/surface/call.c
@@ -135,7 +135,7 @@ typedef struct batch_control {
struct grpc_call {
grpc_completion_queue *cq;
- grpc_pops *pops;
+ grpc_pops pops;
grpc_channel *channel;
grpc_call *parent;
grpc_call *first_child;
@@ -292,9 +292,9 @@ grpc_call *grpc_call_create(
if (pollset_set_alternative != NULL) {
call->pops = grpc_pops_create_from_pollset_set(pollset_set_alternative);
}
- if (call->pops != NULL) {
+ if (!grpc_pops_is_empty(&call->pops)) {
grpc_call_stack_set_pollset_or_pollset_set(
- &exec_ctx, CALL_STACK_FROM_CALL(call), call->pops);
+ &exec_ctx, CALL_STACK_FROM_CALL(call), &call->pops);
}
if (parent_call != NULL) {
GRPC_CALL_INTERNAL_REF(parent_call, "child");
@@ -350,18 +350,15 @@ void grpc_call_set_completion_queue(grpc_exec_ctx *exec_ctx, grpc_call *call,
grpc_completion_queue *cq) {
GPR_ASSERT(cq);
- if (call->pops != NULL && grpc_pops_pollset_set(call->pops) != NULL) {
+ if (grpc_pops_pollset_set(&call->pops) != NULL) {
gpr_log(GPR_ERROR, "A pollset_set is already registered for this call.");
abort();
}
call->cq = cq;
GRPC_CQ_INTERNAL_REF(cq, "bind");
- if (call->pops != NULL) {
- grpc_pops_destroy(call->pops);
- }
call->pops = grpc_pops_create_from_pollset(grpc_cq_pollset(cq));
grpc_call_stack_set_pollset_or_pollset_set(
- exec_ctx, CALL_STACK_FROM_CALL(call), call->pops);
+ exec_ctx, CALL_STACK_FROM_CALL(call), &call->pops);
}
#ifdef GRPC_STREAM_REFCOUNT_DEBUG
@@ -407,7 +404,6 @@ static void destroy_call(grpc_exec_ctx *exec_ctx, void *call, bool success) {
if (c->cq) {
GRPC_CQ_INTERNAL_UNREF(c->cq, "bind");
}
- grpc_pops_destroy(c->pops);
grpc_channel *channel = c->channel;
grpc_call_stack_destroy(exec_ctx, CALL_STACK_FROM_CALL(c), c);
GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, channel, "call");