aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lib')
-rw-r--r--src/core/lib/iomgr/exec_ctx.c17
-rw-r--r--src/core/lib/iomgr/exec_ctx.h3
-rw-r--r--src/core/lib/surface/alarm.c4
-rw-r--r--src/core/lib/surface/channel.c4
-rw-r--r--src/core/lib/surface/completion_queue.c4
5 files changed, 24 insertions, 8 deletions
diff --git a/src/core/lib/iomgr/exec_ctx.c b/src/core/lib/iomgr/exec_ctx.c
index 80aaaee0cb..884227b928 100644
--- a/src/core/lib/iomgr/exec_ctx.c
+++ b/src/core/lib/iomgr/exec_ctx.c
@@ -125,6 +125,16 @@ static gpr_atm timespec_to_atm_round_down(gpr_timespec ts) {
return (gpr_atm)x;
}
+static gpr_atm timespec_to_atm_round_up(gpr_timespec ts) {
+ ts = gpr_time_sub(ts, g_start_time);
+ double x = GPR_MS_PER_SEC * (double)ts.tv_sec +
+ (double)ts.tv_nsec / GPR_NS_PER_MS +
+ (double)(GPR_NS_PER_SEC - 1) / (double)GPR_NS_PER_SEC;
+ if (x < 0) return 0;
+ if (x > GPR_ATM_MAX) return GPR_ATM_MAX;
+ return (gpr_atm)x;
+}
+
grpc_millis grpc_exec_ctx_now(grpc_exec_ctx *exec_ctx) {
if (!exec_ctx->now_is_valid) {
exec_ctx->now = timespec_to_atm_round_down(gpr_now(GPR_CLOCK_MONOTONIC));
@@ -143,11 +153,16 @@ gpr_timespec grpc_millis_to_timespec(grpc_millis millis,
gpr_time_from_millis(millis, GPR_TIMESPAN));
}
-grpc_millis grpc_timespec_to_millis(gpr_timespec ts) {
+grpc_millis grpc_timespec_to_millis_round_down(gpr_timespec ts) {
return timespec_to_atm_round_down(
gpr_convert_clock_type(ts, g_start_time.clock_type));
}
+grpc_millis grpc_timespec_to_millis_round_up(gpr_timespec ts) {
+ return timespec_to_atm_round_up(
+ gpr_convert_clock_type(ts, g_start_time.clock_type));
+}
+
static const grpc_closure_scheduler_vtable exec_ctx_scheduler_vtable = {
exec_ctx_run, exec_ctx_sched, "exec_ctx"};
static grpc_closure_scheduler exec_ctx_scheduler = {&exec_ctx_scheduler_vtable};
diff --git a/src/core/lib/iomgr/exec_ctx.h b/src/core/lib/iomgr/exec_ctx.h
index 87383809f3..bb561ee1c8 100644
--- a/src/core/lib/iomgr/exec_ctx.h
+++ b/src/core/lib/iomgr/exec_ctx.h
@@ -114,6 +114,7 @@ void grpc_exec_ctx_global_shutdown(void);
grpc_millis grpc_exec_ctx_now(grpc_exec_ctx *exec_ctx);
void grpc_exec_ctx_invalidate_now(grpc_exec_ctx *exec_ctx);
gpr_timespec grpc_millis_to_timespec(grpc_millis millis, gpr_clock_type clock);
-grpc_millis grpc_timespec_to_millis(gpr_timespec timespec);
+grpc_millis grpc_timespec_to_millis_round_down(gpr_timespec timespec);
+grpc_millis grpc_timespec_to_millis_round_up(gpr_timespec timespec);
#endif /* GRPC_CORE_LIB_IOMGR_EXEC_CTX_H */
diff --git a/src/core/lib/surface/alarm.c b/src/core/lib/surface/alarm.c
index 5140780bac..39b9f45d05 100644
--- a/src/core/lib/surface/alarm.c
+++ b/src/core/lib/surface/alarm.c
@@ -52,8 +52,8 @@ grpc_alarm *grpc_alarm_create(grpc_completion_queue *cq, gpr_timespec deadline,
grpc_cq_begin_op(cq, tag);
GRPC_CLOSURE_INIT(&alarm->on_alarm, alarm_cb, alarm,
grpc_schedule_on_exec_ctx);
- grpc_timer_init(&exec_ctx, &alarm->alarm, grpc_timespec_to_millis(deadline),
- &alarm->on_alarm);
+ grpc_timer_init(&exec_ctx, &alarm->alarm,
+ grpc_timespec_to_millis_round_up(deadline), &alarm->on_alarm);
grpc_exec_ctx_finish(&exec_ctx);
return alarm;
}
diff --git a/src/core/lib/surface/channel.c b/src/core/lib/surface/channel.c
index b0ff428393..9013e6338b 100644
--- a/src/core/lib/surface/channel.c
+++ b/src/core/lib/surface/channel.c
@@ -276,7 +276,7 @@ grpc_call *grpc_channel_create_call(grpc_channel *channel,
host != NULL ? grpc_mdelem_from_slices(&exec_ctx, GRPC_MDSTR_AUTHORITY,
grpc_slice_ref_internal(*host))
: GRPC_MDNULL,
- grpc_timespec_to_millis(deadline));
+ grpc_timespec_to_millis_round_up(deadline));
grpc_exec_ctx_finish(&exec_ctx);
return call;
}
@@ -341,7 +341,7 @@ grpc_call *grpc_channel_create_registered_call(
grpc_call *call = grpc_channel_create_call_internal(
&exec_ctx, channel, parent_call, propagation_mask, completion_queue, NULL,
GRPC_MDELEM_REF(rc->path), GRPC_MDELEM_REF(rc->authority),
- grpc_timespec_to_millis(deadline));
+ grpc_timespec_to_millis_round_up(deadline));
grpc_exec_ctx_finish(&exec_ctx);
return call;
}
diff --git a/src/core/lib/surface/completion_queue.c b/src/core/lib/surface/completion_queue.c
index f3a8977241..25f8ff6b6a 100644
--- a/src/core/lib/surface/completion_queue.c
+++ b/src/core/lib/surface/completion_queue.c
@@ -815,7 +815,7 @@ static grpc_event cq_next(grpc_completion_queue *cq, gpr_timespec deadline,
GRPC_CQ_INTERNAL_REF(cq, "next");
- grpc_millis deadline_millis = grpc_timespec_to_millis(deadline);
+ grpc_millis deadline_millis = grpc_timespec_to_millis_round_up(deadline);
cq_is_finished_arg is_finished_arg = {
.last_seen_things_queued_ever =
gpr_atm_no_barrier_load(&cqd->things_queued_ever),
@@ -1048,7 +1048,7 @@ static grpc_event cq_pluck(grpc_completion_queue *cq, void *tag,
GRPC_CQ_INTERNAL_REF(cq, "pluck");
gpr_mu_lock(cq->mu);
- grpc_millis deadline_millis = grpc_timespec_to_millis(deadline);
+ grpc_millis deadline_millis = grpc_timespec_to_millis_round_up(deadline);
cq_is_finished_arg is_finished_arg = {
.last_seen_things_queued_ever =
gpr_atm_no_barrier_load(&cqd->things_queued_ever),