From 360817896b3db5087a4cfde16f0eb5acf25eb24b Mon Sep 17 00:00:00 2001 From: Jose Date: Wed, 13 Jun 2018 17:23:57 +0200 Subject: C++ TestHelper simplications --- cpp/test/Common/TestHelper.cpp | 76 ++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 48 deletions(-) (limited to 'cpp/test/Common/TestHelper.cpp') diff --git a/cpp/test/Common/TestHelper.cpp b/cpp/test/Common/TestHelper.cpp index 765686bdcc4..415c0c93e8e 100644 --- a/cpp/test/Common/TestHelper.cpp +++ b/cpp/test/Common/TestHelper.cpp @@ -1,3 +1,11 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2018 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** #include #include @@ -9,50 +17,29 @@ using namespace Test; namespace { -IceUtil::Mutex* globalMutex = 0; #if !defined(ICE_OS_UWP) && (!defined(__APPLE__) || TARGET_OS_IPHONE == 0) Test::TestHelper* instance = 0; -IceUtil::CtrlCHandler* ctrlCHandler = 0; -#endif -class Init +void +shutdownOnInterruptCallback(int) { -public: - - Init() + if(instance) { - globalMutex = new IceUtil::Mutex; + instance->shutdown(); } +} - ~Init() - { - delete globalMutex; - globalMutex = 0; -#if !defined(ICE_OS_UWP) && (!defined(__APPLE__) || TARGET_OS_IPHONE == 0) - if(ctrlCHandler) - { - delete ctrlCHandler; - ctrlCHandler = 0; - } #endif - } -}; - -Init init; } Test::TestHelper::TestHelper(bool registerPlugins) +#if !defined(ICE_OS_UWP) && (!defined(__APPLE__) || TARGET_OS_IPHONE == 0) + : _ctrlCHandler(0) +#endif { #if !defined(ICE_OS_UWP) && (!defined(__APPLE__) || TARGET_OS_IPHONE == 0) - { - IceUtilInternal::MutexPtrLock lock(globalMutex); - if(instance != 0) - { - throw runtime_error("only one instance of the Test::TestHelper class can be used"); - } - instance = this; - } + instance = this; #endif if(registerPlugins) @@ -83,6 +70,13 @@ Test::TestHelper::TestHelper(bool registerPlugins) Test::TestHelper::~TestHelper() { +#if !defined(ICE_OS_UWP) && (!defined(__APPLE__) || TARGET_OS_IPHONE == 0) + if(_ctrlCHandler) + { + delete _ctrlCHandler; + _ctrlCHandler = 0; + } +#endif } void @@ -215,7 +209,6 @@ Test::TestHelper::initialize(int& argc, char* argv[], const Ice::PropertiesPtr& Ice::CommunicatorPtr Test::TestHelper::initialize(int& argc, char* argv[], Ice::InitializationData initData) { - IceUtil::Mutex::Lock lock(_mutex); _communicator = Ice::initialize(argc, argv, initData); return _communicator; } @@ -238,7 +231,6 @@ Test::TestHelper::serverReady() void Test::TestHelper::shutdown() { - IceUtil::Mutex::Lock lock(_mutex); if(_communicator) { _communicator->shutdown(); @@ -251,26 +243,14 @@ Test::TestHelper::shutdownOnInterrupt() { } #else -void -Test::TestHelper::shutdownOnInterruptCallback(int) -{ - if(instance) - { - instance->shutdown(); - } -} - void Test::TestHelper::shutdownOnInterrupt() { + assert(!_ctrlCHandler); + if(_ctrlCHandler == 0) { - IceUtilInternal::MutexPtrLock lock(globalMutex); - assert(!ctrlCHandler); - if(ctrlCHandler == 0) - { - ctrlCHandler = new IceUtil::CtrlCHandler(); - } + _ctrlCHandler = new IceUtil::CtrlCHandler(); } - ctrlCHandler->setCallback(shutdownOnInterruptCallback); + _ctrlCHandler->setCallback(shutdownOnInterruptCallback); } #endif -- cgit v1.2.3