diff options
author | Craig Tiller <ctiller@google.com> | 2015-07-13 09:51:17 -0700 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2015-07-13 09:51:17 -0700 |
commit | 58bbc864badff97950bb68a64ce3ade8662bec5d (patch) | |
tree | 5196e7d7ce9ed4581a1c64f9f5e89bfc90e9bd7a /src | |
parent | 354398f9f5191bb44198b94e1828eafb60de5a67 (diff) |
Updating wrapped languages to new time functions
Diffstat (limited to 'src')
-rw-r--r-- | src/core/client_config/subchannel.c | 2 | ||||
-rw-r--r-- | src/core/iomgr/iomgr.c | 14 | ||||
-rw-r--r-- | src/core/iomgr/pollset_posix.c | 10 | ||||
-rw-r--r-- | src/core/security/credentials.c | 8 | ||||
-rw-r--r-- | src/core/security/google_default_credentials.c | 2 | ||||
-rw-r--r-- | src/core/support/cancellable.c | 5 | ||||
-rw-r--r-- | src/core/support/time.c | 48 | ||||
-rw-r--r-- | src/core/surface/completion_queue.c | 5 | ||||
-rw-r--r-- | src/core/surface/server.c | 6 | ||||
-rw-r--r-- | src/core/transport/chttp2/timeout_encoding.c | 12 | ||||
-rw-r--r-- | src/node/ext/timeval.cc | 3 | ||||
-rw-r--r-- | src/php/ext/grpc/timeval.c | 5 | ||||
-rw-r--r-- | src/ruby/ext/grpc/rb_completion_queue.c | 3 |
13 files changed, 64 insertions, 59 deletions
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<double>::infinity()) { return gpr_inf_past(GPR_CLOCK_REALTIME); } else { - return gpr_time_from_micros(static_cast<int64_t>(millis * 1000)); + return gpr_time_from_micros(static_cast<int64_t>(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); |