aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2015-07-13 08:41:49 -0700
committerGravatar Craig Tiller <ctiller@google.com>2015-07-13 08:41:49 -0700
commit143e7bf0cfcbfd60422f4e8f15e6b5c18259c8cd (patch)
treecbeb3f4da486b08a6cdae1be6754c523e2a361fb /include
parentf0fb537da9e67902f56b50d3d0f516b295609d88 (diff)
Introduce a clock type field onto gpr_timespec.
Use it to validate that arithmetic on time types makes even some vague kind of sense.
Diffstat (limited to 'include')
-rw-r--r--include/grpc++/completion_queue.h3
-rw-r--r--include/grpc/support/time.h28
2 files changed, 18 insertions, 13 deletions
diff --git a/include/grpc++/completion_queue.h b/include/grpc++/completion_queue.h
index f32cbff06c..0523ab6a0e 100644
--- a/include/grpc++/completion_queue.h
+++ b/include/grpc++/completion_queue.h
@@ -105,7 +105,8 @@ class CompletionQueue : public GrpcLibrary {
// Returns false if the queue is ready for destruction, true if event
bool Next(void** tag, bool* ok) {
- return (AsyncNextInternal(tag, ok, gpr_inf_future) != SHUTDOWN);
+ return (AsyncNextInternal(tag, ok, gpr_inf_future(GPR_CLOCK_REALTIME)) !=
+ SHUTDOWN);
}
// Shutdown has to be called, and the CompletionQueue can only be
diff --git a/include/grpc/support/time.h b/include/grpc/support/time.h
index a5c947dfc8..dbf2548d1b 100644
--- a/include/grpc/support/time.h
+++ b/include/grpc/support/time.h
@@ -45,15 +45,28 @@
extern "C" {
#endif
+/* The clocks we support. */
+typedef enum {
+ /* Monotonic clock. Epoch undefined. Always moves forwards. */
+ GPR_CLOCK_MONOTONIC = 0,
+ /* Realtime clock. May jump forwards or backwards. Settable by
+ the system administrator. Has its epoch at 0:00:00 UTC 1 Jan 1970. */
+ GPR_CLOCK_REALTIME,
+ /* Unmeasurable clock type: no base, created by taking the difference
+ between two times */
+ GPR_TIMESPAN
+} gpr_clock_type;
+
typedef struct gpr_timespec {
time_t tv_sec;
int tv_nsec;
+ gpr_clock_type clock_type;
} gpr_timespec;
/* Time constants. */
-extern const gpr_timespec gpr_time_0; /* The zero time interval. */
-extern const gpr_timespec gpr_inf_future; /* The far future */
-extern const gpr_timespec gpr_inf_past; /* The far past. */
+gpr_timespec gpr_time_0(gpr_clock_type type); /* The zero time interval. */
+gpr_timespec gpr_inf_future(gpr_clock_type type); /* The far future */
+gpr_timespec gpr_inf_past(gpr_clock_type type); /* The far past. */
#define GPR_MS_PER_SEC 1000
#define GPR_US_PER_SEC 1000000
@@ -62,15 +75,6 @@ extern const gpr_timespec gpr_inf_past; /* The far past. */
#define GPR_NS_PER_US 1000
#define GPR_US_PER_MS 1000
-/* The clocks we support. */
-typedef enum {
- /* Monotonic clock. Epoch undefined. Always moves forwards. */
- GPR_CLOCK_MONOTONIC = 0,
- /* Realtime clock. May jump forwards or backwards. Settable by
- the system administrator. Has its epoch at 0:00:00 UTC 1 Jan 1970. */
- GPR_CLOCK_REALTIME
-} gpr_clock_type;
-
/* initialize time subsystem */
void gpr_time_init(void);