diff options
author | 2015-10-01 08:01:58 -0700 | |
---|---|---|
committer | 2015-10-01 08:01:58 -0700 | |
commit | b7a597771f4db347748b5e5f89d02ed067c5a614 (patch) | |
tree | 10cf9b21fd8d2904bc6d191db0016ee38ffececf /test/cpp/end2end/streaming_throughput_test.cc | |
parent | 71a0f9d3b02ea51b17581e7b655bb48e85f6e553 (diff) | |
parent | 2b2a1ad6ca97da100fd469085f0ffef847e87e65 (diff) |
Merge github.com:grpc/grpc into clangf
Diffstat (limited to 'test/cpp/end2end/streaming_throughput_test.cc')
-rw-r--r-- | test/cpp/end2end/streaming_throughput_test.cc | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/test/cpp/end2end/streaming_throughput_test.cc b/test/cpp/end2end/streaming_throughput_test.cc index 5864cf0579..d4ab1486cc 100644 --- a/test/cpp/end2end/streaming_throughput_test.cc +++ b/test/cpp/end2end/streaming_throughput_test.cc @@ -31,9 +31,9 @@ * */ -#include <atomic> #include <mutex> #include <thread> +#include <time.h> #include <grpc++/channel.h> #include <grpc++/client_context.h> @@ -44,6 +44,7 @@ #include <grpc++/server_builder.h> #include <grpc++/server_context.h> #include <grpc/grpc.h> +#include <grpc/support/atm.h> #include <grpc/support/thd.h> #include <grpc/support/time.h> #include <gtest/gtest.h> @@ -102,12 +103,17 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service { public: static void BidiStream_Sender( ServerReaderWriter<EchoResponse, EchoRequest>* stream, - std::atomic<bool>* should_exit) { + gpr_atm* should_exit) { EchoResponse response; response.set_message(kLargeString); - while (!should_exit->load()) { - // TODO(vpai): Decide if the below requires blocking annotation - std::this_thread::sleep_for(std::chrono::milliseconds(1)); + while (gpr_atm_acq_load(should_exit) == static_cast<gpr_atm>(0)) { + struct timespec tv = {0, 1000000}; // 1 ms + struct timespec rem; + // TODO (vpai): Mark this blocking + while (nanosleep(&tv, &rem) != 0) { + tv = rem; + }; + stream->Write(response); } } @@ -117,15 +123,21 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service { ServerReaderWriter<EchoResponse, EchoRequest>* stream) GRPC_OVERRIDE { EchoRequest request; - std::atomic<bool> should_exit(false); + gpr_atm should_exit; + gpr_atm_rel_store(&should_exit, static_cast<gpr_atm>(0)); + std::thread sender( std::bind(&TestServiceImpl::BidiStream_Sender, stream, &should_exit)); while (stream->Read(&request)) { - // TODO(vpai): Decide if the below requires blocking annotation - std::this_thread::sleep_for(std::chrono::milliseconds(3)); + struct timespec tv = {0, 3000000}; // 3 ms + struct timespec rem; + // TODO (vpai): Mark this blocking + while (nanosleep(&tv, &rem) != 0) { + tv = rem; + }; } - should_exit.store(true); + gpr_atm_rel_store(&should_exit, static_cast<gpr_atm>(1)); sender.join(); return Status::OK; } @@ -149,7 +161,7 @@ class End2endTest : public ::testing::Test { void ResetStub() { std::shared_ptr<Channel> channel = CreateChannel(server_address_.str(), InsecureCredentials()); - stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel)); + stub_ = grpc::cpp::test::util::TestService::NewStub(channel); } std::unique_ptr<grpc::cpp::test::util::TestService::Stub> stub_; |