aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/iomgr
diff options
context:
space:
mode:
authorGravatar ctiller <ctiller@google.com>2014-12-16 10:44:15 -0800
committerGravatar Nicolas Noble <nnoble@google.com>2014-12-16 17:13:37 -0800
commit769b70ba9d10205d9bfda77bf4420e60ca8d83ba (patch)
tree1b74fcb23a7dde3a045078babaa41d2f0d0153cc /src/core/iomgr
parent5447c5461c692bc6f000a7c363136359dbb92c67 (diff)
Make alarm initialization take a timespec now.
This will allow combining of gpr_now() calls, and make it easier to test the alarm code in the future. Change on 2014/12/16 by ctiller <ctiller@google.com> ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=82246768
Diffstat (limited to 'src/core/iomgr')
-rw-r--r--src/core/iomgr/alarm.h3
-rw-r--r--src/core/iomgr/iomgr_libevent.c5
2 files changed, 5 insertions, 3 deletions
diff --git a/src/core/iomgr/alarm.h b/src/core/iomgr/alarm.h
index e09f165bcf..2bb5bf7022 100644
--- a/src/core/iomgr/alarm.h
+++ b/src/core/iomgr/alarm.h
@@ -53,7 +53,8 @@ typedef struct grpc_alarm grpc_alarm;
information about when to free up any user-level state.
Returns 1 on success, 0 on failure. */
int grpc_alarm_init(grpc_alarm *alarm, gpr_timespec deadline,
- grpc_iomgr_cb_func alarm_cb, void *alarm_cb_arg);
+ grpc_iomgr_cb_func alarm_cb, void *alarm_cb_arg,
+ gpr_timespec now);
/* Note that there is no alarm destroy function. This is because the
alarm is a one-time occurrence with a guarantee that the callback will
diff --git a/src/core/iomgr/iomgr_libevent.c b/src/core/iomgr/iomgr_libevent.c
index 35a1764fa3..3c94d35a38 100644
--- a/src/core/iomgr/iomgr_libevent.c
+++ b/src/core/iomgr/iomgr_libevent.c
@@ -363,10 +363,11 @@ static void libevent_alarm_cb(int fd, short what, void *arg /*=alarm*/) {
}
int grpc_alarm_init(grpc_alarm *alarm, gpr_timespec deadline,
- grpc_iomgr_cb_func alarm_cb, void *alarm_cb_arg) {
+ grpc_iomgr_cb_func alarm_cb, void *alarm_cb_arg,
+ gpr_timespec now) {
grpc_libevent_activation_data *adata =
&alarm->task.activation[GRPC_EM_TA_ONLY];
- gpr_timespec delay_timespec = gpr_time_sub(deadline, gpr_now());
+ gpr_timespec delay_timespec = gpr_time_sub(deadline, now);
struct timeval delay = gpr_timeval_from_timespec(delay_timespec);
alarm->task.type = GRPC_EM_TASK_ALARM;
gpr_atm_rel_store(&alarm->triggered, ALARM_TRIGGER_INIT);