From 7b1c3c99cee800b3436d434e519270912f8441b3 Mon Sep 17 00:00:00 2001 From: Pawel Winogrodzki Date: Mon, 12 Jun 2017 15:17:36 -0700 Subject: [PATCH] resource/examples: Removing /W4 warnings Removing "unreachable code" warnings due to infinite waits. Bug: https://jira.iotivity.org/browse/IOT-1583 Change-Id: I8d057494e39540f35f1ec447217d70eff556d1c0 Signed-off-by: Pawel Winogrodzki Reviewed-on: https://gerrit.iotivity.org/gerrit/20727 Reviewed-by: Phil Coval Tested-by: jenkins-iotivity Reviewed-by: Dan Mihai --- resource/examples/devicediscoveryclient.cpp | 11 +++-------- resource/examples/devicediscoveryserver.cpp | 11 +++-------- resource/examples/mediaserver.cpp | 15 ++++++--------- 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/resource/examples/devicediscoveryclient.cpp b/resource/examples/devicediscoveryclient.cpp index 03e36d0..b657aa7 100644 --- a/resource/examples/devicediscoveryclient.cpp +++ b/resource/examples/devicediscoveryclient.cpp @@ -179,14 +179,9 @@ int main(int argc, char* argv[]) { std::cout << "failed." << std::endl; } - // A condition variable will free the mutex it is given, then do a non- - // intensive block until 'notify' is called on it. In this case, since we - // don't ever call cv.notify, this should be a non-processor intensive version - // of while(true); - std::mutex blocker; - std::condition_variable cv; - std::unique_lock lock(blocker); - cv.wait(lock, []{return false;}); + std::cout << "Waiting. Press \"Enter\" to quit." << std::endl; + // Ignoring all input except for EOL. + std::cin.ignore(std::numeric_limits::max(), '\n'); OC_VERIFY(OCPlatform::stop() == OC_STACK_OK); diff --git a/resource/examples/devicediscoveryserver.cpp b/resource/examples/devicediscoveryserver.cpp index ce216be..dcfcb41 100644 --- a/resource/examples/devicediscoveryserver.cpp +++ b/resource/examples/devicediscoveryserver.cpp @@ -186,14 +186,9 @@ int main() DeletePlatformInfo(); - // A condition variable will free the mutex it is given, then do a non- - // intensive block until 'notify' is called on it. In this case, since we - // don't ever call cv.notify, this should be a non-processor intensive version - // of while(true); - std::mutex blocker; - std::condition_variable cv; - std::unique_lock lock(blocker); - cv.wait(lock, []{return false;}); + std::cout << "Waiting. Press \"Enter\" to quit." << std::endl; + // Ignoring all input except for EOL. + std::cin.ignore(std::numeric_limits::max(), '\n'); // Perform platform clean up. OC_VERIFY(OCPlatform::stop() == OC_STACK_OK); diff --git a/resource/examples/mediaserver.cpp b/resource/examples/mediaserver.cpp index da8ad44..b3d70cf 100644 --- a/resource/examples/mediaserver.cpp +++ b/resource/examples/mediaserver.cpp @@ -676,15 +676,12 @@ int main(int argc, char* argv[]) myMedia.createResource(); cout << "Created resource." << std::endl; - // A condition variable will free the mutex it is given, then do a non- - // intensive block until 'notify' is called on it. In this case, since we - // don't ever call cv.notify, this should be a non-processor intensive version - // of while(true); - std::mutex blocker; - std::condition_variable cv; - std::unique_lock lock(blocker); - cout <<"Waiting" << std::endl; - cv.wait(lock, []{return false;}); + cout <<"Waiting. Press \"Enter\" to quit." << std::endl; +#ifdef _MSC_VER +#undef max +#endif + // Ignoring all input except for EOL. + cin.ignore(numeric_limits::max(), '\n'); // Perform platform clean up. OC_VERIFY(OCPlatform::stop() == OC_STACK_OK); -- 2.7.4