From 143e7bf0cfcbfd60422f4e8f15e6b5c18259c8cd Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 13 Jul 2015 08:41:49 -0700 Subject: Introduce a clock type field onto gpr_timespec. Use it to validate that arithmetic on time types makes even some vague kind of sense. --- src/core/channel/client_channel.c | 4 +- src/core/iomgr/alarm.c | 4 +- src/core/iomgr/iocp_windows.c | 2 +- src/core/iomgr/iomgr.c | 7 ++- src/core/iomgr/pollset_posix.c | 2 +- src/core/iomgr/tcp_server_windows.c | 2 +- src/core/security/credentials.c | 15 ++--- src/core/security/google_default_credentials.c | 4 +- src/core/security/json_token.c | 2 +- src/core/security/jwt_verifier.c | 27 +++++---- src/core/support/sync_posix.c | 2 +- src/core/support/sync_win32.c | 2 +- src/core/support/time.c | 80 +++++++++++++++++++------- src/core/support/time_posix.c | 10 +++- src/core/surface/call.c | 6 +- src/core/surface/lame_client.c | 2 +- src/core/surface/server.c | 7 ++- src/core/transport/chttp2/incoming_metadata.c | 4 +- src/core/transport/chttp2/parsing.c | 2 +- src/core/transport/chttp2/stream_encoder.c | 3 +- src/core/transport/chttp2/timeout_encoding.c | 2 +- src/core/transport/stream_op.c | 2 +- src/core/transport/transport_op_string.c | 2 +- src/cpp/client/client_context.cc | 6 +- src/cpp/common/completion_queue.cc | 6 +- src/cpp/util/time.cc | 12 ++-- src/csharp/ext/grpc_csharp_ext.c | 7 ++- src/php/ext/grpc/call.c | 2 +- src/php/ext/grpc/completion_queue.c | 5 +- src/php/ext/grpc/server.c | 6 +- src/php/ext/grpc/timeval.c | 6 +- src/python/src/grpc/_adapter/_c/utility.c | 3 +- src/ruby/ext/grpc/rb_completion_queue.c | 4 +- src/ruby/ext/grpc/rb_grpc.c | 4 +- 34 files changed, 159 insertions(+), 95 deletions(-) (limited to 'src') diff --git a/src/core/channel/client_channel.c b/src/core/channel/client_channel.c index f890f99237..10e01ebbb4 100644 --- a/src/core/channel/client_channel.c +++ b/src/core/channel/client_channel.c @@ -132,7 +132,7 @@ static void handle_op_after_cancellation(grpc_call_element *elem, mdb.list.head = &calld->status; mdb.list.tail = &calld->details; mdb.garbage.head = mdb.garbage.tail = NULL; - mdb.deadline = gpr_inf_future; + mdb.deadline = gpr_inf_future(GPR_CLOCK_REALTIME); grpc_sopb_add_metadata(op->recv_ops, mdb); *op->recv_state = GRPC_STREAM_CLOSED; op->on_done_recv->cb(op->on_done_recv->cb_arg, 1); @@ -518,7 +518,7 @@ static void init_call_elem(grpc_call_element *elem, gpr_mu_init(&calld->mu_state); calld->elem = elem; calld->state = CALL_CREATED; - calld->deadline = gpr_inf_future; + calld->deadline = gpr_inf_future(GPR_CLOCK_REALTIME); } /* Destructor for call_data */ diff --git a/src/core/iomgr/alarm.c b/src/core/iomgr/alarm.c index 5860834de3..5b9a37e5dd 100644 --- a/src/core/iomgr/alarm.c +++ b/src/core/iomgr/alarm.c @@ -102,7 +102,8 @@ void grpc_alarm_list_init(gpr_timespec now) { void grpc_alarm_list_shutdown(void) { int i; - while (run_some_expired_alarms(NULL, gpr_inf_future, NULL, 0)) + while (run_some_expired_alarms(NULL, gpr_inf_future(GPR_CLOCK_REALTIME), NULL, + 0)) ; for (i = 0; i < NUM_SHARDS; i++) { shard_type *shard = &g_shards[i]; @@ -127,6 +128,7 @@ static gpr_timespec dbl_to_ts(double d) { gpr_timespec ts; ts.tv_sec = d; ts.tv_nsec = 1e9 * (d - ts.tv_sec); + ts.clock_type = GPR_TIMESPAN; return ts; } diff --git a/src/core/iomgr/iocp_windows.c b/src/core/iomgr/iocp_windows.c index 0c62bfccd5..ddb1834437 100644 --- a/src/core/iomgr/iocp_windows.c +++ b/src/core/iomgr/iocp_windows.c @@ -158,7 +158,7 @@ void grpc_iocp_shutdown(void) { BOOL success; gpr_event_set(&g_shutdown_iocp, (void *)1); grpc_iocp_kick(); - gpr_event_wait(&g_iocp_done, gpr_inf_future); + gpr_event_wait(&g_iocp_done, gpr_inf_future(GPR_CLOCK_REALTIME)); success = CloseHandle(g_iocp); GPR_ASSERT(success); } diff --git a/src/core/iomgr/iomgr.c b/src/core/iomgr/iomgr.c index cca92d3b32..2a90b9aced 100644 --- a/src/core/iomgr/iomgr.c +++ b/src/core/iomgr/iomgr.c @@ -57,7 +57,7 @@ static grpc_iomgr_object g_root_object; static void background_callback_executor(void *ignored) { gpr_mu_lock(&g_mu); while (!g_shutdown) { - gpr_timespec deadline = gpr_inf_future; + gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_REALTIME); gpr_timespec short_deadline = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(100)); if (g_cbs_head) { @@ -145,7 +145,7 @@ void grpc_iomgr_shutdown(void) { } while (g_cbs_head); continue; } - if (grpc_alarm_check(&g_mu, gpr_inf_future, NULL)) { + if (grpc_alarm_check(&g_mu, gpr_inf_future(GPR_CLOCK_REALTIME), NULL)) { gpr_log(GPR_DEBUG, "got late alarm"); continue; } @@ -174,7 +174,8 @@ void grpc_iomgr_shutdown(void) { gpr_mu_unlock(&g_mu); grpc_kick_poller(); - gpr_event_wait(&g_background_callback_executor_done, gpr_inf_future); + gpr_event_wait(&g_background_callback_executor_done, + gpr_inf_future(GPR_CLOCK_REALTIME)); grpc_alarm_list_shutdown(); diff --git a/src/core/iomgr/pollset_posix.c b/src/core/iomgr/pollset_posix.c index 85101764d2..e95d9d1458 100644 --- a/src/core/iomgr/pollset_posix.c +++ b/src/core/iomgr/pollset_posix.c @@ -191,7 +191,7 @@ int grpc_poll_deadline_to_millis_timeout(gpr_timespec deadline, gpr_timespec now) { gpr_timespec timeout; static const int max_spin_polling_us = 10; - if (gpr_time_cmp(deadline, gpr_inf_future) == 0) { + if (gpr_time_cmp(deadline, gpr_inf_future(GPR_CLOCK_REALTIME)) == 0) { return -1; } if (gpr_time_cmp( diff --git a/src/core/iomgr/tcp_server_windows.c b/src/core/iomgr/tcp_server_windows.c index d70968de88..19ded3e8bf 100644 --- a/src/core/iomgr/tcp_server_windows.c +++ b/src/core/iomgr/tcp_server_windows.c @@ -115,7 +115,7 @@ void grpc_tcp_server_destroy(grpc_tcp_server *s, } /* This happens asynchronously. Wait while that happens. */ while (s->active_ports) { - gpr_cv_wait(&s->cv, &s->mu, gpr_inf_future); + gpr_cv_wait(&s->cv, &s->mu, gpr_inf_future(GPR_CLOCK_REALTIME)); } gpr_mu_unlock(&s->mu); diff --git a/src/core/security/credentials.c b/src/core/security/credentials.c index 230f0dfb85..5d03b7c063 100644 --- a/src/core/security/credentials.c +++ b/src/core/security/credentials.c @@ -324,7 +324,7 @@ static void jwt_reset_cache(grpc_jwt_credentials *c) { gpr_free(c->cached.service_url); c->cached.service_url = NULL; } - c->cached.jwt_expiration = gpr_inf_past; + c->cached.jwt_expiration = gpr_inf_past(GPR_CLOCK_REALTIME); } static void jwt_destroy(grpc_credentials *creds) { @@ -347,8 +347,8 @@ static void jwt_get_request_metadata(grpc_credentials *creds, grpc_credentials_metadata_cb cb, void *user_data) { grpc_jwt_credentials *c = (grpc_jwt_credentials *)creds; - gpr_timespec refresh_threshold = {GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS, - 0}; + gpr_timespec refresh_threshold = + gpr_time_from_seconds(GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS); /* See if we can return a cached jwt. */ grpc_credentials_md_store *jwt_md = NULL; @@ -516,6 +516,7 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response( access_token->value); token_lifetime->tv_sec = strtol(expires_in->value, NULL, 10); token_lifetime->tv_nsec = 0; + token_lifetime->clock_type = GPR_TIMESPAN; if (*token_md != NULL) grpc_credentials_md_store_unref(*token_md); *token_md = grpc_credentials_md_store_create(1); grpc_credentials_md_store_add_cstrings( @@ -552,7 +553,7 @@ static void on_oauth2_token_fetcher_http_response( r->cb(r->user_data, c->access_token_md->entries, c->access_token_md->num_entries, status); } else { - c->token_expiration = gpr_inf_past; + c->token_expiration = gpr_inf_past(GPR_CLOCK_REALTIME); r->cb(r->user_data, NULL, 0, status); } gpr_mu_unlock(&c->mu); @@ -564,8 +565,8 @@ static void oauth2_token_fetcher_get_request_metadata( grpc_credentials_metadata_cb cb, void *user_data) { grpc_oauth2_token_fetcher_credentials *c = (grpc_oauth2_token_fetcher_credentials *)creds; - gpr_timespec refresh_threshold = {GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS, - 0}; + gpr_timespec refresh_threshold = + gpr_time_from_seconds(GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS); grpc_credentials_md_store *cached_access_token_md = NULL; { gpr_mu_lock(&c->mu); @@ -596,7 +597,7 @@ static void init_oauth2_token_fetcher(grpc_oauth2_token_fetcher_credentials *c, c->base.type = GRPC_CREDENTIALS_TYPE_OAUTH2; gpr_ref_init(&c->base.refcount, 1); gpr_mu_init(&c->mu); - c->token_expiration = gpr_inf_past; + c->token_expiration = gpr_inf_past(GPR_CLOCK_REALTIME); c->fetch_func = fetch_func; grpc_httpcli_context_init(&c->httpcli_context); } diff --git a/src/core/security/google_default_credentials.c b/src/core/security/google_default_credentials.c index f622deff42..43f9f62198 100644 --- a/src/core/security/google_default_credentials.c +++ b/src/core/security/google_default_credentials.c @@ -91,7 +91,7 @@ static int is_stack_running_on_compute_engine(void) { /* The http call is local. If it takes more than one sec, it is for sure not on compute engine. */ - gpr_timespec max_detection_delay = {1, 0}; + gpr_timespec max_detection_delay = gpr_time_from_seconds(1); grpc_pollset_init(&detector.pollset); detector.is_done = 0; @@ -112,7 +112,7 @@ static int is_stack_running_on_compute_engine(void) { called once for the lifetime of the process by the default credentials. */ gpr_mu_lock(GRPC_POLLSET_MU(&detector.pollset)); while (!detector.is_done) { - grpc_pollset_work(&detector.pollset, gpr_inf_future); + grpc_pollset_work(&detector.pollset, gpr_inf_future(GPR_CLOCK_REALTIME)); } gpr_mu_unlock(GRPC_POLLSET_MU(&detector.pollset)); diff --git a/src/core/security/json_token.c b/src/core/security/json_token.c index 9b1ea255ae..021912f333 100644 --- a/src/core/security/json_token.c +++ b/src/core/security/json_token.c @@ -49,7 +49,7 @@ /* --- Constants. --- */ /* 1 hour max. */ -const gpr_timespec grpc_max_auth_token_lifetime = {3600, 0}; +const gpr_timespec grpc_max_auth_token_lifetime = {3600, 0, GPR_TIMESPAN}; #define GRPC_JWT_RSA_SHA256_ALGORITHM "RS256" #define GRPC_JWT_TYPE "JWT" diff --git a/src/core/security/jwt_verifier.c b/src/core/security/jwt_verifier.c index 9140eb2ef7..1276693da7 100644 --- a/src/core/security/jwt_verifier.c +++ b/src/core/security/jwt_verifier.c @@ -109,7 +109,7 @@ static const char *validate_string_field(const grpc_json *json, static gpr_timespec validate_time_field(const grpc_json *json, const char *key) { - gpr_timespec result = gpr_time_0; + gpr_timespec result = gpr_time_0(GPR_CLOCK_REALTIME); if (json->type != GRPC_JSON_NUMBER) { gpr_log(GPR_ERROR, "Invalid %s field [%s]", key, json->value); return result; @@ -221,17 +221,17 @@ const char *grpc_jwt_claims_audience(const grpc_jwt_claims *claims) { } gpr_timespec grpc_jwt_claims_issued_at(const grpc_jwt_claims *claims) { - if (claims == NULL) return gpr_inf_past; + if (claims == NULL) return gpr_inf_past(GPR_CLOCK_REALTIME); return claims->iat; } gpr_timespec grpc_jwt_claims_expires_at(const grpc_jwt_claims *claims) { - if (claims == NULL) return gpr_inf_future; + if (claims == NULL) return gpr_inf_future(GPR_CLOCK_REALTIME); return claims->exp; } gpr_timespec grpc_jwt_claims_not_before(const grpc_jwt_claims *claims) { - if (claims == NULL) return gpr_inf_past; + if (claims == NULL) return gpr_inf_past(GPR_CLOCK_REALTIME); return claims->nbf; } @@ -242,9 +242,9 @@ grpc_jwt_claims *grpc_jwt_claims_from_json(grpc_json *json, gpr_slice buffer) { memset(claims, 0, sizeof(grpc_jwt_claims)); claims->json = json; claims->buffer = buffer; - claims->iat = gpr_inf_past; - claims->nbf = gpr_inf_past; - claims->exp = gpr_inf_future; + claims->iat = gpr_inf_past(GPR_CLOCK_REALTIME); + claims->nbf = gpr_inf_past(GPR_CLOCK_REALTIME); + claims->exp = gpr_inf_future(GPR_CLOCK_REALTIME); /* Per the spec, all fields are optional. */ for (cur = json->child; cur != NULL; cur = cur->next) { @@ -262,13 +262,16 @@ grpc_jwt_claims *grpc_jwt_claims_from_json(grpc_json *json, gpr_slice buffer) { if (claims->jti == NULL) goto error; } else if (strcmp(cur->key, "iat") == 0) { claims->iat = validate_time_field(cur, "iat"); - if (gpr_time_cmp(claims->iat, gpr_time_0) == 0) goto error; + if (gpr_time_cmp(claims->iat, gpr_time_0(GPR_CLOCK_REALTIME)) == 0) + goto error; } else if (strcmp(cur->key, "exp") == 0) { claims->exp = validate_time_field(cur, "exp"); - if (gpr_time_cmp(claims->exp, gpr_time_0) == 0) goto error; + if (gpr_time_cmp(claims->exp, gpr_time_0(GPR_CLOCK_REALTIME)) == 0) + goto error; } else if (strcmp(cur->key, "nbf") == 0) { claims->nbf = validate_time_field(cur, "nbf"); - if (gpr_time_cmp(claims->nbf, gpr_time_0) == 0) goto error; + if (gpr_time_cmp(claims->nbf, gpr_time_0(GPR_CLOCK_REALTIME)) == 0) + goto error; } } return claims; @@ -359,10 +362,10 @@ void verifier_cb_ctx_destroy(verifier_cb_ctx *ctx) { /* --- grpc_jwt_verifier object. --- */ /* Clock skew defaults to one minute. */ -gpr_timespec grpc_jwt_verifier_clock_skew = {60, 0}; +gpr_timespec grpc_jwt_verifier_clock_skew = {60, 0, GPR_TIMESPAN}; /* Max delay defaults to one minute. */ -gpr_timespec grpc_jwt_verifier_max_delay = {60, 0}; +gpr_timespec grpc_jwt_verifier_max_delay = {60, 0, GPR_TIMESPAN}; typedef struct { char *email_domain; diff --git a/src/core/support/sync_posix.c b/src/core/support/sync_posix.c index 0ccbd4923f..41af8ceb0a 100644 --- a/src/core/support/sync_posix.c +++ b/src/core/support/sync_posix.c @@ -63,7 +63,7 @@ void gpr_cv_destroy(gpr_cv *cv) { GPR_ASSERT(pthread_cond_destroy(cv) == 0); } int gpr_cv_wait(gpr_cv *cv, gpr_mu *mu, gpr_timespec abs_deadline) { int err = 0; - if (gpr_time_cmp(abs_deadline, gpr_inf_future) == 0) { + if (gpr_time_cmp(abs_deadline, gpr_inf_future(GPR_CLOCK_REALTIME)) == 0) { err = pthread_cond_wait(cv, mu); } else { struct timespec abs_deadline_ts; diff --git a/src/core/support/sync_win32.c b/src/core/support/sync_win32.c index 29b77fc4c2..63196d10d3 100644 --- a/src/core/support/sync_win32.c +++ b/src/core/support/sync_win32.c @@ -83,7 +83,7 @@ int gpr_cv_wait(gpr_cv *cv, gpr_mu *mu, gpr_timespec abs_deadline) { int timeout = 0; DWORD timeout_max_ms; mu->locked = 0; - if (gpr_time_cmp(abs_deadline, gpr_inf_future) == 0) { + if (gpr_time_cmp(abs_deadline, gpr_inf_future(GPR_CLOCK_REALTIME)) == 0) { SleepConditionVariableCS(cv, &mu->cs, INFINITE); } else { gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME); diff --git a/src/core/support/time.c b/src/core/support/time.c index d47b08b266..aee64c9778 100644 --- a/src/core/support/time.c +++ b/src/core/support/time.c @@ -41,6 +41,7 @@ int gpr_time_cmp(gpr_timespec a, gpr_timespec b) { int cmp = (a.tv_sec > b.tv_sec) - (a.tv_sec < b.tv_sec); + GPR_ASSERT(a.clock_type == b.clock_type); if (cmp == 0) { cmp = (a.tv_nsec > b.tv_nsec) - (a.tv_nsec < b.tv_nsec); } @@ -71,19 +72,40 @@ gpr_timespec gpr_time_max(gpr_timespec a, gpr_timespec b) { ((t)(TYPE_IS_SIGNED(t) ? (TOP_BIT_OF_TYPE(t) - 1) \ : ((TOP_BIT_OF_TYPE(t) - 1) << 1) + 1)) -const gpr_timespec gpr_time_0 = {0, 0}; -const gpr_timespec gpr_inf_future = {TYPE_MAX(time_t), 0}; -const gpr_timespec gpr_inf_past = {TYPE_MIN(time_t), 0}; +gpr_timespec gpr_time_0(gpr_clock_type type) { + gpr_timespec out; + out.tv_sec = 0; + out.tv_nsec = 0; + out.clock_type = type; + return out; +} + +gpr_timespec gpr_inf_future(gpr_clock_type type) { + gpr_timespec out; + out.tv_sec = TYPE_MAX(time_t); + out.tv_nsec = 0; + out.clock_type = type; + return out; +} + +gpr_timespec gpr_inf_past(gpr_clock_type type) { + gpr_timespec out; + out.tv_sec = TYPE_MIN(time_t); + out.tv_nsec = 0; + out.clock_type = type; + return out; +} /* TODO(ctiller): consider merging _nanos, _micros, _millis into a single function for maintainability. Similarly for _seconds, _minutes, and _hours */ gpr_timespec gpr_time_from_nanos(long ns) { gpr_timespec result; + result.clock_type = GPR_TIMESPAN; if (ns == LONG_MAX) { - result = gpr_inf_future; + result = gpr_inf_future(GPR_TIMESPAN); } else if (ns == LONG_MIN) { - result = gpr_inf_past; + result = gpr_inf_past(GPR_TIMESPAN); } else if (ns >= 0) { result.tv_sec = ns / GPR_NS_PER_SEC; result.tv_nsec = (int)(ns - result.tv_sec * GPR_NS_PER_SEC); @@ -97,10 +119,11 @@ gpr_timespec gpr_time_from_nanos(long ns) { gpr_timespec gpr_time_from_micros(long us) { gpr_timespec result; + result.clock_type = GPR_TIMESPAN; if (us == LONG_MAX) { - result = gpr_inf_future; + result = gpr_inf_future(GPR_TIMESPAN); } else if (us == LONG_MIN) { - result = gpr_inf_past; + result = gpr_inf_past(GPR_TIMESPAN); } else if (us >= 0) { result.tv_sec = us / 1000000; result.tv_nsec = (int)((us - result.tv_sec * 1000000) * 1000); @@ -114,10 +137,11 @@ gpr_timespec gpr_time_from_micros(long us) { gpr_timespec gpr_time_from_millis(long ms) { gpr_timespec result; + result.clock_type = GPR_TIMESPAN; if (ms == LONG_MAX) { - result = gpr_inf_future; + result = gpr_inf_future(GPR_TIMESPAN); } else if (ms == LONG_MIN) { - result = gpr_inf_past; + result = gpr_inf_past(GPR_TIMESPAN); } else if (ms >= 0) { result.tv_sec = ms / 1000; result.tv_nsec = (int)((ms - result.tv_sec * 1000) * 1000000); @@ -131,10 +155,11 @@ gpr_timespec gpr_time_from_millis(long ms) { gpr_timespec gpr_time_from_seconds(long s) { gpr_timespec result; + result.clock_type = GPR_TIMESPAN; if (s == LONG_MAX) { - result = gpr_inf_future; + result = gpr_inf_future(GPR_TIMESPAN); } else if (s == LONG_MIN) { - result = gpr_inf_past; + result = gpr_inf_past(GPR_TIMESPAN); } else { result.tv_sec = s; result.tv_nsec = 0; @@ -144,10 +169,11 @@ gpr_timespec gpr_time_from_seconds(long s) { gpr_timespec gpr_time_from_minutes(long m) { gpr_timespec result; + result.clock_type = GPR_TIMESPAN; if (m >= LONG_MAX / 60) { - result = gpr_inf_future; + result = gpr_inf_future(GPR_TIMESPAN); } else if (m <= LONG_MIN / 60) { - result = gpr_inf_past; + result = gpr_inf_past(GPR_TIMESPAN); } else { result.tv_sec = m * 60; result.tv_nsec = 0; @@ -157,10 +183,11 @@ gpr_timespec gpr_time_from_minutes(long m) { gpr_timespec gpr_time_from_hours(long h) { gpr_timespec result; + result.clock_type = GPR_TIMESPAN; if (h >= LONG_MAX / 3600) { - result = gpr_inf_future; + result = gpr_inf_future(GPR_TIMESPAN); } else if (h <= LONG_MIN / 3600) { - result = gpr_inf_past; + result = gpr_inf_past(GPR_TIMESPAN); } else { result.tv_sec = h * 3600; result.tv_nsec = 0; @@ -171,6 +198,8 @@ gpr_timespec gpr_time_from_hours(long h) { gpr_timespec gpr_time_add(gpr_timespec a, gpr_timespec b) { gpr_timespec sum; int inc = 0; + GPR_ASSERT(b.clock_type == GPR_TIMESPAN); + sum.clock_type = a.clock_type; sum.tv_nsec = a.tv_nsec + b.tv_nsec; if (sum.tv_nsec >= GPR_NS_PER_SEC) { sum.tv_nsec -= GPR_NS_PER_SEC; @@ -180,14 +209,14 @@ gpr_timespec gpr_time_add(gpr_timespec a, gpr_timespec b) { sum = a; } else if (b.tv_sec == TYPE_MAX(time_t) || (b.tv_sec >= 0 && a.tv_sec >= TYPE_MAX(time_t) - b.tv_sec)) { - sum = gpr_inf_future; + sum = gpr_inf_future(sum.clock_type); } else if (b.tv_sec == TYPE_MIN(time_t) || (b.tv_sec <= 0 && a.tv_sec <= TYPE_MIN(time_t) - b.tv_sec)) { - sum = gpr_inf_past; + sum = gpr_inf_past(sum.clock_type); } else { sum.tv_sec = a.tv_sec + b.tv_sec; if (inc != 0 && sum.tv_sec == TYPE_MAX(time_t) - 1) { - sum = gpr_inf_future; + sum = gpr_inf_future(sum.clock_type); } else { sum.tv_sec += inc; } @@ -198,6 +227,12 @@ gpr_timespec gpr_time_add(gpr_timespec a, gpr_timespec b) { gpr_timespec gpr_time_sub(gpr_timespec a, gpr_timespec b) { gpr_timespec diff; int dec = 0; + if (b.clock_type == GPR_TIMESPAN) { + diff.clock_type = a.clock_type; + } else { + GPR_ASSERT(a.clock_type == b.clock_type); + diff.clock_type = GPR_TIMESPAN; + } diff.tv_nsec = a.tv_nsec - b.tv_nsec; if (diff.tv_nsec < 0) { diff.tv_nsec += GPR_NS_PER_SEC; @@ -207,14 +242,14 @@ gpr_timespec gpr_time_sub(gpr_timespec a, gpr_timespec b) { diff = a; } else if (b.tv_sec == TYPE_MIN(time_t) || (b.tv_sec <= 0 && a.tv_sec >= TYPE_MAX(time_t) + b.tv_sec)) { - diff = gpr_inf_future; + diff = gpr_inf_future(GPR_CLOCK_REALTIME); } else if (b.tv_sec == TYPE_MAX(time_t) || (b.tv_sec >= 0 && a.tv_sec <= TYPE_MIN(time_t) + b.tv_sec)) { - diff = gpr_inf_past; + diff = gpr_inf_past(GPR_CLOCK_REALTIME); } else { diff.tv_sec = a.tv_sec - b.tv_sec; if (dec != 0 && diff.tv_sec == TYPE_MIN(time_t) + 1) { - diff = gpr_inf_past; + diff = gpr_inf_past(GPR_CLOCK_REALTIME); } else { diff.tv_sec -= dec; } @@ -225,6 +260,9 @@ gpr_timespec gpr_time_sub(gpr_timespec a, gpr_timespec b) { int gpr_time_similar(gpr_timespec a, gpr_timespec b, gpr_timespec threshold) { int cmp_ab; + GPR_ASSERT(a.clock_type == b.clock_type); + GPR_ASSERT(threshold.clock_type == GPR_TIMESPAN); + cmp_ab = gpr_time_cmp(a, b); if (cmp_ab == 0) return 1; if (cmp_ab < 0) { diff --git a/src/core/support/time_posix.c b/src/core/support/time_posix.c index f9b7958783..f28c2d7b78 100644 --- a/src/core/support/time_posix.c +++ b/src/core/support/time_posix.c @@ -38,6 +38,7 @@ #include #include #include +#include #include static struct timespec timespec_from_gpr(gpr_timespec gts) { @@ -48,10 +49,12 @@ static struct timespec timespec_from_gpr(gpr_timespec gts) { } #if _POSIX_TIMERS > 0 -static gpr_timespec gpr_from_timespec(struct timespec ts) { +static gpr_timespec gpr_from_timespec(struct timespec ts, + gpr_clock_type clock) { gpr_timespec rv; rv.tv_sec = ts.tv_sec; rv.tv_nsec = (int)ts.tv_nsec; + rv.clock_type = clock; return rv; } @@ -62,8 +65,9 @@ void gpr_time_init(void) {} gpr_timespec gpr_now(gpr_clock_type clock) { struct timespec now; + GPR_ASSERT(clock != GPR_TIMESPAN); clock_gettime(clockid_for_gpr_clock[clock], &now); - return gpr_from_timespec(now); + return gpr_from_timespec(now, clock); } #else /* For some reason Apple's OSes haven't implemented clock_gettime. */ @@ -99,6 +103,8 @@ gpr_timespec gpr_now(gpr_clock_type clock) { now.tv_sec = now_dbl * 1e-9; now.tv_nsec = now_dbl - now.tv_sec * 1e9; break; + case GPR_TIMESPAN: + abort(); } return now; diff --git a/src/core/surface/call.c b/src/core/surface/call.c index 8e6047d89c..a663577e72 100644 --- a/src/core/surface/call.c +++ b/src/core/surface/call.c @@ -329,7 +329,7 @@ grpc_call *grpc_call_create(grpc_channel *channel, grpc_completion_queue *cq, } grpc_call_stack_init(channel_stack, server_transport_data, initial_op_ptr, CALL_STACK_FROM_CALL(call)); - if (gpr_time_cmp(send_deadline, gpr_inf_future) != 0) { + if (gpr_time_cmp(send_deadline, gpr_inf_future(GPR_CLOCK_REALTIME)) != 0) { set_deadline_alarm(call, send_deadline); } return call; @@ -930,7 +930,7 @@ static int fill_send_ops(grpc_call *call, grpc_transport_stream_op *op) { mdb.list = chain_metadata_from_app(call, data.send_metadata.count, data.send_metadata.metadata); mdb.garbage.head = mdb.garbage.tail = NULL; - mdb.deadline = gpr_inf_future; + mdb.deadline = gpr_inf_future(GPR_CLOCK_REALTIME); /* send status */ /* TODO(ctiller): cache common status values */ data = call->request_data[GRPC_IOREQ_SEND_STATUS]; @@ -1283,7 +1283,7 @@ static void recv_metadata(grpc_call *call, grpc_metadata_batch *md) { l->md = 0; } } - if (gpr_time_cmp(md->deadline, gpr_inf_future) != 0) { + if (gpr_time_cmp(md->deadline, gpr_inf_future(GPR_CLOCK_REALTIME)) != 0) { set_deadline_alarm(call, md->deadline); } if (!is_trailing) { diff --git a/src/core/surface/lame_client.c b/src/core/surface/lame_client.c index 3dd56fe5a9..3f2bb5c8a9 100644 --- a/src/core/surface/lame_client.c +++ b/src/core/surface/lame_client.c @@ -72,7 +72,7 @@ static void lame_start_transport_stream_op(grpc_call_element *elem, mdb.list.head = &calld->status; mdb.list.tail = &calld->details; mdb.garbage.head = mdb.garbage.tail = NULL; - mdb.deadline = gpr_inf_future; + mdb.deadline = gpr_inf_future(GPR_CLOCK_REALTIME); grpc_sopb_add_metadata(op->recv_ops, mdb); *op->recv_state = GRPC_STREAM_CLOSED; op->on_done_recv->cb(op->on_done_recv->cb_arg, 1); diff --git a/src/core/surface/server.c b/src/core/surface/server.c index 4f868c52b6..026ba70347 100644 --- a/src/core/surface/server.c +++ b/src/core/surface/server.c @@ -549,7 +549,8 @@ static void server_on_recv(void *ptr, int success) { grpc_stream_op *op = &ops[i]; if (op->type != GRPC_OP_METADATA) continue; grpc_metadata_batch_filter(&op->data.metadata, server_filter, elem); - if (0 != gpr_time_cmp(op->data.metadata.deadline, gpr_inf_future)) { + if (0 != gpr_time_cmp(op->data.metadata.deadline, + gpr_inf_future(GPR_CLOCK_REALTIME))) { calld->deadline = op->data.metadata.deadline; } calld->got_initial_metadata = 1; @@ -623,7 +624,7 @@ static void accept_stream(void *cd, grpc_transport *transport, channel_data *chand = cd; /* create a call */ grpc_call_create(chand->channel, NULL, transport_server_data, NULL, 0, - gpr_inf_future); + gpr_inf_future(GPR_CLOCK_REALTIME)); } static void channel_connectivity_changed(void *cd, int iomgr_status_ignored) { @@ -651,7 +652,7 @@ static void init_call_elem(grpc_call_element *elem, call_data *calld = elem->call_data; channel_data *chand = elem->channel_data; memset(calld, 0, sizeof(call_data)); - calld->deadline = gpr_inf_future; + calld->deadline = gpr_inf_future(GPR_CLOCK_REALTIME); calld->call = grpc_call_from_top_element(elem); gpr_mu_init(&calld->mu_state); diff --git a/src/core/transport/chttp2/incoming_metadata.c b/src/core/transport/chttp2/incoming_metadata.c index 77162a6864..974b864ffb 100644 --- a/src/core/transport/chttp2/incoming_metadata.c +++ b/src/core/transport/chttp2/incoming_metadata.c @@ -42,7 +42,7 @@ void grpc_chttp2_incoming_metadata_buffer_init( grpc_chttp2_incoming_metadata_buffer *buffer) { - buffer->deadline = gpr_inf_future; + buffer->deadline = gpr_inf_future(GPR_CLOCK_REALTIME); } void grpc_chttp2_incoming_metadata_buffer_destroy( @@ -87,7 +87,7 @@ void grpc_chttp2_incoming_metadata_buffer_place_metadata_batch_into( b.list.tail = (void *)(gpr_intptr)buffer->count; b.garbage.head = b.garbage.tail = NULL; b.deadline = buffer->deadline; - buffer->deadline = gpr_inf_future; + buffer->deadline = gpr_inf_future(GPR_CLOCK_REALTIME); grpc_sopb_add_metadata(sopb, b); } diff --git a/src/core/transport/chttp2/parsing.c b/src/core/transport/chttp2/parsing.c index 9597395aab..14c24611ec 100644 --- a/src/core/transport/chttp2/parsing.c +++ b/src/core/transport/chttp2/parsing.c @@ -594,7 +594,7 @@ static void on_header(void *tp, grpc_mdelem *md) { cached_timeout)) { gpr_log(GPR_ERROR, "Ignoring bad timeout value '%s'", grpc_mdstr_as_c_string(md->value)); - *cached_timeout = gpr_inf_future; + *cached_timeout = gpr_inf_future(GPR_CLOCK_REALTIME); } grpc_mdelem_set_user_data(md, free_timeout, cached_timeout); } diff --git a/src/core/transport/chttp2/stream_encoder.c b/src/core/transport/chttp2/stream_encoder.c index d553d80085..d7fc2da5d3 100644 --- a/src/core/transport/chttp2/stream_encoder.c +++ b/src/core/transport/chttp2/stream_encoder.c @@ -585,7 +585,8 @@ void grpc_chttp2_encode(grpc_stream_op *ops, size_t ops_count, int eof, l->md = hpack_enc(compressor, l->md, &st); need_unref |= l->md != NULL; } - if (gpr_time_cmp(op->data.metadata.deadline, gpr_inf_future) != 0) { + if (gpr_time_cmp(op->data.metadata.deadline, + gpr_inf_future(GPR_CLOCK_REALTIME)) != 0) { deadline_enc(compressor, op->data.metadata.deadline, &st); } curop++; diff --git a/src/core/transport/chttp2/timeout_encoding.c b/src/core/transport/chttp2/timeout_encoding.c index 33915c4039..7b19712d9c 100644 --- a/src/core/transport/chttp2/timeout_encoding.c +++ b/src/core/transport/chttp2/timeout_encoding.c @@ -147,7 +147,7 @@ int grpc_chttp2_decode_timeout(const char *buffer, gpr_timespec *timeout) { gpr_uint32 xp = x * 10 + *p - '0'; have_digit = 1; if (xp < x) { - *timeout = gpr_inf_future; + *timeout = gpr_inf_future(GPR_CLOCK_REALTIME); return 1; } x = xp; diff --git a/src/core/transport/stream_op.c b/src/core/transport/stream_op.c index fdb50c6b71..71061fe0c7 100644 --- a/src/core/transport/stream_op.c +++ b/src/core/transport/stream_op.c @@ -205,7 +205,7 @@ void grpc_metadata_batch_assert_ok(grpc_metadata_batch *batch) { void grpc_metadata_batch_init(grpc_metadata_batch *batch) { batch->list.head = batch->list.tail = batch->garbage.head = batch->garbage.tail = NULL; - batch->deadline = gpr_inf_future; + batch->deadline = gpr_inf_future(GPR_CLOCK_REALTIME); } void grpc_metadata_batch_destroy(grpc_metadata_batch *batch) { diff --git a/src/core/transport/transport_op_string.c b/src/core/transport/transport_op_string.c index 0da396a320..eebba14707 100644 --- a/src/core/transport/transport_op_string.c +++ b/src/core/transport/transport_op_string.c @@ -61,7 +61,7 @@ static void put_metadata_list(gpr_strvec *b, grpc_metadata_batch md) { if (m != md.list.head) gpr_strvec_add(b, gpr_strdup(", ")); put_metadata(b, m->md); } - if (gpr_time_cmp(md.deadline, gpr_inf_future) != 0) { + if (gpr_time_cmp(md.deadline, gpr_inf_future(GPR_CLOCK_REALTIME)) != 0) { char *tmp; gpr_asprintf(&tmp, " deadline=%d.%09d", md.deadline.tv_sec, md.deadline.tv_nsec); diff --git a/src/cpp/client/client_context.cc b/src/cpp/client/client_context.cc index c68f6dd9f8..372f3e27ec 100644 --- a/src/cpp/client/client_context.cc +++ b/src/cpp/client/client_context.cc @@ -44,7 +44,7 @@ ClientContext::ClientContext() : initial_metadata_received_(false), call_(nullptr), cq_(nullptr), - deadline_(gpr_inf_future) {} + deadline_(gpr_inf_future(GPR_CLOCK_REALTIME)) {} ClientContext::~ClientContext() { if (call_) { @@ -53,8 +53,8 @@ ClientContext::~ClientContext() { if (cq_) { // Drain cq_. grpc_completion_queue_shutdown(cq_); - while (grpc_completion_queue_next(cq_, gpr_inf_future).type != - GRPC_QUEUE_SHUTDOWN) + while (grpc_completion_queue_next(cq_, gpr_inf_future(GPR_CLOCK_REALTIME)) + .type != GRPC_QUEUE_SHUTDOWN) ; grpc_completion_queue_destroy(cq_); } diff --git a/src/cpp/common/completion_queue.cc b/src/cpp/common/completion_queue.cc index b2dd1acdca..593963f672 100644 --- a/src/cpp/common/completion_queue.cc +++ b/src/cpp/common/completion_queue.cc @@ -70,7 +70,8 @@ CompletionQueue::NextStatus CompletionQueue::AsyncNextInternal( } bool CompletionQueue::Pluck(CompletionQueueTag* tag) { - auto ev = grpc_completion_queue_pluck(cq_, tag, gpr_inf_future); + auto ev = + grpc_completion_queue_pluck(cq_, tag, gpr_inf_future(GPR_CLOCK_REALTIME)); bool ok = ev.success != 0; void* ignored = tag; GPR_ASSERT(tag->FinalizeResult(&ignored, &ok)); @@ -80,7 +81,8 @@ bool CompletionQueue::Pluck(CompletionQueueTag* tag) { } void CompletionQueue::TryPluck(CompletionQueueTag* tag) { - auto ev = grpc_completion_queue_pluck(cq_, tag, gpr_time_0); + auto ev = + grpc_completion_queue_pluck(cq_, tag, gpr_time_0(GPR_CLOCK_REALTIME)); if (ev.type == GRPC_QUEUE_TIMEOUT) return; bool ok = ev.success != 0; void* ignored = tag; diff --git a/src/cpp/util/time.cc b/src/cpp/util/time.cc index fd94d00b32..99b857a428 100644 --- a/src/cpp/util/time.cc +++ b/src/cpp/util/time.cc @@ -51,8 +51,9 @@ void Timepoint2Timespec(const system_clock::time_point& from, system_clock::duration deadline = from.time_since_epoch(); seconds secs = duration_cast(deadline); if (from == system_clock::time_point::max() || - secs.count() >= gpr_inf_future.tv_sec || secs.count() < 0) { - *to = gpr_inf_future; + secs.count() >= gpr_inf_future(GPR_CLOCK_REALTIME).tv_sec || + secs.count() < 0) { + *to = gpr_inf_future(GPR_CLOCK_REALTIME); return; } nanoseconds nsecs = duration_cast(deadline - secs); @@ -65,8 +66,9 @@ void TimepointHR2Timespec(const high_resolution_clock::time_point& from, high_resolution_clock::duration deadline = from.time_since_epoch(); seconds secs = duration_cast(deadline); if (from == high_resolution_clock::time_point::max() || - secs.count() >= gpr_inf_future.tv_sec || secs.count() < 0) { - *to = gpr_inf_future; + secs.count() >= gpr_inf_future(GPR_CLOCK_REALTIME).tv_sec || + secs.count() < 0) { + *to = gpr_inf_future(GPR_CLOCK_REALTIME); return; } nanoseconds nsecs = duration_cast(deadline - secs); @@ -75,7 +77,7 @@ void TimepointHR2Timespec(const high_resolution_clock::time_point& from, } system_clock::time_point Timespec2Timepoint(gpr_timespec t) { - if (gpr_time_cmp(t, gpr_inf_future) == 0) { + if (gpr_time_cmp(t, gpr_inf_future(GPR_CLOCK_REALTIME)) == 0) { return system_clock::time_point::max(); } system_clock::time_point tp; diff --git a/src/csharp/ext/grpc_csharp_ext.c b/src/csharp/ext/grpc_csharp_ext.c index a55cc9e247..7dd1959a5f 100644 --- a/src/csharp/ext/grpc_csharp_ext.c +++ b/src/csharp/ext/grpc_csharp_ext.c @@ -302,12 +302,13 @@ grpcsharp_completion_queue_destroy(grpc_completion_queue *cq) { GPR_EXPORT grpc_event GPR_CALLTYPE grpcsharp_completion_queue_next(grpc_completion_queue *cq) { - return grpc_completion_queue_next(cq, gpr_inf_future); + return grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_REALTIME)); } GPR_EXPORT grpc_event GPR_CALLTYPE grpcsharp_completion_queue_pluck(grpc_completion_queue *cq, void *tag) { - return grpc_completion_queue_pluck(cq, tag, gpr_inf_future); + return grpc_completion_queue_pluck(cq, tag, + gpr_inf_future(GPR_CLOCK_REALTIME)); } /* Channel */ @@ -382,7 +383,7 @@ grpcsharp_channel_args_destroy(grpc_channel_args *args) { GPR_EXPORT gpr_timespec GPR_CALLTYPE gprsharp_now(void) { return gpr_now(GPR_CLOCK_REALTIME); } GPR_EXPORT gpr_timespec GPR_CALLTYPE gprsharp_inf_future(void) { - return gpr_inf_future; + return gpr_inf_future(GPR_CLOCK_REALTIME); } GPR_EXPORT gpr_int32 GPR_CALLTYPE gprsharp_sizeof_timespec(void) { diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c index 10a4946ea6..b67bae7568 100644 --- a/src/php/ext/grpc/call.c +++ b/src/php/ext/grpc/call.c @@ -408,7 +408,7 @@ PHP_METHOD(Call, startBatch) { goto cleanup; } event = grpc_completion_queue_pluck(completion_queue, call->wrapped, - gpr_inf_future); + gpr_inf_future(GPR_CLOCK_REALTIME)); if (!event.success) { zend_throw_exception(spl_ce_LogicException, "The batch failed for some reason", diff --git a/src/php/ext/grpc/completion_queue.c b/src/php/ext/grpc/completion_queue.c index b24c83757c..c653a592ef 100644 --- a/src/php/ext/grpc/completion_queue.c +++ b/src/php/ext/grpc/completion_queue.c @@ -43,8 +43,9 @@ void grpc_php_init_completion_queue(TSRMLS_D) { void grpc_php_shutdown_completion_queue(TSRMLS_D) { grpc_completion_queue_shutdown(completion_queue); - while (grpc_completion_queue_next(completion_queue, gpr_inf_future).type != - GRPC_QUEUE_SHUTDOWN) + while (grpc_completion_queue_next(completion_queue, + gpr_inf_future(GPR_CLOCK_REALTIME)) + .type != GRPC_QUEUE_SHUTDOWN) ; grpc_completion_queue_destroy(completion_queue); } diff --git a/src/php/ext/grpc/server.c b/src/php/ext/grpc/server.c index 02c886c715..c319526e42 100644 --- a/src/php/ext/grpc/server.c +++ b/src/php/ext/grpc/server.c @@ -64,7 +64,8 @@ void free_wrapped_grpc_server(void *object TSRMLS_DC) { wrapped_grpc_server *server = (wrapped_grpc_server *)object; if (server->wrapped != NULL) { grpc_server_shutdown_and_notify(server->wrapped, completion_queue, NULL); - grpc_completion_queue_pluck(completion_queue, NULL, gpr_inf_future); + grpc_completion_queue_pluck(completion_queue, NULL, + gpr_inf_future(GPR_CLOCK_REALTIME)); grpc_server_destroy(server->wrapped); } efree(server); @@ -143,7 +144,8 @@ PHP_METHOD(Server, requestCall) { (long)error_code TSRMLS_CC); goto cleanup; } - event = grpc_completion_queue_pluck(completion_queue, NULL, gpr_inf_future); + event = grpc_completion_queue_pluck(completion_queue, NULL, + gpr_inf_future(GPR_CLOCK_REALTIME)); if (!event.success) { zend_throw_exception(spl_ce_LogicException, "Failed to request a call for some reason", diff --git a/src/php/ext/grpc/timeval.c b/src/php/ext/grpc/timeval.c index ccf7f0f81a..d7530488e4 100644 --- a/src/php/ext/grpc/timeval.c +++ b/src/php/ext/grpc/timeval.c @@ -228,7 +228,8 @@ PHP_METHOD(Timeval, zero) { * @return Timeval Infinite future time value */ PHP_METHOD(Timeval, infFuture) { - zval *grpc_php_timeval_inf_future = grpc_php_wrap_timeval(gpr_inf_future); + zval *grpc_php_timeval_inf_future = + grpc_php_wrap_timeval(gpr_inf_future(GPR_CLOCK_REALTIME)); RETURN_DESTROY_ZVAL(grpc_php_timeval_inf_future); } @@ -237,7 +238,8 @@ PHP_METHOD(Timeval, infFuture) { * @return Timeval Infinite past time value */ PHP_METHOD(Timeval, infPast) { - zval *grpc_php_timeval_inf_past = grpc_php_wrap_timeval(gpr_inf_past); + zval *grpc_php_timeval_inf_past = + grpc_php_wrap_timeval(gpr_inf_past(GPR_CLOCK_REALTIME)); RETURN_DESTROY_ZVAL(grpc_php_timeval_inf_past); } diff --git a/src/python/src/grpc/_adapter/_c/utility.c b/src/python/src/grpc/_adapter/_c/utility.c index 480a720c21..b82b042268 100644 --- a/src/python/src/grpc/_adapter/_c/utility.c +++ b/src/python/src/grpc/_adapter/_c/utility.c @@ -385,7 +385,8 @@ static int pygrpc_isinf(double x) { gpr_timespec pygrpc_cast_double_to_gpr_timespec(double seconds) { gpr_timespec result; if (pygrpc_isinf(seconds)) { - result = seconds > 0.0 ? gpr_inf_future : gpr_inf_past; + result = seconds > 0.0 ? gpr_inf_future(GPR_CLOCK_REALTIME) + : gpr_inf_past(GPR_CLOCK_REALTIME); } else { result.tv_sec = (time_t)seconds; result.tv_nsec = ((seconds - result.tv_sec) * 1e9); diff --git a/src/ruby/ext/grpc/rb_completion_queue.c b/src/ruby/ext/grpc/rb_completion_queue.c index 2d52d96dc8..8a98e16308 100644 --- a/src/ruby/ext/grpc/rb_completion_queue.c +++ b/src/ruby/ext/grpc/rb_completion_queue.c @@ -82,7 +82,7 @@ static void grpc_rb_completion_queue_shutdown_drain(grpc_completion_queue *cq) { next_call.cq = cq; next_call.event.type = GRPC_QUEUE_TIMEOUT; /* TODO: the timeout should be a module level constant that defaults - * to gpr_inf_future. + * to gpr_inf_future(GPR_CLOCK_REALTIME). * * - at the moment this does not work, it stalls. Using a small timeout like * this one works, and leads to fast test run times; a longer timeout was @@ -143,7 +143,7 @@ grpc_event grpc_rb_completion_queue_pluck_event(VALUE self, VALUE tag, TypedData_Get_Struct(self, grpc_completion_queue, &grpc_rb_completion_queue_data_type, next_call.cq); if (TYPE(timeout) == T_NIL) { - next_call.timeout = gpr_inf_future; + next_call.timeout = gpr_inf_future(GPR_CLOCK_REALTIME); } else { next_call.timeout = grpc_rb_time_timeval(timeout, /* absolute time*/ 0); } diff --git a/src/ruby/ext/grpc/rb_grpc.c b/src/ruby/ext/grpc/rb_grpc.c index 699548b940..706a2a75c2 100644 --- a/src/ruby/ext/grpc/rb_grpc.c +++ b/src/ruby/ext/grpc/rb_grpc.c @@ -235,11 +235,11 @@ static void Init_grpc_time_consts() { rb_define_const( grpc_rb_mTimeConsts, "INFINITE_FUTURE", TypedData_Wrap_Struct(grpc_rb_cTimeVal, &grpc_rb_timespec_data_type, - (void *)&gpr_inf_future)); + (void *)&gpr_inf_future(GPR_CLOCK_REALTIME))); rb_define_const( grpc_rb_mTimeConsts, "INFINITE_PAST", TypedData_Wrap_Struct(grpc_rb_cTimeVal, &grpc_rb_timespec_data_type, - (void *)&gpr_inf_past)); + (void *)&gpr_inf_past(GPR_CLOCK_REALTIME))); rb_define_method(grpc_rb_cTimeVal, "to_time", grpc_rb_time_val_to_time, 0); rb_define_method(grpc_rb_cTimeVal, "inspect", grpc_rb_time_val_inspect, 0); rb_define_method(grpc_rb_cTimeVal, "to_s", grpc_rb_time_val_to_s, 0); -- cgit v1.2.3 From 354398f9f5191bb44198b94e1828eafb60de5a67 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 13 Jul 2015 09:16:03 -0700 Subject: Updating wrapped languages to new time functions --- src/cpp/util/time.cc | 2 ++ src/node/ext/completion_queue_async_worker.cc | 3 ++- src/node/ext/server.cc | 3 ++- src/node/ext/timeval.cc | 8 ++++---- src/python/src/grpc/_adapter/_c/utility.c | 1 + src/ruby/ext/grpc/rb_grpc.c | 13 ++++++++++--- test/cpp/end2end/end2end_test.cc | 5 +++-- test/cpp/end2end/thread_stress_test.cc | 2 +- test/cpp/util/time_test.cc | 9 ++++++--- 9 files changed, 31 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/cpp/util/time.cc b/src/cpp/util/time.cc index 99b857a428..a814cad452 100644 --- a/src/cpp/util/time.cc +++ b/src/cpp/util/time.cc @@ -59,6 +59,7 @@ void Timepoint2Timespec(const system_clock::time_point& from, nanoseconds nsecs = duration_cast(deadline - secs); to->tv_sec = secs.count(); to->tv_nsec = nsecs.count(); + to->clock_type = GPR_CLOCK_REALTIME; } void TimepointHR2Timespec(const high_resolution_clock::time_point& from, @@ -74,6 +75,7 @@ void TimepointHR2Timespec(const high_resolution_clock::time_point& from, nanoseconds nsecs = duration_cast(deadline - secs); to->tv_sec = secs.count(); to->tv_nsec = nsecs.count(); + to->clock_type = GPR_CLOCK_REALTIME; } system_clock::time_point Timespec2Timepoint(gpr_timespec t) { diff --git a/src/node/ext/completion_queue_async_worker.cc b/src/node/ext/completion_queue_async_worker.cc index 4be208c82d..1215c97e19 100644 --- a/src/node/ext/completion_queue_async_worker.cc +++ b/src/node/ext/completion_queue_async_worker.cc @@ -62,7 +62,8 @@ CompletionQueueAsyncWorker::CompletionQueueAsyncWorker() CompletionQueueAsyncWorker::~CompletionQueueAsyncWorker() {} void CompletionQueueAsyncWorker::Execute() { - result = grpc_completion_queue_next(queue, gpr_inf_future); + result = + grpc_completion_queue_next(queue, gpr_inf_future(GPR_CLOCK_REALTIME)); if (!result.success) { SetErrorMessage("The batch encountered an error"); } diff --git a/src/node/ext/server.cc b/src/node/ext/server.cc index 51c55ba965..34cde9ffab 100644 --- a/src/node/ext/server.cc +++ b/src/node/ext/server.cc @@ -161,7 +161,8 @@ void Server::ShutdownServer() { grpc_server_shutdown_and_notify(this->wrapped_server, this->shutdown_queue, NULL); - grpc_completion_queue_pluck(this->shutdown_queue, NULL, gpr_inf_future); + grpc_completion_queue_pluck(this->shutdown_queue, NULL, + gpr_inf_future(GPR_CLOCK_REALTIME)); this->wrapped_server = NULL; } } diff --git a/src/node/ext/timeval.cc b/src/node/ext/timeval.cc index bc3237f7a6..e3620fc91d 100644 --- a/src/node/ext/timeval.cc +++ b/src/node/ext/timeval.cc @@ -42,18 +42,18 @@ namespace node { gpr_timespec MillisecondsToTimespec(double millis) { if (millis == std::numeric_limits::infinity()) { - return gpr_inf_future; + return gpr_inf_future(GPR_CLOCK_REALTIME); } else if (millis == -std::numeric_limits::infinity()) { - return gpr_inf_past; + return gpr_inf_past(GPR_CLOCK_REALTIME); } else { return gpr_time_from_micros(static_cast(millis * 1000)); } } double TimespecToMilliseconds(gpr_timespec timespec) { - if (gpr_time_cmp(timespec, gpr_inf_future) == 0) { + if (gpr_time_cmp(timespec, gpr_inf_future(GPR_CLOCK_REALTIME)) == 0) { return std::numeric_limits::infinity(); - } else if (gpr_time_cmp(timespec, gpr_inf_past) == 0) { + } else if (gpr_time_cmp(timespec, gpr_inf_past(GPR_CLOCK_REALTIME)) == 0) { return -std::numeric_limits::infinity(); } else { return (static_cast(timespec.tv_sec) * 1000 + diff --git a/src/python/src/grpc/_adapter/_c/utility.c b/src/python/src/grpc/_adapter/_c/utility.c index b82b042268..000c8d0c38 100644 --- a/src/python/src/grpc/_adapter/_c/utility.c +++ b/src/python/src/grpc/_adapter/_c/utility.c @@ -390,6 +390,7 @@ gpr_timespec pygrpc_cast_double_to_gpr_timespec(double seconds) { } else { result.tv_sec = (time_t)seconds; result.tv_nsec = ((seconds - result.tv_sec) * 1e9); + result.clock_type = GPR_CLOCK_REALTIME; } return result; } diff --git a/src/ruby/ext/grpc/rb_grpc.c b/src/ruby/ext/grpc/rb_grpc.c index 706a2a75c2..b0ecbce091 100644 --- a/src/ruby/ext/grpc/rb_grpc.c +++ b/src/ruby/ext/grpc/rb_grpc.c @@ -222,24 +222,31 @@ static VALUE grpc_rb_time_val_to_s(VALUE self) { return rb_funcall(grpc_rb_time_val_to_time(self), id_to_s, 0); } +static gpr_timespec zero_realtime; +static gpr_timespec inf_future_realtime; +static gpr_timespec inf_past_realtime; + /* Adds a module with constants that map to gpr's static timeval structs. */ static void Init_grpc_time_consts() { VALUE grpc_rb_mTimeConsts = rb_define_module_under(grpc_rb_mGrpcCore, "TimeConsts"); grpc_rb_cTimeVal = rb_define_class_under(grpc_rb_mGrpcCore, "TimeSpec", rb_cObject); + zero_realtime = gpr_time_0(GPR_CLOCK_REALTIME); + inf_future_realtime = gpr_inf_future(GPR_CLOCK_REALTIME); + inf_past_realtime = gpr_inf_past(GPR_CLOCK_REALTIME); rb_define_const( grpc_rb_mTimeConsts, "ZERO", TypedData_Wrap_Struct(grpc_rb_cTimeVal, &grpc_rb_timespec_data_type, - (void *)&gpr_time_0)); + (void *)&zero_realtime)); rb_define_const( grpc_rb_mTimeConsts, "INFINITE_FUTURE", TypedData_Wrap_Struct(grpc_rb_cTimeVal, &grpc_rb_timespec_data_type, - (void *)&gpr_inf_future(GPR_CLOCK_REALTIME))); + (void *)&inf_future_realtime)); rb_define_const( grpc_rb_mTimeConsts, "INFINITE_PAST", TypedData_Wrap_Struct(grpc_rb_cTimeVal, &grpc_rb_timespec_data_type, - (void *)&gpr_inf_past(GPR_CLOCK_REALTIME))); + (void *)&inf_past_realtime)); rb_define_method(grpc_rb_cTimeVal, "to_time", grpc_rb_time_val_to_time, 0); rb_define_method(grpc_rb_cTimeVal, "inspect", grpc_rb_time_val_inspect, 0); rb_define_method(grpc_rb_cTimeVal, "to_s", grpc_rb_time_val_to_s, 0); diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index f0d9f75214..403fffed5c 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -75,7 +75,7 @@ const char* kServerCancelAfterReads = "cancel_after_reads"; void MaybeEchoDeadline(ServerContext* context, const EchoRequest* request, EchoResponse* response) { if (request->has_param() && request->param().echo_deadline()) { - gpr_timespec deadline = gpr_inf_future; + gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_REALTIME); if (context->deadline() != system_clock::time_point::max()) { Timepoint2Timespec(context->deadline(), &deadline); } @@ -373,7 +373,8 @@ TEST_F(End2endTest, EchoDeadlineForNoDeadlineRpc) { Status s = stub_->Echo(&context, request, &response); EXPECT_EQ(response.message(), request.message()); EXPECT_TRUE(s.ok()); - EXPECT_EQ(response.param().request_deadline(), gpr_inf_future.tv_sec); + EXPECT_EQ(response.param().request_deadline(), + gpr_inf_future(GPR_CLOCK_REALTIME).tv_sec); } TEST_F(End2endTest, UnimplementedRpc) { diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc index 0b4d942566..cae34455b9 100644 --- a/test/cpp/end2end/thread_stress_test.cc +++ b/test/cpp/end2end/thread_stress_test.cc @@ -71,7 +71,7 @@ namespace { void MaybeEchoDeadline(ServerContext* context, const EchoRequest* request, EchoResponse* response) { if (request->has_param() && request->param().echo_deadline()) { - gpr_timespec deadline = gpr_inf_future; + gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_REALTIME); if (context->deadline() != system_clock::time_point::max()) { Timepoint2Timespec(context->deadline(), &deadline); } diff --git a/test/cpp/util/time_test.cc b/test/cpp/util/time_test.cc index a3cfb1c961..1770a80574 100644 --- a/test/cpp/util/time_test.cc +++ b/test/cpp/util/time_test.cc @@ -47,6 +47,7 @@ class TimeTest : public ::testing::Test {}; TEST_F(TimeTest, AbsolutePointTest) { long us = 10000000L; gpr_timespec ts = gpr_time_from_micros(us); + ts.clock_type = GPR_CLOCK_REALTIME; system_clock::time_point tp{microseconds(us)}; system_clock::time_point tp_converted = Timespec2Timepoint(ts); gpr_timespec ts_converted; @@ -61,15 +62,17 @@ TEST_F(TimeTest, AbsolutePointTest) { // gpr_inf_future is treated specially and mapped to/from time_point::max() TEST_F(TimeTest, InfFuture) { EXPECT_EQ(system_clock::time_point::max(), - Timespec2Timepoint(gpr_inf_future)); + Timespec2Timepoint(gpr_inf_future(GPR_CLOCK_REALTIME))); gpr_timespec from_time_point_max; Timepoint2Timespec(system_clock::time_point::max(), &from_time_point_max); - EXPECT_EQ(0, gpr_time_cmp(gpr_inf_future, from_time_point_max)); + EXPECT_EQ( + 0, gpr_time_cmp(gpr_inf_future(GPR_CLOCK_REALTIME), from_time_point_max)); // This will cause an overflow Timepoint2Timespec( std::chrono::time_point::max(), &from_time_point_max); - EXPECT_EQ(0, gpr_time_cmp(gpr_inf_future, from_time_point_max)); + EXPECT_EQ( + 0, gpr_time_cmp(gpr_inf_future(GPR_CLOCK_REALTIME), from_time_point_max)); } } // namespace -- cgit v1.2.3 From 58bbc864badff97950bb68a64ce3ade8662bec5d Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 13 Jul 2015 09:51:17 -0700 Subject: Updating wrapped languages to new time functions --- include/grpc/support/time.h | 12 ++-- src/core/client_config/subchannel.c | 2 +- src/core/iomgr/iomgr.c | 14 ++--- src/core/iomgr/pollset_posix.c | 10 ++-- src/core/security/credentials.c | 8 +-- src/core/security/google_default_credentials.c | 2 +- src/core/support/cancellable.c | 5 +- src/core/support/time.c | 48 +++++++-------- src/core/surface/completion_queue.c | 5 +- src/core/surface/server.c | 6 +- src/core/transport/chttp2/timeout_encoding.c | 12 ++-- src/node/ext/timeval.cc | 3 +- src/php/ext/grpc/timeval.c | 5 +- src/ruby/ext/grpc/rb_completion_queue.c | 3 +- test/core/end2end/cq_verifier.c | 4 +- test/core/fling/server.c | 2 +- test/core/httpcli/httpcli_test.c | 4 +- test/core/iomgr/alarm_list_test.c | 36 +++++++----- test/core/iomgr/tcp_client_posix_test.c | 6 +- test/core/statistics/census_log_tests.c | 3 +- test/core/support/cancellable_test.c | 45 ++++++++------ test/core/support/sync_test.c | 19 +++--- test/core/support/time_test.c | 62 ++++++++++---------- test/core/transport/chttp2/timeout_encoding_test.c | 68 +++++++++++----------- test/core/util/test_config.h | 14 +++-- 25 files changed, 214 insertions(+), 184 deletions(-) (limited to 'src') diff --git a/include/grpc/support/time.h b/include/grpc/support/time.h index dbf2548d1b..2a93377202 100644 --- a/include/grpc/support/time.h +++ b/include/grpc/support/time.h @@ -94,12 +94,12 @@ gpr_timespec gpr_time_sub(gpr_timespec a, gpr_timespec b); /* Return a timespec representing a given number of time units. LONG_MIN is interpreted as gpr_inf_past, and LONG_MAX as gpr_inf_future. */ -gpr_timespec gpr_time_from_micros(long x); -gpr_timespec gpr_time_from_nanos(long x); -gpr_timespec gpr_time_from_millis(long x); -gpr_timespec gpr_time_from_seconds(long x); -gpr_timespec gpr_time_from_minutes(long x); -gpr_timespec gpr_time_from_hours(long x); +gpr_timespec gpr_time_from_micros(long x, gpr_clock_type clock_type); +gpr_timespec gpr_time_from_nanos(long x, gpr_clock_type clock_type); +gpr_timespec gpr_time_from_millis(long x, gpr_clock_type clock_type); +gpr_timespec gpr_time_from_seconds(long x, gpr_clock_type clock_type); +gpr_timespec gpr_time_from_minutes(long x, gpr_clock_type clock_type); +gpr_timespec gpr_time_from_hours(long x, gpr_clock_type clock_type); gpr_int32 gpr_time_to_millis(gpr_timespec timespec); diff --git a/src/core/client_config/subchannel.c b/src/core/client_config/subchannel.c index 8cdad1015f..35f172683a 100644 --- a/src/core/client_config/subchannel.c +++ b/src/core/client_config/subchannel.c @@ -302,7 +302,7 @@ static void continue_connect(grpc_subchannel *c) { static void start_connect(grpc_subchannel *c) { gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME); c->next_attempt = now; - c->backoff_delta = gpr_time_from_seconds(1); + c->backoff_delta = gpr_time_from_seconds(1, GPR_TIMESPAN); continue_connect(c); } diff --git a/src/core/iomgr/iomgr.c b/src/core/iomgr/iomgr.c index 2a90b9aced..0244f689b1 100644 --- a/src/core/iomgr/iomgr.c +++ b/src/core/iomgr/iomgr.c @@ -58,8 +58,8 @@ static void background_callback_executor(void *ignored) { gpr_mu_lock(&g_mu); while (!g_shutdown) { gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_REALTIME); - gpr_timespec short_deadline = - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(100)); + gpr_timespec short_deadline = gpr_time_add( + gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(100, GPR_TIMESPAN)); if (g_cbs_head) { grpc_iomgr_closure *closure = g_cbs_head; g_cbs_head = closure->next; @@ -110,8 +110,8 @@ static size_t count_objects(void) { void grpc_iomgr_shutdown(void) { grpc_iomgr_object *obj; grpc_iomgr_closure *closure; - gpr_timespec shutdown_deadline = - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(10)); + gpr_timespec shutdown_deadline = gpr_time_add( + gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(10, GPR_TIMESPAN)); gpr_timespec last_warning_time = gpr_now(GPR_CLOCK_REALTIME); gpr_mu_lock(&g_mu); @@ -119,7 +119,7 @@ void grpc_iomgr_shutdown(void) { while (g_cbs_head != NULL || g_root_object.next != &g_root_object) { if (gpr_time_cmp( gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), last_warning_time), - gpr_time_from_seconds(1)) >= 0) { + gpr_time_from_seconds(1, GPR_TIMESPAN)) >= 0) { if (g_cbs_head != NULL && g_root_object.next != &g_root_object) { gpr_log(GPR_DEBUG, "Waiting for %d iomgr objects to be destroyed and executing " @@ -151,8 +151,8 @@ void grpc_iomgr_shutdown(void) { } if (g_root_object.next != &g_root_object) { int timeout = 0; - gpr_timespec short_deadline = - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(100)); + gpr_timespec short_deadline = gpr_time_add( + gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis(100, GPR_TIMESPAN)); while (gpr_cv_wait(&g_rcv, &g_mu, short_deadline) && g_cbs_head == NULL) { if (gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), shutdown_deadline) > 0) { timeout = 1; diff --git a/src/core/iomgr/pollset_posix.c b/src/core/iomgr/pollset_posix.c index e95d9d1458..7afff58eee 100644 --- a/src/core/iomgr/pollset_posix.c +++ b/src/core/iomgr/pollset_posix.c @@ -194,14 +194,14 @@ int grpc_poll_deadline_to_millis_timeout(gpr_timespec deadline, if (gpr_time_cmp(deadline, gpr_inf_future(GPR_CLOCK_REALTIME)) == 0) { return -1; } - if (gpr_time_cmp( - deadline, - gpr_time_add(now, gpr_time_from_micros(max_spin_polling_us))) <= 0) { + if (gpr_time_cmp(deadline, gpr_time_add(now, gpr_time_from_micros( + max_spin_polling_us, + GPR_TIMESPAN))) <= 0) { return 0; } timeout = gpr_time_sub(deadline, now); - return gpr_time_to_millis( - gpr_time_add(timeout, gpr_time_from_nanos(GPR_NS_PER_SEC - 1))); + return gpr_time_to_millis(gpr_time_add( + timeout, gpr_time_from_nanos(GPR_NS_PER_SEC - 1, GPR_TIMESPAN))); } /* diff --git a/src/core/security/credentials.c b/src/core/security/credentials.c index 5d03b7c063..fb59fa4b0e 100644 --- a/src/core/security/credentials.c +++ b/src/core/security/credentials.c @@ -347,8 +347,8 @@ static void jwt_get_request_metadata(grpc_credentials *creds, grpc_credentials_metadata_cb cb, void *user_data) { grpc_jwt_credentials *c = (grpc_jwt_credentials *)creds; - gpr_timespec refresh_threshold = - gpr_time_from_seconds(GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS); + gpr_timespec refresh_threshold = gpr_time_from_seconds( + GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS, GPR_TIMESPAN); /* See if we can return a cached jwt. */ grpc_credentials_md_store *jwt_md = NULL; @@ -565,8 +565,8 @@ static void oauth2_token_fetcher_get_request_metadata( grpc_credentials_metadata_cb cb, void *user_data) { grpc_oauth2_token_fetcher_credentials *c = (grpc_oauth2_token_fetcher_credentials *)creds; - gpr_timespec refresh_threshold = - gpr_time_from_seconds(GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS); + gpr_timespec refresh_threshold = gpr_time_from_seconds( + GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS, GPR_TIMESPAN); grpc_credentials_md_store *cached_access_token_md = NULL; { gpr_mu_lock(&c->mu); diff --git a/src/core/security/google_default_credentials.c b/src/core/security/google_default_credentials.c index 43f9f62198..833484310f 100644 --- a/src/core/security/google_default_credentials.c +++ b/src/core/security/google_default_credentials.c @@ -91,7 +91,7 @@ static int is_stack_running_on_compute_engine(void) { /* The http call is local. If it takes more than one sec, it is for sure not on compute engine. */ - gpr_timespec max_detection_delay = gpr_time_from_seconds(1); + gpr_timespec max_detection_delay = gpr_time_from_seconds(1, GPR_TIMESPAN); grpc_pollset_init(&detector.pollset); detector.is_done = 0; diff --git a/src/core/support/cancellable.c b/src/core/support/cancellable.c index 3cbb318ab6..4756f1e125 100644 --- a/src/core/support/cancellable.c +++ b/src/core/support/cancellable.c @@ -121,8 +121,9 @@ void gpr_cancellable_cancel(gpr_cancellable *c) { } else { gpr_event ev; gpr_event_init(&ev); - gpr_event_wait(&ev, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_micros(1000))); + gpr_event_wait( + &ev, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(1000, GPR_TIMESPAN))); } } } while (failures != 0); diff --git a/src/core/support/time.c b/src/core/support/time.c index aee64c9778..570f195bd1 100644 --- a/src/core/support/time.c +++ b/src/core/support/time.c @@ -99,13 +99,13 @@ gpr_timespec gpr_inf_past(gpr_clock_type type) { /* TODO(ctiller): consider merging _nanos, _micros, _millis into a single function for maintainability. Similarly for _seconds, _minutes, and _hours */ -gpr_timespec gpr_time_from_nanos(long ns) { +gpr_timespec gpr_time_from_nanos(long ns, gpr_clock_type type) { gpr_timespec result; - result.clock_type = GPR_TIMESPAN; + result.clock_type = type; if (ns == LONG_MAX) { - result = gpr_inf_future(GPR_TIMESPAN); + result = gpr_inf_future(type); } else if (ns == LONG_MIN) { - result = gpr_inf_past(GPR_TIMESPAN); + result = gpr_inf_past(type); } else if (ns >= 0) { result.tv_sec = ns / GPR_NS_PER_SEC; result.tv_nsec = (int)(ns - result.tv_sec * GPR_NS_PER_SEC); @@ -117,13 +117,13 @@ gpr_timespec gpr_time_from_nanos(long ns) { return result; } -gpr_timespec gpr_time_from_micros(long us) { +gpr_timespec gpr_time_from_micros(long us, gpr_clock_type type) { gpr_timespec result; - result.clock_type = GPR_TIMESPAN; + result.clock_type = type; if (us == LONG_MAX) { - result = gpr_inf_future(GPR_TIMESPAN); + result = gpr_inf_future(type); } else if (us == LONG_MIN) { - result = gpr_inf_past(GPR_TIMESPAN); + result = gpr_inf_past(type); } else if (us >= 0) { result.tv_sec = us / 1000000; result.tv_nsec = (int)((us - result.tv_sec * 1000000) * 1000); @@ -135,13 +135,13 @@ gpr_timespec gpr_time_from_micros(long us) { return result; } -gpr_timespec gpr_time_from_millis(long ms) { +gpr_timespec gpr_time_from_millis(long ms, gpr_clock_type type) { gpr_timespec result; - result.clock_type = GPR_TIMESPAN; + result.clock_type = type; if (ms == LONG_MAX) { - result = gpr_inf_future(GPR_TIMESPAN); + result = gpr_inf_future(type); } else if (ms == LONG_MIN) { - result = gpr_inf_past(GPR_TIMESPAN); + result = gpr_inf_past(type); } else if (ms >= 0) { result.tv_sec = ms / 1000; result.tv_nsec = (int)((ms - result.tv_sec * 1000) * 1000000); @@ -153,13 +153,13 @@ gpr_timespec gpr_time_from_millis(long ms) { return result; } -gpr_timespec gpr_time_from_seconds(long s) { +gpr_timespec gpr_time_from_seconds(long s, gpr_clock_type type) { gpr_timespec result; - result.clock_type = GPR_TIMESPAN; + result.clock_type = type; if (s == LONG_MAX) { - result = gpr_inf_future(GPR_TIMESPAN); + result = gpr_inf_future(type); } else if (s == LONG_MIN) { - result = gpr_inf_past(GPR_TIMESPAN); + result = gpr_inf_past(type); } else { result.tv_sec = s; result.tv_nsec = 0; @@ -167,13 +167,13 @@ gpr_timespec gpr_time_from_seconds(long s) { return result; } -gpr_timespec gpr_time_from_minutes(long m) { +gpr_timespec gpr_time_from_minutes(long m, gpr_clock_type type) { gpr_timespec result; - result.clock_type = GPR_TIMESPAN; + result.clock_type = type; if (m >= LONG_MAX / 60) { - result = gpr_inf_future(GPR_TIMESPAN); + result = gpr_inf_future(type); } else if (m <= LONG_MIN / 60) { - result = gpr_inf_past(GPR_TIMESPAN); + result = gpr_inf_past(type); } else { result.tv_sec = m * 60; result.tv_nsec = 0; @@ -181,13 +181,13 @@ gpr_timespec gpr_time_from_minutes(long m) { return result; } -gpr_timespec gpr_time_from_hours(long h) { +gpr_timespec gpr_time_from_hours(long h, gpr_clock_type type) { gpr_timespec result; - result.clock_type = GPR_TIMESPAN; + result.clock_type = type; if (h >= LONG_MAX / 3600) { - result = gpr_inf_future(GPR_TIMESPAN); + result = gpr_inf_future(type); } else if (h <= LONG_MIN / 3600) { - result = gpr_inf_past(GPR_TIMESPAN); + result = gpr_inf_past(type); } else { result.tv_sec = h * 3600; result.tv_nsec = 0; diff --git a/src/core/surface/completion_queue.c b/src/core/surface/completion_queue.c index c67f75fc5c..7f135d4bdd 100644 --- a/src/core/surface/completion_queue.c +++ b/src/core/surface/completion_queue.c @@ -260,8 +260,9 @@ grpc_pollset *grpc_cq_pollset(grpc_completion_queue *cc) { void grpc_cq_hack_spin_pollset(grpc_completion_queue *cc) { gpr_mu_lock(GRPC_POLLSET_MU(&cc->pollset)); grpc_pollset_kick(&cc->pollset); - grpc_pollset_work(&cc->pollset, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_millis(100))); + grpc_pollset_work(&cc->pollset, + gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_millis(100, GPR_TIMESPAN))); gpr_mu_unlock(GRPC_POLLSET_MU(&cc->pollset)); } diff --git a/src/core/surface/server.c b/src/core/surface/server.c index 650b8b86fe..37f0c3c005 100644 --- a/src/core/surface/server.c +++ b/src/core/surface/server.c @@ -487,9 +487,9 @@ static void maybe_finish_shutdown(grpc_server *server) { if (server->root_channel_data.next != &server->root_channel_data || server->listeners_destroyed < num_listeners(server)) { - if (gpr_time_cmp( - gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), server->last_shutdown_message_time), - gpr_time_from_seconds(1)) >= 0) { + if (gpr_time_cmp(gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), + server->last_shutdown_message_time), + gpr_time_from_seconds(1, GPR_TIMESPAN)) >= 0) { server->last_shutdown_message_time = gpr_now(GPR_CLOCK_REALTIME); gpr_log(GPR_DEBUG, "Waiting for %d channels and %d/%d listeners to be destroyed" diff --git a/src/core/transport/chttp2/timeout_encoding.c b/src/core/transport/chttp2/timeout_encoding.c index 7b19712d9c..1dd768ada4 100644 --- a/src/core/transport/chttp2/timeout_encoding.c +++ b/src/core/transport/chttp2/timeout_encoding.c @@ -159,22 +159,22 @@ int grpc_chttp2_decode_timeout(const char *buffer, gpr_timespec *timeout) { /* decode unit specifier */ switch (*p) { case 'n': - *timeout = gpr_time_from_nanos(x); + *timeout = gpr_time_from_nanos(x, GPR_TIMESPAN); break; case 'u': - *timeout = gpr_time_from_micros(x); + *timeout = gpr_time_from_micros(x, GPR_TIMESPAN); break; case 'm': - *timeout = gpr_time_from_millis(x); + *timeout = gpr_time_from_millis(x, GPR_TIMESPAN); break; case 'S': - *timeout = gpr_time_from_seconds(x); + *timeout = gpr_time_from_seconds(x, GPR_TIMESPAN); break; case 'M': - *timeout = gpr_time_from_minutes(x); + *timeout = gpr_time_from_minutes(x, GPR_TIMESPAN); break; case 'H': - *timeout = gpr_time_from_hours(x); + *timeout = gpr_time_from_hours(x, GPR_TIMESPAN); break; default: return 0; diff --git a/src/node/ext/timeval.cc b/src/node/ext/timeval.cc index e3620fc91d..60de4d816d 100644 --- a/src/node/ext/timeval.cc +++ b/src/node/ext/timeval.cc @@ -46,7 +46,8 @@ gpr_timespec MillisecondsToTimespec(double millis) { } else if (millis == -std::numeric_limits::infinity()) { return gpr_inf_past(GPR_CLOCK_REALTIME); } else { - return gpr_time_from_micros(static_cast(millis * 1000)); + return gpr_time_from_micros(static_cast(millis * 1000), + GPR_CLOCK_REALTIME); } } diff --git a/src/php/ext/grpc/timeval.c b/src/php/ext/grpc/timeval.c index d7530488e4..4fd069e19a 100644 --- a/src/php/ext/grpc/timeval.c +++ b/src/php/ext/grpc/timeval.c @@ -98,7 +98,7 @@ PHP_METHOD(Timeval, __construct) { "Timeval expects a long", 1 TSRMLS_CC); return; } - gpr_timespec time = gpr_time_from_micros(microseconds); + gpr_timespec time = gpr_time_from_micros(microseconds, GPR_TIMESPAN); memcpy(&timeval->wrapped, &time, sizeof(gpr_timespec)); } @@ -217,7 +217,8 @@ PHP_METHOD(Timeval, now) { * @return Timeval Zero length time interval */ PHP_METHOD(Timeval, zero) { - zval *grpc_php_timeval_zero = grpc_php_wrap_timeval(gpr_time_0); + zval *grpc_php_timeval_zero = + grpc_php_wrap_timeval(gpr_time_0(GPR_CLOCK_REALTIME)); RETURN_ZVAL(grpc_php_timeval_zero, false, /* Copy original before returning? */ true /* Destroy original before returning */); diff --git a/src/ruby/ext/grpc/rb_completion_queue.c b/src/ruby/ext/grpc/rb_completion_queue.c index 8a98e16308..f89439f4c1 100644 --- a/src/ruby/ext/grpc/rb_completion_queue.c +++ b/src/ruby/ext/grpc/rb_completion_queue.c @@ -91,7 +91,8 @@ static void grpc_rb_completion_queue_shutdown_drain(grpc_completion_queue *cq) { * - investigate further, this is probably another example of C-level cleanup * not working consistently in all cases. */ - next_call.timeout = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(5e3)); + next_call.timeout = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(5e3, GPR_TIMESPAN)); do { rb_thread_call_without_gvl(grpc_rb_completion_queue_next_no_gil, (void *)&next_call, NULL, NULL); diff --git a/test/core/end2end/cq_verifier.c b/test/core/end2end/cq_verifier.c index 407c72b519..81e158e969 100644 --- a/test/core/end2end/cq_verifier.c +++ b/test/core/end2end/cq_verifier.c @@ -248,8 +248,8 @@ void cq_verify(cq_verifier *v) { } void cq_verify_empty(cq_verifier *v) { - gpr_timespec deadline = - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(1)); + gpr_timespec deadline = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_seconds(1, GPR_TIMESPAN)); grpc_event ev; GPR_ASSERT(v->expect.next == &v->expect && "expectation queue must be empty"); diff --git a/test/core/fling/server.c b/test/core/fling/server.c index 468013c3ec..082bbd368a 100644 --- a/test/core/fling/server.c +++ b/test/core/fling/server.c @@ -242,7 +242,7 @@ int main(int argc, char **argv) { } ev = grpc_completion_queue_next( cq, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_micros(1000000))); + gpr_time_from_micros(1000000, GPR_TIMESPAN))); s = ev.tag; switch (ev.type) { case GRPC_OP_COMPLETE: diff --git a/test/core/httpcli/httpcli_test.c b/test/core/httpcli/httpcli_test.c index ca0b2d1519..4801eb3e39 100644 --- a/test/core/httpcli/httpcli_test.c +++ b/test/core/httpcli/httpcli_test.c @@ -145,8 +145,8 @@ int main(int argc, char **argv) { gpr_free(args[0]); gpr_free(args[2]); - gpr_sleep_until( - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(5))); + gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_seconds(5, GPR_TIMESPAN))); grpc_test_init(argc, argv); grpc_init(); diff --git a/test/core/iomgr/alarm_list_test.c b/test/core/iomgr/alarm_list_test.c index 2d7cf6c3ec..56d662e61a 100644 --- a/test/core/iomgr/alarm_list_test.c +++ b/test/core/iomgr/alarm_list_test.c @@ -60,45 +60,51 @@ static void add_test(void) { /* 10 ms alarms. will expire in the current epoch */ for (i = 0; i < 10; i++) { - grpc_alarm_init(&alarms[i], gpr_time_add(start, gpr_time_from_millis(10)), + grpc_alarm_init(&alarms[i], + gpr_time_add(start, gpr_time_from_millis(10, GPR_TIMESPAN)), cb, (void *)(gpr_intptr)i, start); } /* 1010 ms alarms. will expire in the next epoch */ for (i = 10; i < 20; i++) { - grpc_alarm_init(&alarms[i], gpr_time_add(start, gpr_time_from_millis(1010)), + grpc_alarm_init(&alarms[i], gpr_time_add(start, gpr_time_from_millis( + 1010, GPR_TIMESPAN)), cb, (void *)(gpr_intptr)i, start); } /* collect alarms. Only the first batch should be ready. */ - GPR_ASSERT(10 == - grpc_alarm_check( - NULL, gpr_time_add(start, gpr_time_from_millis(500)), NULL)); + GPR_ASSERT(10 == grpc_alarm_check(NULL, + gpr_time_add(start, gpr_time_from_millis( + 500, GPR_TIMESPAN)), + NULL)); for (i = 0; i < 20; i++) { GPR_ASSERT(cb_called[i][1] == (i < 10)); GPR_ASSERT(cb_called[i][0] == 0); } - GPR_ASSERT(0 == - grpc_alarm_check( - NULL, gpr_time_add(start, gpr_time_from_millis(600)), NULL)); + GPR_ASSERT(0 == grpc_alarm_check( + NULL, gpr_time_add( + start, gpr_time_from_millis(600, GPR_TIMESPAN)), + NULL)); for (i = 0; i < 30; i++) { GPR_ASSERT(cb_called[i][1] == (i < 10)); GPR_ASSERT(cb_called[i][0] == 0); } /* collect the rest of the alarms */ - GPR_ASSERT(10 == - grpc_alarm_check( - NULL, gpr_time_add(start, gpr_time_from_millis(1500)), NULL)); + GPR_ASSERT( + 10 == grpc_alarm_check(NULL, gpr_time_add(start, gpr_time_from_millis( + 1500, GPR_TIMESPAN)), + NULL)); for (i = 0; i < 30; i++) { GPR_ASSERT(cb_called[i][1] == (i < 20)); GPR_ASSERT(cb_called[i][0] == 0); } - GPR_ASSERT(0 == - grpc_alarm_check( - NULL, gpr_time_add(start, gpr_time_from_millis(1600)), NULL)); + GPR_ASSERT(0 == grpc_alarm_check(NULL, + gpr_time_add(start, gpr_time_from_millis( + 1600, GPR_TIMESPAN)), + NULL)); for (i = 0; i < 30; i++) { GPR_ASSERT(cb_called[i][1] == (i < 20)); GPR_ASSERT(cb_called[i][0] == 0); @@ -108,7 +114,7 @@ static void add_test(void) { } static gpr_timespec tfm(int m) { - gpr_timespec t = gpr_time_from_millis(m); + gpr_timespec t = gpr_time_from_millis(m, GPR_TIMESPAN); t.clock_type = GPR_CLOCK_REALTIME; return t; } diff --git a/test/core/iomgr/tcp_client_posix_test.c b/test/core/iomgr/tcp_client_posix_test.c index 36b1d6c939..f08230902e 100644 --- a/test/core/iomgr/tcp_client_posix_test.c +++ b/test/core/iomgr/tcp_client_posix_test.c @@ -188,12 +188,14 @@ void test_times_out(void) { /* Make sure the event doesn't trigger early */ gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); - while (gpr_time_cmp(gpr_time_add(connect_deadline, gpr_time_from_seconds(2)), + while (gpr_time_cmp(gpr_time_add(connect_deadline, + gpr_time_from_seconds(2, GPR_TIMESPAN)), gpr_now(GPR_CLOCK_REALTIME)) > 0) { int is_after_deadline = gpr_time_cmp(connect_deadline, gpr_now(GPR_CLOCK_REALTIME)) <= 0; if (is_after_deadline && - gpr_time_cmp(gpr_time_add(connect_deadline, gpr_time_from_seconds(1)), + gpr_time_cmp(gpr_time_add(connect_deadline, + gpr_time_from_seconds(1, GPR_TIMESPAN)), gpr_now(GPR_CLOCK_REALTIME)) > 0) { /* allow some slack before insisting that things be done */ } else { diff --git a/test/core/statistics/census_log_tests.c b/test/core/statistics/census_log_tests.c index 0f326d28e2..3292f8a64d 100644 --- a/test/core/statistics/census_log_tests.c +++ b/test/core/statistics/census_log_tests.c @@ -237,7 +237,8 @@ static void reader_thread(void* arg) { gpr_timespec interval; int counter = 0; printf(" Reader starting\n"); - interval = gpr_time_from_micros(args->read_iteration_interval_in_msec * 1000); + interval = gpr_time_from_micros(args->read_iteration_interval_in_msec * 1000, + GPR_TIMESPAN); gpr_mu_lock(args->mu); while (!args->stop_flag && records_read < args->total_records) { gpr_cv_wait(&args->stop, args->mu, interval); diff --git a/test/core/support/cancellable_test.c b/test/core/support/cancellable_test.c index ca206bd839..9b321d388e 100644 --- a/test/core/support/cancellable_test.c +++ b/test/core/support/cancellable_test.c @@ -83,24 +83,29 @@ static void test(void) { /* Test timeout on event wait for uncancelled gpr_cancellable */ interval = gpr_now(GPR_CLOCK_REALTIME); - gpr_event_cancellable_wait(&t.ev, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_micros(1000000)), - &t.cancel); + gpr_event_cancellable_wait( + &t.ev, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(1000000, GPR_TIMESPAN)), + &t.cancel); interval = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), interval); - GPR_ASSERT(gpr_time_cmp(interval, gpr_time_from_micros(500000)) >= 0); - GPR_ASSERT(gpr_time_cmp(gpr_time_from_micros(2000000), interval) >= 0); + GPR_ASSERT( + gpr_time_cmp(interval, gpr_time_from_micros(500000, GPR_TIMESPAN)) >= 0); + GPR_ASSERT( + gpr_time_cmp(gpr_time_from_micros(2000000, GPR_TIMESPAN), interval) >= 0); /* Test timeout on cv wait for uncancelled gpr_cancellable */ gpr_mu_lock(&t.mu); interval = gpr_now(GPR_CLOCK_REALTIME); while (!gpr_cv_cancellable_wait( - &t.cv, &t.mu, - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(1000000)), + &t.cv, &t.mu, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(1000000, GPR_TIMESPAN)), &t.cancel)) { } interval = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), interval); - GPR_ASSERT(gpr_time_cmp(interval, gpr_time_from_micros(500000)) >= 0); - GPR_ASSERT(gpr_time_cmp(gpr_time_from_micros(2000000), interval) >= 0); + GPR_ASSERT( + gpr_time_cmp(interval, gpr_time_from_micros(500000, GPR_TIMESPAN)) >= 0); + GPR_ASSERT( + gpr_time_cmp(gpr_time_from_micros(2000000, GPR_TIMESPAN), interval) >= 0); gpr_mu_unlock(&t.mu); /* Create some threads. They all wait until cancelled; the last to finish @@ -114,8 +119,9 @@ static void test(void) { /* Wait a second, and check that no threads have finished waiting. */ gpr_mu_lock(&t.mu); - gpr_cv_wait(&t.cv, &t.mu, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_micros(1000000))); + gpr_cv_wait(&t.cv, &t.mu, + gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(1000000, GPR_TIMESPAN))); GPR_ASSERT(t.n == n); gpr_mu_unlock(&t.mu); @@ -133,21 +139,24 @@ static void test(void) { gpr_mu_lock(&t.mu); interval = gpr_now(GPR_CLOCK_REALTIME); while (!gpr_cv_cancellable_wait( - &t.cv, &t.mu, - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(1000000)), + &t.cv, &t.mu, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(1000000, GPR_TIMESPAN)), &t.cancel)) { } interval = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), interval); - GPR_ASSERT(gpr_time_cmp(gpr_time_from_micros(100000), interval) >= 0); + GPR_ASSERT( + gpr_time_cmp(gpr_time_from_micros(100000, GPR_TIMESPAN), interval) >= 0); gpr_mu_unlock(&t.mu); /* Test timeout on event wait for cancelled gpr_cancellable */ interval = gpr_now(GPR_CLOCK_REALTIME); - gpr_event_cancellable_wait(&t.ev, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_micros(1000000)), - &t.cancel); + gpr_event_cancellable_wait( + &t.ev, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(1000000, GPR_TIMESPAN)), + &t.cancel); interval = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), interval); - GPR_ASSERT(gpr_time_cmp(gpr_time_from_micros(100000), interval) >= 0); + GPR_ASSERT( + gpr_time_cmp(gpr_time_from_micros(100000, GPR_TIMESPAN), interval) >= 0); gpr_mu_destroy(&t.mu); gpr_cv_destroy(&t.cv); diff --git a/test/core/support/sync_test.c b/test/core/support/sync_test.c index 73dd06c96f..f729eb0b92 100644 --- a/test/core/support/sync_test.c +++ b/test/core/support/sync_test.c @@ -245,8 +245,8 @@ static void test(const char *name, void (*body)(void *m), struct test *m; gpr_timespec start = gpr_now(GPR_CLOCK_REALTIME); gpr_timespec time_taken; - gpr_timespec deadline = - gpr_time_add(start, gpr_time_from_micros(timeout_s * 1000000)); + gpr_timespec deadline = gpr_time_add( + start, gpr_time_from_micros(timeout_s * 1000000, GPR_TIMESPAN)); fprintf(stderr, "%s:", name); while (gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), deadline) < 0) { iterations <<= 1; @@ -324,8 +324,8 @@ static void inc_with_1ms_delay(void *v /*=m*/) { for (i = 0; i != m->iterations; i++) { gpr_timespec deadline; gpr_mu_lock(&m->mu); - deadline = - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(1000)); + deadline = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(1000, GPR_TIMESPAN)); while (!gpr_cv_wait(&m->cv, &m->mu, deadline)) { } m->counter++; @@ -341,8 +341,8 @@ static void inc_with_1ms_delay_event(void *v /*=m*/) { gpr_int64 i; for (i = 0; i != m->iterations; i++) { gpr_timespec deadline; - deadline = - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(1000)); + deadline = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(1000, GPR_TIMESPAN)); GPR_ASSERT(gpr_event_wait(&m->event, deadline) == NULL); gpr_mu_lock(&m->mu); m->counter++; @@ -385,9 +385,10 @@ static void consumer(void *v /*=m*/) { gpr_mu_lock(&m->mu); m->counter = n; gpr_mu_unlock(&m->mu); - GPR_ASSERT(!queue_remove(&m->q, &value, - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_micros(1000000)))); + GPR_ASSERT( + !queue_remove(&m->q, &value, + gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(1000000, GPR_TIMESPAN)))); mark_thread_done(m); } diff --git a/test/core/support/time_test.c b/test/core/support/time_test.c index 29908744ae..594863c278 100644 --- a/test/core/support/time_test.c +++ b/test/core/support/time_test.c @@ -113,37 +113,37 @@ static void test_values(void) { fprintf(stderr, "\n"); for (i = 1; i != 1000 * 1000 * 1000; i *= 10) { - x = gpr_time_from_micros(i); + x = gpr_time_from_micros(i, GPR_TIMESPAN); GPR_ASSERT(x.tv_sec == i / GPR_US_PER_SEC && x.tv_nsec == (i % GPR_US_PER_SEC) * GPR_NS_PER_US); - x = gpr_time_from_nanos(i); + x = gpr_time_from_nanos(i, GPR_TIMESPAN); GPR_ASSERT(x.tv_sec == i / GPR_NS_PER_SEC && x.tv_nsec == (i % GPR_NS_PER_SEC)); - x = gpr_time_from_millis(i); + x = gpr_time_from_millis(i, GPR_TIMESPAN); GPR_ASSERT(x.tv_sec == i / GPR_MS_PER_SEC && x.tv_nsec == (i % GPR_MS_PER_SEC) * GPR_NS_PER_MS); } /* Test possible overflow in conversion of -ve values. */ - x = gpr_time_from_micros(-(LONG_MAX - 999997)); + x = gpr_time_from_micros(-(LONG_MAX - 999997), GPR_TIMESPAN); GPR_ASSERT(x.tv_sec < 0); GPR_ASSERT(x.tv_nsec >= 0 && x.tv_nsec < GPR_NS_PER_SEC); - x = gpr_time_from_nanos(-(LONG_MAX - 999999997)); + x = gpr_time_from_nanos(-(LONG_MAX - 999999997), GPR_TIMESPAN); GPR_ASSERT(x.tv_sec < 0); GPR_ASSERT(x.tv_nsec >= 0 && x.tv_nsec < GPR_NS_PER_SEC); - x = gpr_time_from_millis(-(LONG_MAX - 997)); + x = gpr_time_from_millis(-(LONG_MAX - 997), GPR_TIMESPAN); GPR_ASSERT(x.tv_sec < 0); GPR_ASSERT(x.tv_nsec >= 0 && x.tv_nsec < GPR_NS_PER_SEC); /* Test general -ve values. */ for (i = -1; i > -1000 * 1000 * 1000; i *= 7) { - x = gpr_time_from_micros(i); + x = gpr_time_from_micros(i, GPR_TIMESPAN); GPR_ASSERT(x.tv_sec * GPR_US_PER_SEC + x.tv_nsec / GPR_NS_PER_US == i); - x = gpr_time_from_nanos(i); + x = gpr_time_from_nanos(i, GPR_TIMESPAN); GPR_ASSERT(x.tv_sec * GPR_NS_PER_SEC + x.tv_nsec == i); - x = gpr_time_from_millis(i); + x = gpr_time_from_millis(i, GPR_TIMESPAN); GPR_ASSERT(x.tv_sec * GPR_MS_PER_SEC + x.tv_nsec / GPR_NS_PER_MS == i); } } @@ -158,17 +158,19 @@ static void test_add_sub(void) { for (k = 1; k <= 10000000; k *= 10) { int sum = i + j; int diff = i - j; - gpr_timespec it = gpr_time_from_micros(i * k); - gpr_timespec jt = gpr_time_from_micros(j * k); + gpr_timespec it = gpr_time_from_micros(i * k, GPR_TIMESPAN); + gpr_timespec jt = gpr_time_from_micros(j * k, GPR_TIMESPAN); gpr_timespec sumt = gpr_time_add(it, jt); gpr_timespec difft = gpr_time_sub(it, jt); - if (gpr_time_cmp(gpr_time_from_micros(sum * k), sumt) != 0) { + if (gpr_time_cmp(gpr_time_from_micros(sum * k, GPR_TIMESPAN), sumt) != + 0) { fprintf(stderr, "i %d j %d sum %d sumt ", i, j, sum); ts_to_s(sumt, &to_fp, stderr); fprintf(stderr, "\n"); GPR_ASSERT(0); } - if (gpr_time_cmp(gpr_time_from_micros(diff * k), difft) != 0) { + if (gpr_time_cmp(gpr_time_from_micros(diff * k, GPR_TIMESPAN), difft) != + 0) { fprintf(stderr, "i %d j %d diff %d diff ", i, j, diff); ts_to_s(sumt, &to_fp, stderr); fprintf(stderr, "\n"); @@ -181,12 +183,12 @@ static void test_add_sub(void) { static void test_overflow(void) { /* overflow */ - gpr_timespec x = gpr_time_from_micros(1); + gpr_timespec x = gpr_time_from_micros(1, GPR_TIMESPAN); do { x = gpr_time_add(x, x); } while (gpr_time_cmp(x, gpr_inf_future(GPR_TIMESPAN)) < 0); GPR_ASSERT(gpr_time_cmp(x, gpr_inf_future(GPR_TIMESPAN)) == 0); - x = gpr_time_from_micros(-1); + x = gpr_time_from_micros(-1, GPR_TIMESPAN); do { x = gpr_time_add(x, x); } while (gpr_time_cmp(x, gpr_inf_past(GPR_TIMESPAN)) > 0); @@ -214,7 +216,7 @@ static void test_sticky_infinities(void) { GPR_ASSERT(gpr_time_cmp(x, infinity[i]) == 0); } for (k = -200; k <= 200; k++) { - gpr_timespec y = gpr_time_from_micros(k * 100000); + gpr_timespec y = gpr_time_from_micros(k * 100000, GPR_TIMESPAN); gpr_timespec x = gpr_time_add(infinity[i], y); GPR_ASSERT(gpr_time_cmp(x, infinity[i]) == 0); x = gpr_time_sub(infinity[i], y); @@ -236,21 +238,21 @@ static void test_similar(void) { GPR_ASSERT(0 == gpr_time_similar(gpr_inf_future(GPR_TIMESPAN), gpr_inf_past(GPR_TIMESPAN), gpr_time_0(GPR_TIMESPAN))); - GPR_ASSERT(1 == gpr_time_similar(gpr_time_from_micros(10), - gpr_time_from_micros(10), + GPR_ASSERT(1 == gpr_time_similar(gpr_time_from_micros(10, GPR_TIMESPAN), + gpr_time_from_micros(10, GPR_TIMESPAN), gpr_time_0(GPR_TIMESPAN))); - GPR_ASSERT(1 == gpr_time_similar(gpr_time_from_micros(10), - gpr_time_from_micros(15), - gpr_time_from_micros(10))); - GPR_ASSERT(1 == gpr_time_similar(gpr_time_from_micros(15), - gpr_time_from_micros(10), - gpr_time_from_micros(10))); - GPR_ASSERT(0 == gpr_time_similar(gpr_time_from_micros(10), - gpr_time_from_micros(25), - gpr_time_from_micros(10))); - GPR_ASSERT(0 == gpr_time_similar(gpr_time_from_micros(25), - gpr_time_from_micros(10), - gpr_time_from_micros(10))); + GPR_ASSERT(1 == gpr_time_similar(gpr_time_from_micros(10, GPR_TIMESPAN), + gpr_time_from_micros(15, GPR_TIMESPAN), + gpr_time_from_micros(10, GPR_TIMESPAN))); + GPR_ASSERT(1 == gpr_time_similar(gpr_time_from_micros(15, GPR_TIMESPAN), + gpr_time_from_micros(10, GPR_TIMESPAN), + gpr_time_from_micros(10, GPR_TIMESPAN))); + GPR_ASSERT(0 == gpr_time_similar(gpr_time_from_micros(10, GPR_TIMESPAN), + gpr_time_from_micros(25, GPR_TIMESPAN), + gpr_time_from_micros(10, GPR_TIMESPAN))); + GPR_ASSERT(0 == gpr_time_similar(gpr_time_from_micros(25, GPR_TIMESPAN), + gpr_time_from_micros(10, GPR_TIMESPAN), + gpr_time_from_micros(10, GPR_TIMESPAN))); } int main(int argc, char *argv[]) { diff --git a/test/core/transport/chttp2/timeout_encoding_test.c b/test/core/transport/chttp2/timeout_encoding_test.c index b5ab26768b..ba6c3191f1 100644 --- a/test/core/transport/chttp2/timeout_encoding_test.c +++ b/test/core/transport/chttp2/timeout_encoding_test.c @@ -54,34 +54,35 @@ static void assert_encodes_as(gpr_timespec ts, const char *s) { void test_encoding(void) { LOG_TEST("test_encoding"); - assert_encodes_as(gpr_time_from_micros(-1), "1n"); - assert_encodes_as(gpr_time_from_seconds(-10), "1n"); - assert_encodes_as(gpr_time_from_nanos(10), "10n"); - assert_encodes_as(gpr_time_from_nanos(999999999), "1S"); - assert_encodes_as(gpr_time_from_micros(1), "1u"); - assert_encodes_as(gpr_time_from_micros(10), "10u"); - assert_encodes_as(gpr_time_from_micros(100), "100u"); - assert_encodes_as(gpr_time_from_micros(890), "890u"); - assert_encodes_as(gpr_time_from_micros(900), "900u"); - assert_encodes_as(gpr_time_from_micros(901), "901u"); - assert_encodes_as(gpr_time_from_millis(1), "1m"); - assert_encodes_as(gpr_time_from_millis(2), "2m"); - assert_encodes_as(gpr_time_from_micros(10001), "10100u"); - assert_encodes_as(gpr_time_from_micros(999999), "1S"); - assert_encodes_as(gpr_time_from_millis(1000), "1S"); - assert_encodes_as(gpr_time_from_millis(2000), "2S"); - assert_encodes_as(gpr_time_from_millis(2500), "2500m"); - assert_encodes_as(gpr_time_from_millis(59900), "59900m"); - assert_encodes_as(gpr_time_from_seconds(50), "50S"); - assert_encodes_as(gpr_time_from_seconds(59), "59S"); - assert_encodes_as(gpr_time_from_seconds(60), "1M"); - assert_encodes_as(gpr_time_from_seconds(80), "80S"); - assert_encodes_as(gpr_time_from_seconds(90), "90S"); - assert_encodes_as(gpr_time_from_minutes(2), "2M"); - assert_encodes_as(gpr_time_from_minutes(20), "20M"); - assert_encodes_as(gpr_time_from_hours(1), "1H"); - assert_encodes_as(gpr_time_from_hours(10), "10H"); - assert_encodes_as(gpr_time_from_seconds(1000000000), "1000000000S"); + assert_encodes_as(gpr_time_from_micros(-1, GPR_TIMESPAN), "1n"); + assert_encodes_as(gpr_time_from_seconds(-10, GPR_TIMESPAN), "1n"); + assert_encodes_as(gpr_time_from_nanos(10, GPR_TIMESPAN), "10n"); + assert_encodes_as(gpr_time_from_nanos(999999999, GPR_TIMESPAN), "1S"); + assert_encodes_as(gpr_time_from_micros(1, GPR_TIMESPAN), "1u"); + assert_encodes_as(gpr_time_from_micros(10, GPR_TIMESPAN), "10u"); + assert_encodes_as(gpr_time_from_micros(100, GPR_TIMESPAN), "100u"); + assert_encodes_as(gpr_time_from_micros(890, GPR_TIMESPAN), "890u"); + assert_encodes_as(gpr_time_from_micros(900, GPR_TIMESPAN), "900u"); + assert_encodes_as(gpr_time_from_micros(901, GPR_TIMESPAN), "901u"); + assert_encodes_as(gpr_time_from_millis(1, GPR_TIMESPAN), "1m"); + assert_encodes_as(gpr_time_from_millis(2, GPR_TIMESPAN), "2m"); + assert_encodes_as(gpr_time_from_micros(10001, GPR_TIMESPAN), "10100u"); + assert_encodes_as(gpr_time_from_micros(999999, GPR_TIMESPAN), "1S"); + assert_encodes_as(gpr_time_from_millis(1000, GPR_TIMESPAN), "1S"); + assert_encodes_as(gpr_time_from_millis(2000, GPR_TIMESPAN), "2S"); + assert_encodes_as(gpr_time_from_millis(2500, GPR_TIMESPAN), "2500m"); + assert_encodes_as(gpr_time_from_millis(59900, GPR_TIMESPAN), "59900m"); + assert_encodes_as(gpr_time_from_seconds(50, GPR_TIMESPAN), "50S"); + assert_encodes_as(gpr_time_from_seconds(59, GPR_TIMESPAN), "59S"); + assert_encodes_as(gpr_time_from_seconds(60, GPR_TIMESPAN), "1M"); + assert_encodes_as(gpr_time_from_seconds(80, GPR_TIMESPAN), "80S"); + assert_encodes_as(gpr_time_from_seconds(90, GPR_TIMESPAN), "90S"); + assert_encodes_as(gpr_time_from_minutes(2, GPR_TIMESPAN), "2M"); + assert_encodes_as(gpr_time_from_minutes(20, GPR_TIMESPAN), "20M"); + assert_encodes_as(gpr_time_from_hours(1, GPR_TIMESPAN), "1H"); + assert_encodes_as(gpr_time_from_hours(10, GPR_TIMESPAN), "10H"); + assert_encodes_as(gpr_time_from_seconds(1000000000, GPR_TIMESPAN), + "1000000000S"); } static void assert_decodes_as(const char *buffer, gpr_timespec expected) { @@ -91,7 +92,8 @@ static void assert_decodes_as(const char *buffer, gpr_timespec expected) { GPR_ASSERT(0 == gpr_time_cmp(got, expected)); } -void decode_suite(char ext, gpr_timespec (*answer)(long x)) { +void decode_suite(char ext, + gpr_timespec (*answer)(long x, gpr_clock_type clock)) { long test_vals[] = {1, 12, 123, 1234, 12345, 123456, 1234567, 12345678, 123456789, 98765432, 9876543, 987654, 98765, 9876, 987, 98, 9}; @@ -99,19 +101,19 @@ void decode_suite(char ext, gpr_timespec (*answer)(long x)) { char *input; for (i = 0; i < GPR_ARRAY_SIZE(test_vals); i++) { gpr_asprintf(&input, "%ld%c", test_vals[i], ext); - assert_decodes_as(input, answer(test_vals[i])); + assert_decodes_as(input, answer(test_vals[i], GPR_TIMESPAN)); gpr_free(input); gpr_asprintf(&input, " %ld%c", test_vals[i], ext); - assert_decodes_as(input, answer(test_vals[i])); + assert_decodes_as(input, answer(test_vals[i], GPR_TIMESPAN)); gpr_free(input); gpr_asprintf(&input, "%ld %c", test_vals[i], ext); - assert_decodes_as(input, answer(test_vals[i])); + assert_decodes_as(input, answer(test_vals[i], GPR_TIMESPAN)); gpr_free(input); gpr_asprintf(&input, "%ld %c ", test_vals[i], ext); - assert_decodes_as(input, answer(test_vals[i])); + assert_decodes_as(input, answer(test_vals[i], GPR_TIMESPAN)); gpr_free(input); } } diff --git a/test/core/util/test_config.h b/test/core/util/test_config.h index 3218953166..063c797ce9 100644 --- a/test/core/util/test_config.h +++ b/test/core/util/test_config.h @@ -51,13 +51,15 @@ extern "C" { #define GRPC_TEST_SLOWDOWN_FACTOR \ (GRPC_TEST_SLOWDOWN_BUILD_FACTOR * GRPC_TEST_SLOWDOWN_MACHINE_FACTOR) -#define GRPC_TIMEOUT_SECONDS_TO_DEADLINE(x) \ - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), \ - gpr_time_from_micros(GRPC_TEST_SLOWDOWN_FACTOR * 1e6 * (x))) +#define GRPC_TIMEOUT_SECONDS_TO_DEADLINE(x) \ + gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), \ + gpr_time_from_micros(GRPC_TEST_SLOWDOWN_FACTOR * 1e6 * (x), \ + GPR_TIMESPAN)) -#define GRPC_TIMEOUT_MILLIS_TO_DEADLINE(x) \ - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), \ - gpr_time_from_micros(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x))) +#define GRPC_TIMEOUT_MILLIS_TO_DEADLINE(x) \ + gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), \ + gpr_time_from_micros(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x), \ + GPR_TIMESPAN)) #ifndef GRPC_TEST_CUSTOM_PICK_PORT #define GRPC_TEST_PICK_PORT -- cgit v1.2.3 From 677c50c92a89870c479230d03fa4a93109310906 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 13 Jul 2015 10:49:06 -0700 Subject: Update C++ impl --- src/cpp/client/secure_credentials.cc | 6 ++++-- test/cpp/end2end/end2end_test.cc | 8 +++++--- test/cpp/end2end/server_crash_test.cc | 16 ++++++++-------- test/cpp/end2end/thread_stress_test.cc | 6 ++++-- test/cpp/qps/driver.cc | 7 ++++--- test/cpp/qps/worker.cc | 4 ++-- test/cpp/util/time_test.cc | 2 +- 7 files changed, 28 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc index 4d200908fb..01c7f14f1a 100644 --- a/src/cpp/client/secure_credentials.cc +++ b/src/cpp/client/secure_credentials.cc @@ -92,7 +92,8 @@ std::shared_ptr ServiceAccountCredentials( "with non-positive lifetime"); return WrapCredentials(nullptr); } - gpr_timespec lifetime = gpr_time_from_seconds(token_lifetime_seconds); + gpr_timespec lifetime = + gpr_time_from_seconds(token_lifetime_seconds, GPR_TIMESPAN); return WrapCredentials(grpc_service_account_credentials_create( json_key.c_str(), scope.c_str(), lifetime)); } @@ -105,7 +106,8 @@ std::shared_ptr JWTCredentials(const grpc::string& json_key, "Trying to create JWTCredentials with non-positive lifetime"); return WrapCredentials(nullptr); } - gpr_timespec lifetime = gpr_time_from_seconds(token_lifetime_seconds); + gpr_timespec lifetime = + gpr_time_from_seconds(token_lifetime_seconds, GPR_TIMESPAN); return WrapCredentials( grpc_jwt_credentials_create(json_key.c_str(), lifetime)); } diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 403fffed5c..4b9529ca0d 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -116,14 +116,16 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service { while (!context->IsCancelled()) { gpr_sleep_until(gpr_time_add( gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_micros(request->param().client_cancel_after_us()))); + gpr_time_from_micros(request->param().client_cancel_after_us(), + GPR_TIMESPAN))); } return Status::CANCELLED; } else if (request->has_param() && request->param().server_cancel_after_us()) { gpr_sleep_until(gpr_time_add( gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_micros(request->param().server_cancel_after_us()))); + gpr_time_from_micros(request->param().server_cancel_after_us(), + GPR_TIMESPAN))); return Status::CANCELLED; } else { EXPECT_FALSE(context->IsCancelled()); @@ -529,7 +531,7 @@ TEST_F(End2endTest, BadCredentials) { void CancelRpc(ClientContext* context, int delay_us, TestServiceImpl* service) { gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_micros(delay_us))); + gpr_time_from_micros(delay_us, GPR_TIMESPAN))); while (!service->signal_client()) { } context->TryCancel(); diff --git a/test/cpp/end2end/server_crash_test.cc b/test/cpp/end2end/server_crash_test.cc index 4d4d590bdd..7d95b4460d 100644 --- a/test/cpp/end2end/server_crash_test.cc +++ b/test/cpp/end2end/server_crash_test.cc @@ -84,8 +84,8 @@ class ServiceImpl GRPC_FINAL gpr_log(GPR_INFO, "recv msg %s", request.message().c_str()); response.set_message(request.message()); stream->Write(response); - gpr_sleep_until( - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(1))); + gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_seconds(1, GPR_TIMESPAN))); } return Status::OK; } @@ -99,8 +99,8 @@ class ServiceImpl GRPC_FINAL msg << "Hello " << i; response.set_message(msg.str()); if (!writer->Write(response)) break; - gpr_sleep_until( - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(1))); + gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_seconds(1, GPR_TIMESPAN))); } return Status::OK; } @@ -147,8 +147,8 @@ class CrashTest : public ::testing::Test { TEST_F(CrashTest, ResponseStream) { auto server = CreateServerAndClient("response"); - gpr_sleep_until( - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(5))); + gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_seconds(5, GPR_TIMESPAN))); KillClient(); server->Shutdown(); GPR_ASSERT(HadOneResponseStream()); @@ -157,8 +157,8 @@ TEST_F(CrashTest, ResponseStream) { TEST_F(CrashTest, BidiStream) { auto server = CreateServerAndClient("bidi"); - gpr_sleep_until( - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(5))); + gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_seconds(5, GPR_TIMESPAN))); KillClient(); server->Shutdown(); GPR_ASSERT(HadOneBidiStream()); diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc index cae34455b9..62d552dd0d 100644 --- a/test/cpp/end2end/thread_stress_test.cc +++ b/test/cpp/end2end/thread_stress_test.cc @@ -97,14 +97,16 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service { while (!context->IsCancelled()) { gpr_sleep_until(gpr_time_add( gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_micros(request->param().client_cancel_after_us()))); + gpr_time_from_micros(request->param().client_cancel_after_us(), + GPR_TIMESPAN))); } return Status::CANCELLED; } else if (request->has_param() && request->param().server_cancel_after_us()) { gpr_sleep_until(gpr_time_add( gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_micros(request->param().server_cancel_after_us()))); + gpr_time_from_micros(request->param().server_cancel_after_us(), + GPR_TIMESPAN))); return Status::CANCELLED; } else { EXPECT_FALSE(context->IsCancelled()); diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc index 5597bcd549..a0360295e0 100644 --- a/test/cpp/qps/driver.cc +++ b/test/cpp/qps/driver.cc @@ -186,7 +186,8 @@ std::unique_ptr RunScenario( // Let everything warmup gpr_log(GPR_INFO, "Warming up"); gpr_timespec start = gpr_now(GPR_CLOCK_REALTIME); - gpr_sleep_until(gpr_time_add(start, gpr_time_from_seconds(warmup_seconds))); + gpr_sleep_until( + gpr_time_add(start, gpr_time_from_seconds(warmup_seconds, GPR_TIMESPAN))); // Start a run gpr_log(GPR_INFO, "Starting"); @@ -211,8 +212,8 @@ std::unique_ptr RunScenario( // Wait some time gpr_log(GPR_INFO, "Running"); - gpr_sleep_until( - gpr_time_add(start, gpr_time_from_seconds(benchmark_seconds))); + gpr_sleep_until(gpr_time_add( + start, gpr_time_from_seconds(benchmark_seconds, GPR_TIMESPAN))); // Finish a run std::unique_ptr result(new ScenarioResult); diff --git a/test/cpp/qps/worker.cc b/test/cpp/qps/worker.cc index 2bc0a56970..7cf4903148 100644 --- a/test/cpp/qps/worker.cc +++ b/test/cpp/qps/worker.cc @@ -57,8 +57,8 @@ static void RunServer() { QpsWorker worker(FLAGS_driver_port, FLAGS_server_port); while (!got_sigint) { - gpr_sleep_until( - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(5))); + gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_seconds(5, GPR_TIMESPAN))); } } diff --git a/test/cpp/util/time_test.cc b/test/cpp/util/time_test.cc index 1770a80574..4cb6ec4b4e 100644 --- a/test/cpp/util/time_test.cc +++ b/test/cpp/util/time_test.cc @@ -46,7 +46,7 @@ class TimeTest : public ::testing::Test {}; TEST_F(TimeTest, AbsolutePointTest) { long us = 10000000L; - gpr_timespec ts = gpr_time_from_micros(us); + gpr_timespec ts = gpr_time_from_micros(us, GPR_TIMESPAN); ts.clock_type = GPR_CLOCK_REALTIME; system_clock::time_point tp{microseconds(us)}; system_clock::time_point tp_converted = Timespec2Timepoint(ts); -- cgit v1.2.3 From 21038ce1d4f09ad0f4cb9a1d42c40928265d0ae3 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 14 Jul 2015 06:55:47 -0700 Subject: Mac, Windows support for new timespec --- src/core/support/time_posix.c | 1 + src/core/support/time_win32.c | 1 + 2 files changed, 2 insertions(+) (limited to 'src') diff --git a/src/core/support/time_posix.c b/src/core/support/time_posix.c index f28c2d7b78..258b2e640e 100644 --- a/src/core/support/time_posix.c +++ b/src/core/support/time_posix.c @@ -92,6 +92,7 @@ gpr_timespec gpr_now(gpr_clock_type clock) { struct timeval now_tv; double now_dbl; + now.clock_type = clock; switch (clock) { case GPR_CLOCK_REALTIME: gettimeofday(&now_tv, NULL); diff --git a/src/core/support/time_win32.c b/src/core/support/time_win32.c index fa77c74eeb..238cd07ebc 100644 --- a/src/core/support/time_win32.c +++ b/src/core/support/time_win32.c @@ -55,6 +55,7 @@ gpr_timespec gpr_now(gpr_clock_type clock) { struct _timeb now_tb; LARGE_INTEGER timestamp; double now_dbl; + now_tv.clock_type = clock; switch (clock) { case GPR_CLOCK_REALTIME: _ftime_s(&now_tb); -- cgit v1.2.3 From 5a1e7fda8482b06eba4c6e0df3f923e3edf02d43 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 14 Jul 2015 07:14:47 -0700 Subject: Ruby fixes for new timespec --- src/ruby/ext/grpc/rb_grpc.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/ruby/ext/grpc/rb_grpc.c b/src/ruby/ext/grpc/rb_grpc.c index b0ecbce091..f138bf6dd5 100644 --- a/src/ruby/ext/grpc/rb_grpc.c +++ b/src/ruby/ext/grpc/rb_grpc.c @@ -98,6 +98,7 @@ gpr_timespec grpc_rb_time_timeval(VALUE time, int interval) { const char *tstr = interval ? "time interval" : "time"; const char *want = " want |