Make Next free of time_point to timespec conversion

pull/1108/head
Yang Gao 10 years ago
parent 3bd5fa6c78
commit b7b965c842
  1. 7
      include/grpc++/completion_queue.h
  2. 17
      src/cpp/common/completion_queue.cc

@ -36,6 +36,7 @@
#include <chrono>
#include <grpc++/impl/client_unary_call.h>
#include <grpc/support/time.h>
struct grpc_completion_queue;
@ -88,9 +89,7 @@ class CompletionQueue {
// Returns false if the queue is ready for destruction, true if event
bool Next(void** tag, bool* ok) {
return (
AsyncNext(tag, ok, (std::chrono::system_clock::time_point::max)()) !=
SHUTDOWN);
return (AsyncNextInternal(tag, ok, gpr_inf_future) != SHUTDOWN);
}
// Shutdown has to be called, and the CompletionQueue can only be
@ -122,6 +121,8 @@ class CompletionQueue {
const grpc::protobuf::Message& request,
grpc::protobuf::Message* result);
NextStatus AsyncNextInternal(void** tag, bool* ok, gpr_timespec deadline);
// Wraps grpc_completion_queue_pluck.
// Cannot be mixed with calls to Next().
bool Pluck(CompletionQueueTag* tag);

@ -36,7 +36,6 @@
#include <grpc/grpc.h>
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/cpp/util/time.h"
namespace grpc {
@ -57,15 +56,12 @@ class EventDeleter {
}
};
CompletionQueue::NextStatus
CompletionQueue::AsyncNext(void** tag, bool* ok,
std::chrono::system_clock::time_point deadline) {
CompletionQueue::NextStatus CompletionQueue::AsyncNextInternal(
void** tag, bool* ok, gpr_timespec deadline) {
std::unique_ptr<grpc_event, EventDeleter> ev;
gpr_timespec gpr_deadline;
Timepoint2Timespec(deadline, &gpr_deadline);
for (;;) {
ev.reset(grpc_completion_queue_next(cq_, gpr_deadline));
ev.reset(grpc_completion_queue_next(cq_, deadline));
if (!ev) { /* got a NULL back because deadline passed */
return TIMEOUT;
}
@ -81,6 +77,13 @@ CompletionQueue::AsyncNext(void** tag, bool* ok,
}
}
CompletionQueue::NextStatus CompletionQueue::AsyncNext(
void** tag, bool* ok, std::chrono::system_clock::time_point deadline) {
gpr_timespec gpr_deadline;
Timepoint2Timespec(deadline, &gpr_deadline);
return AsyncNextInternal(tag, ok, gpr_deadline);
}
bool CompletionQueue::Pluck(CompletionQueueTag* tag) {
std::unique_ptr<grpc_event, EventDeleter> ev;

Loading…
Cancel
Save