Stop abusing operator() overloading

changes/36/217536/1
vjpai 10 years ago
parent 9440a14558
commit 6e2e64a8b4
  1. 13
      test/cpp/qps/client_async.cc
  2. 6
      test/cpp/qps/server_async.cc

@ -98,7 +98,7 @@ class ClientRpcContext {
public:
ClientRpcContext() {}
virtual ~ClientRpcContext() {}
virtual bool operator()() = 0; // do next state, return false if steps done
virtual bool RunNextState() = 0; // do next state, return false if steps done
static void *tag(ClientRpcContext *c) { return reinterpret_cast<void *>(c); }
static ClientRpcContext *detag(void *t) {
return reinterpret_cast<ClientRpcContext *>(t);
@ -126,7 +126,7 @@ class ClientRpcContextUnaryImpl : public ClientRpcContext {
response_reader_(
start_req(stub_, &context_, req_, ClientRpcContext::tag(this))) {}
~ClientRpcContextUnaryImpl() GRPC_OVERRIDE {}
bool operator()() GRPC_OVERRIDE { return (this->*next_state_)(); }
bool RunNextState() GRPC_OVERRIDE { return (this->*next_state_)(); }
void report_stats(gpr_histogram *hist) GRPC_OVERRIDE {
gpr_histogram_add(hist, now() - start_);
}
@ -242,18 +242,19 @@ static void RunTest(const int client_threads, const int client_channels,
cli_cq.Next(&got_tag, &ok);
if (!ok) break;
ClientRpcContext *ctx = ClientRpcContext::detag(got_tag);
if ((*ctx)() == false) {
if (ctx->RunNextState() == false) {
// call the callback and then delete it
(*ctx)();
ctx->report_stats(hist);
ctx->RunNextState();
delete ctx;
}
cli_cq.Next(&got_tag, &ok);
if (!ok) break;
ctx = ClientRpcContext::detag(got_tag);
if ((*ctx)() == false) {
if (ctx->RunNextState() == false) {
// call the callback and then delete it
ctx->report_stats(hist);
(*ctx)();
ctx->RunNextState();
delete ctx;
}
// Now do runtime round-robin assignment of the next

@ -155,7 +155,7 @@ class AsyncQpsServerTest {
EXPECT_EQ(ok, true);
ServerRpcContext *ctx = detag(got_tag);
// The tag is a pointer to an RPC context to invoke
if ((*ctx)() == false) {
if (ctx->RunNextState() == false) {
// this RPC context is done, so refresh it
ctx->refresh();
}
@ -173,7 +173,7 @@ class AsyncQpsServerTest {
public:
ServerRpcContext() {}
virtual ~ServerRpcContext(){};
virtual bool operator()() = 0; // do next state, return false if all done
virtual bool RunNextState() = 0;// do next state, return false if all done
virtual void refresh() = 0; // start this back at a clean state
};
static void *tag(ServerRpcContext *func) {
@ -200,7 +200,7 @@ class AsyncQpsServerTest {
AsyncQpsServerTest::tag(this));
}
~ServerRpcContextUnaryImpl() GRPC_OVERRIDE {}
bool operator()() GRPC_OVERRIDE { return (this->*next_state_)(); }
bool RunNextState() GRPC_OVERRIDE { return (this->*next_state_)(); }
void refresh() GRPC_OVERRIDE {
srv_ctx_ = ServerContext();
req_ = RequestType();

Loading…
Cancel
Save