diff --git a/cpp/include/IceUtil/Cond.h b/cpp/include/IceUtil/Cond.h index 21ccccd0683..45913f857b3 100644 --- a/cpp/include/IceUtil/Cond.h +++ b/cpp/include/IceUtil/Cond.h @@ -9,32 +9,6 @@ #include #include -#if defined(_WIN32) && !defined(ICE_HAS_WIN32_CONDVAR) -# include - -namespace IceUtilInternal -{ -// -// Needed for implementation. -// -class Semaphore -{ -public: - - Semaphore(long = 0); - ICE_API ~Semaphore(); - - void wait() const; - bool timedWait(const IceUtil::Time&) const; - void post(int = 1) const; - -private: - - mutable HANDLE _sem; -}; -} -#endif - namespace IceUtil { @@ -79,7 +53,7 @@ class ICE_API Cond : private noncopyable // // wait atomically unlocks the mutex and waits for the condition // variable to be signaled. Before returning to the calling thread - // the mutex is reaquired. + // the mutex is reacquired. // template inline void wait(const Lock& lock) const @@ -94,7 +68,7 @@ class ICE_API Cond : private noncopyable // // wait atomically unlocks the mutex and waits for the condition // variable to be signaled for up to the given timeout. Before - // returning to the calling thread the mutex is reaquired. Returns + // returning to the calling thread the mutex is reacquired. Returns // true if the condition variable was signaled, false on a // timeout. // @@ -113,85 +87,11 @@ class ICE_API Cond : private noncopyable friend class Monitor; friend class Monitor; - // - // The Monitor implementation uses waitImpl & timedWaitImpl. - // -#if defined(_WIN32) && !defined(ICE_HAS_WIN32_CONDVAR) - - template void - waitImpl(const M& mutex) const - { - preWait(); - - typedef typename M::LockState LockState; - - LockState state; - mutex.unlock(state); - - try - { - dowait(); - mutex.lock(state); - } - catch(...) - { - mutex.lock(state); - throw; - } - } - template bool - timedWaitImpl(const M& mutex, const Time& timeout) const - { - preWait(); - - typedef typename M::LockState LockState; - - LockState state; - mutex.unlock(state); - - try - { - bool rc = timedDowait(timeout); - mutex.lock(state); - return rc; - } - catch(...) - { - mutex.lock(state); - throw; - } - } - -#else - template void waitImpl(const M&) const; template bool timedWaitImpl(const M&, const Time&) const; -#endif - #ifdef _WIN32 -# ifdef ICE_HAS_WIN32_CONDVAR mutable CONDITION_VARIABLE _cond; -# else - void wake(bool); - void preWait() const; - void postWait(bool) const; - bool timedDowait(const Time&) const; - void dowait() const; - - Mutex _internal; - IceUtilInternal::Semaphore _gate; - IceUtilInternal::Semaphore _queue; - mutable long _blocked; - mutable long _unblocked; - enum State - { - StateIdle, - StateSignal, - StateBroadcast - }; - mutable State _state; -# endif #else mutable pthread_cond_t _cond; #endif @@ -200,8 +100,6 @@ class ICE_API Cond : private noncopyable #ifdef _WIN32 -# ifdef ICE_HAS_WIN32_CONDVAR - template inline void Cond::waitImpl(const M& mutex) const { @@ -247,9 +145,8 @@ Cond::timedWaitImpl(const M& mutex, const Time& timeout) const return true; } -# endif - #else + template inline void Cond::waitImpl(const M& mutex) const { diff --git a/cpp/include/IceUtil/IceUtil.h b/cpp/include/IceUtil/IceUtil.h index c68114b75c1..39c1eb71b29 100644 --- a/cpp/include/IceUtil/IceUtil.h +++ b/cpp/include/IceUtil/IceUtil.h @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include diff --git a/cpp/include/IceUtil/Options.h b/cpp/include/IceUtil/Options.h index 1f6ba3c59d7..9331272424d 100644 --- a/cpp/include/IceUtil/Options.h +++ b/cpp/include/IceUtil/Options.h @@ -6,7 +6,6 @@ #define ICE_UTIL_OPTIONS_H #include -#include #include #include #include @@ -108,8 +107,6 @@ class ICE_API Options bool parseCalled; - IceUtil::RecMutex _m; - Options(const Options&); // Not allowed. void operator=(const Options&); // Not allowed. diff --git a/cpp/include/IceUtil/RecMutex.h b/cpp/include/IceUtil/RecMutex.h deleted file mode 100644 index a0d094362db..00000000000 --- a/cpp/include/IceUtil/RecMutex.h +++ /dev/null @@ -1,107 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#ifndef ICE_UTIL_RMUTEX_H -#define ICE_UTIL_RMUTEX_H - -#include -#include -#include -#include - -namespace IceUtil -{ - -// -// Forward declarations for friend. -// -class Cond; - -// -// Recursive Mutex implementation. -// -class ICE_API RecMutex -{ -public: - - // - // Lock & TryLock typedefs. - // - typedef LockT Lock; - typedef TryLockT TryLock; - - RecMutex(); - RecMutex(const MutexProtocol); - ~RecMutex(); - - // - // Note that lock/tryLock & unlock in general should not be used - // directly. Instead use Lock & TryLock. - // - - void lock() const; - - // - // Returns true if the lock was acquired or was already acquired - // by the calling thread, and false otherwise. - // - bool tryLock() const; - - void unlock() const; - - // - // Returns true if the mutex will unlock when calling unlock() - // (false otherwise). For non-recursive mutexes, this will always - // return true. - // This function is used by the Monitor implementation to know whether - // the Mutex has been locked for the first time, or unlocked for the - // last time (that is another thread is able to acquire the mutex). - // Pre-condition: the mutex must be locked. - // - bool willUnlock() const; - -private: - - void init(const MutexProtocol); - // noncopyable - RecMutex(const RecMutex&); - void operator=(const RecMutex&); - - // - // LockState and the lock/unlock variations are for use by the - // Condition variable implementation. - // -#ifdef _WIN32 - struct LockState - { -# ifdef ICE_HAS_WIN32_CONDVAR - CRITICAL_SECTION* mutex; -# endif - int count; - }; -#else - struct LockState - { - pthread_mutex_t* mutex; - int count; - }; -#endif - - void unlock(LockState&) const; - void lock(LockState&) const; - - friend class Cond; - -#ifdef _WIN32 - mutable CRITICAL_SECTION _mutex; -#else - mutable pthread_mutex_t _mutex; -#endif - - mutable int _count; -}; - -} // End namespace IceUtil - -#endif diff --git a/cpp/msbuild/ice.test.sln b/cpp/msbuild/ice.test.sln index a4fb5008437..b24ba307da3 100644 --- a/cpp/msbuild/ice.test.sln +++ b/cpp/msbuild/ice.test.sln @@ -529,13 +529,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "client", "..\test\IceUtil\s {C7223CC8-0AAA-470B-ACB3-12B9DE75525C} = {C7223CC8-0AAA-470B-ACB3-12B9DE75525C} EndProjectSection EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "priority", "priority", "{3CEFD8CF-0E59-4614-A7BB-AD25F220FAB4}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "client", "..\test\IceUtil\priority\msbuild\client.vcxproj", "{2C646634-969C-4A25-B9F2-ACE22302A89C}" - ProjectSection(ProjectDependencies) = postProject - {C7223CC8-0AAA-470B-ACB3-12B9DE75525C} = {C7223CC8-0AAA-470B-ACB3-12B9DE75525C} - EndProjectSection -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "inputUtil", "inputUtil", "{47D78666-F196-4700-B4B7-D83B75EA23DC}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "client", "..\test\IceUtil\inputUtil\msbuild\client.vcxproj", "{2D412D9D-49F4-4259-A175-D6BBA1E8DFFD}" @@ -1882,14 +1875,6 @@ Global {15F7115E-5CD1-4CC9-9B8C-9C9357801302}.Release|Win32.Build.0 = Release|Win32 {15F7115E-5CD1-4CC9-9B8C-9C9357801302}.Release|x64.ActiveCfg = Release|x64 {15F7115E-5CD1-4CC9-9B8C-9C9357801302}.Release|x64.Build.0 = Release|x64 - {2C646634-969C-4A25-B9F2-ACE22302A89C}.Debug|Win32.ActiveCfg = Debug|Win32 - {2C646634-969C-4A25-B9F2-ACE22302A89C}.Debug|Win32.Build.0 = Debug|Win32 - {2C646634-969C-4A25-B9F2-ACE22302A89C}.Debug|x64.ActiveCfg = Debug|x64 - {2C646634-969C-4A25-B9F2-ACE22302A89C}.Debug|x64.Build.0 = Debug|x64 - {2C646634-969C-4A25-B9F2-ACE22302A89C}.Release|Win32.ActiveCfg = Release|Win32 - {2C646634-969C-4A25-B9F2-ACE22302A89C}.Release|Win32.Build.0 = Release|Win32 - {2C646634-969C-4A25-B9F2-ACE22302A89C}.Release|x64.ActiveCfg = Release|x64 - {2C646634-969C-4A25-B9F2-ACE22302A89C}.Release|x64.Build.0 = Release|x64 {2D412D9D-49F4-4259-A175-D6BBA1E8DFFD}.Debug|Win32.ActiveCfg = Debug|Win32 {2D412D9D-49F4-4259-A175-D6BBA1E8DFFD}.Debug|Win32.Build.0 = Debug|Win32 {2D412D9D-49F4-4259-A175-D6BBA1E8DFFD}.Debug|x64.ActiveCfg = Debug|x64 @@ -2882,8 +2867,6 @@ Global {66CF01A0-7BE5-482E-8D27-6294E691B084} = {5988D9A8-57AD-4D79-8214-E0C4385224B3} {9A5024F6-703B-4A4A-A4CC-ED14F77158FF} = {39AA1944-6915-43F5-B219-EC2DA22F6CBC} {15F7115E-5CD1-4CC9-9B8C-9C9357801302} = {9A5024F6-703B-4A4A-A4CC-ED14F77158FF} - {3CEFD8CF-0E59-4614-A7BB-AD25F220FAB4} = {39AA1944-6915-43F5-B219-EC2DA22F6CBC} - {2C646634-969C-4A25-B9F2-ACE22302A89C} = {3CEFD8CF-0E59-4614-A7BB-AD25F220FAB4} {47D78666-F196-4700-B4B7-D83B75EA23DC} = {39AA1944-6915-43F5-B219-EC2DA22F6CBC} {2D412D9D-49F4-4259-A175-D6BBA1E8DFFD} = {47D78666-F196-4700-B4B7-D83B75EA23DC} {DE878A39-59DE-4F36-B669-68C84D60C93B} = {39AA1944-6915-43F5-B219-EC2DA22F6CBC} diff --git a/cpp/src/Ice/CommunicatorI.h b/cpp/src/Ice/CommunicatorI.h index 0d6df13601c..1bda6063299 100644 --- a/cpp/src/Ice/CommunicatorI.h +++ b/cpp/src/Ice/CommunicatorI.h @@ -5,8 +5,6 @@ #ifndef ICE_COMMUNICATOR_I_H #define ICE_COMMUNICATOR_I_H -#include - #include #include #include diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp index a7d1a3500a8..bb764bf20fb 100644 --- a/cpp/src/Ice/Instance.cpp +++ b/cpp/src/Ice/Instance.cpp @@ -282,7 +282,7 @@ IceInternal::ObserverUpdaterI::updateThreadObservers() bool IceInternal::Instance::destroyed() const { - Lock sync(*this); + lock_guard lock(_mutex); return _state == StateDestroyed; } @@ -305,7 +305,7 @@ IceInternal::Instance::defaultsAndOverrides() const RouterManagerPtr IceInternal::Instance::routerManager() const { - Lock sync(*this); + lock_guard lock(_mutex); if(_state == StateDestroyed) { @@ -319,7 +319,7 @@ IceInternal::Instance::routerManager() const LocatorManagerPtr IceInternal::Instance::locatorManager() const { - Lock sync(*this); + lock_guard lock(_mutex); if(_state == StateDestroyed) { @@ -333,7 +333,7 @@ IceInternal::Instance::locatorManager() const ReferenceFactoryPtr IceInternal::Instance::referenceFactory() const { - Lock sync(*this); + lock_guard lock(_mutex); if(_state == StateDestroyed) { @@ -347,7 +347,7 @@ IceInternal::Instance::referenceFactory() const RequestHandlerFactoryPtr IceInternal::Instance::requestHandlerFactory() const { - Lock sync(*this); + lock_guard lock(_mutex); if(_state == StateDestroyed) { @@ -361,7 +361,7 @@ IceInternal::Instance::requestHandlerFactory() const ProxyFactoryPtr IceInternal::Instance::proxyFactory() const { - Lock sync(*this); + lock_guard lock(_mutex); if(_state == StateDestroyed) { @@ -375,7 +375,7 @@ IceInternal::Instance::proxyFactory() const OutgoingConnectionFactoryPtr IceInternal::Instance::outgoingConnectionFactory() const { - Lock sync(*this); + lock_guard lock(_mutex); if(_state == StateDestroyed) { @@ -389,7 +389,7 @@ IceInternal::Instance::outgoingConnectionFactory() const ObjectAdapterFactoryPtr IceInternal::Instance::objectAdapterFactory() const { - Lock sync(*this); + lock_guard lock(_mutex); if(_state == StateDestroyed) { @@ -421,7 +421,7 @@ IceInternal::Instance::networkProxy() const ThreadPoolPtr IceInternal::Instance::clientThreadPool() { - Lock sync(*this); + lock_guard lock(_mutex); if(_state == StateDestroyed) { @@ -435,7 +435,7 @@ IceInternal::Instance::clientThreadPool() ThreadPoolPtr IceInternal::Instance::serverThreadPool() { - Lock sync(*this); + lock_guard lock(_mutex); if(_state == StateDestroyed) { @@ -458,7 +458,7 @@ IceInternal::Instance::serverThreadPool() EndpointHostResolverPtr IceInternal::Instance::endpointHostResolver() { - Lock sync(*this); + lock_guard lock(_mutex); if(_state == StateDestroyed) { @@ -472,7 +472,7 @@ IceInternal::Instance::endpointHostResolver() RetryQueuePtr IceInternal::Instance::retryQueue() { - Lock sync(*this); + lock_guard lock(_mutex); if(_state == StateDestroyed) { @@ -486,7 +486,7 @@ IceInternal::Instance::retryQueue() IceUtil::TimerPtr IceInternal::Instance::timer() { - Lock sync(*this); + lock_guard lock(_mutex); if(_state == StateDestroyed) { @@ -499,7 +499,7 @@ IceInternal::Instance::timer() EndpointFactoryManagerPtr IceInternal::Instance::endpointFactoryManager() const { - Lock sync(*this); + lock_guard lock(_mutex); if(_state == StateDestroyed) { @@ -513,7 +513,7 @@ IceInternal::Instance::endpointFactoryManager() const DynamicLibraryListPtr IceInternal::Instance::dynamicLibraryList() const { - Lock sync(*this); + lock_guard lock(_mutex); if(_state == StateDestroyed) { @@ -527,7 +527,7 @@ IceInternal::Instance::dynamicLibraryList() const PluginManagerPtr IceInternal::Instance::pluginManager() const { - Lock sync(*this); + lock_guard lock(_mutex); if(_state == StateDestroyed) { @@ -558,7 +558,7 @@ IceInternal::Instance::createAdmin(const ObjectAdapterPtr& adminAdapter, const I ObjectAdapterPtr adapter = adminAdapter; bool createAdapter = !adminAdapter; - Lock sync(*this); + unique_lock lock(_mutex); if(_state == StateDestroyed) { @@ -595,7 +595,7 @@ IceInternal::Instance::createAdmin(const ObjectAdapterPtr& adminAdapter, const I _adminIdentity = adminIdentity; _adminAdapter = adapter; addAllAdminFacets(); - sync.release(); + lock.unlock(); if(createAdapter) { @@ -611,7 +611,7 @@ IceInternal::Instance::createAdmin(const ObjectAdapterPtr& adminAdapter, const I // in the adapter are lost) // adapter->destroy(); - sync.acquire(); + lock.lock(); _adminAdapter = 0; throw; } @@ -623,7 +623,7 @@ IceInternal::Instance::createAdmin(const ObjectAdapterPtr& adminAdapter, const I Ice::ObjectPrxPtr IceInternal::Instance::getAdmin() { - Lock sync(*this); + unique_lock lock(_mutex); if(_state == StateDestroyed) { @@ -657,7 +657,7 @@ IceInternal::Instance::getAdmin() _adminIdentity = adminIdentity; _adminAdapter = adapter; addAllAdminFacets(); - sync.release(); + lock.unlock(); try { adapter->activate(); @@ -670,7 +670,7 @@ IceInternal::Instance::getAdmin() // in the adapter are lost) // adapter->destroy(); - sync.acquire(); + lock.lock(); _adminAdapter = 0; throw; } @@ -758,7 +758,7 @@ IceInternal::Instance::setServerProcessProxy(const ObjectAdapterPtr& adminAdapte void IceInternal::Instance::addAdminFacet(const shared_ptr& servant, const string& facet) { - Lock sync(*this); + lock_guard lock(_mutex); if(_state == StateDestroyed) { @@ -781,7 +781,7 @@ IceInternal::Instance::addAdminFacet(const shared_ptr& servant, const st shared_ptr IceInternal::Instance::removeAdminFacet(const string& facet) { - Lock sync(*this); + lock_guard lock(_mutex); if(_state == StateDestroyed) { @@ -814,7 +814,7 @@ IceInternal::Instance::removeAdminFacet(const string& facet) shared_ptr IceInternal::Instance::findAdminFacet(const string& facet) { - Lock sync(*this); + lock_guard lock(_mutex); if(_state == StateDestroyed) { @@ -846,7 +846,7 @@ IceInternal::Instance::findAdminFacet(const string& facet) FacetMap IceInternal::Instance::findAllAdminFacets() { - Lock sync(*this); + lock_guard lock(_mutex); if(_state == StateDestroyed) { @@ -872,7 +872,7 @@ IceInternal::Instance::findAllAdminFacets() void IceInternal::Instance::setDefaultLocator(const Ice::LocatorPrxPtr& defaultLocator) { - Lock sync(*this); + lock_guard lock(_mutex); if(_state == StateDestroyed) { @@ -885,7 +885,7 @@ IceInternal::Instance::setDefaultLocator(const Ice::LocatorPrxPtr& defaultLocato void IceInternal::Instance::setDefaultRouter(const Ice::RouterPrxPtr& defaultRouter) { - Lock sync(*this); + lock_guard lock(_mutex); if(_state == StateDestroyed) { @@ -1545,17 +1545,14 @@ void IceInternal::Instance::destroy() { { - Lock sync(*this); + unique_lock lock(_mutex); // // If destroy is in progress, wait for it to be done. This is // necessary in case destroy() is called concurrently by // multiple threads. // - while(_state == StateDestroyInProgress) - { - wait(); - } + _conditionVariable.wait(lock, [this] { return _state != StateDestroyInProgress; }); if(_state == StateDestroyed) { @@ -1688,7 +1685,7 @@ IceInternal::Instance::destroy() } { - Lock sync(*this); + lock_guard lock(_mutex); _objectAdapterFactory = 0; _outgoingConnectionFactory = 0; @@ -1712,7 +1709,7 @@ IceInternal::Instance::destroy() _adminFacets.clear(); _state = StateDestroyed; - notifyAll(); + _conditionVariable.notify_all(); } } diff --git a/cpp/src/Ice/Instance.h b/cpp/src/Ice/Instance.h index c7dc5903573..1a5a9d08a2e 100644 --- a/cpp/src/Ice/Instance.h +++ b/cpp/src/Ice/Instance.h @@ -7,7 +7,6 @@ #include #include -#include #include #include #include @@ -75,7 +74,7 @@ struct BufSizeWarnInfo int rcvSize; }; -class Instance : public IceUtil::Shared, public IceUtil::Monitor +class Instance : public IceUtil::Shared { public: @@ -197,6 +196,8 @@ class Instance : public IceUtil::Shared, public IceUtil::Monitor _setBufSizeWarn; std::mutex _setBufSizeWarnMutex; + mutable std::recursive_mutex _mutex; + std::condition_variable_any _conditionVariable; }; class ProcessI : public Ice::Process diff --git a/cpp/src/Ice/ObjectAdapterFactory.cpp b/cpp/src/Ice/ObjectAdapterFactory.cpp index 5c92719e5de..32afc391f82 100644 --- a/cpp/src/Ice/ObjectAdapterFactory.cpp +++ b/cpp/src/Ice/ObjectAdapterFactory.cpp @@ -18,7 +18,7 @@ IceInternal::ObjectAdapterFactory::shutdown() list> adapters; { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); // // Ignore shutdown requests if the object adapter factory has @@ -34,7 +34,7 @@ IceInternal::ObjectAdapterFactory::shutdown() _instance = nullptr; _communicator = nullptr; - notifyAll(); + _conditionVariable.notify_all(); } // Deactivate outside the thread synchronization, to avoid deadlocks. @@ -47,16 +47,12 @@ IceInternal::ObjectAdapterFactory::waitForShutdown() list> adapters; { - IceUtil::Monitor::Lock sync(*this); + unique_lock lock(_mutex); // // First we wait for the shutdown of the factory itself. // - while(_instance) - { - wait(); - } - + _conditionVariable.wait(lock, [this] { return !_instance; }); adapters = _adapters; } @@ -67,7 +63,7 @@ IceInternal::ObjectAdapterFactory::waitForShutdown() bool IceInternal::ObjectAdapterFactory::isShutdown() const { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); return _instance == 0; } @@ -83,14 +79,14 @@ IceInternal::ObjectAdapterFactory::destroy() list> adapters; { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); adapters = _adapters; } // Now we destroy each object adapter. for_each(adapters.begin(), adapters.end(), [](const shared_ptr& adapter) { adapter->destroy(); }); { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); _adapters.clear(); } } @@ -101,7 +97,7 @@ IceInternal::ObjectAdapterFactory::updateObservers(void (ObjectAdapterI::*fn)()) list> adapters; { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); adapters = _adapters; } @@ -117,7 +113,7 @@ IceInternal::ObjectAdapterFactory::createObjectAdapter(const string& name, const { shared_ptr adapter; { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); if(!_instance) { @@ -150,7 +146,7 @@ IceInternal::ObjectAdapterFactory::createObjectAdapter(const string& name, const adapter->initialize(router); initialized = true; - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); if(!_instance) { throw CommunicatorDestroyedException(__FILE__, __LINE__); @@ -169,7 +165,7 @@ IceInternal::ObjectAdapterFactory::createObjectAdapter(const string& name, const { if(!name.empty()) { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); _adapterNamesInUse.erase(name); } throw; @@ -183,7 +179,7 @@ IceInternal::ObjectAdapterFactory::findObjectAdapter(const ObjectPrxPtr& proxy) { list> adapters; { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); if(!_instance) { @@ -214,7 +210,7 @@ IceInternal::ObjectAdapterFactory::findObjectAdapter(const ObjectPrxPtr& proxy) void IceInternal::ObjectAdapterFactory::removeObjectAdapter(const ObjectAdapterPtr& adapter) { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); if(!_instance) { @@ -238,7 +234,7 @@ IceInternal::ObjectAdapterFactory::flushAsyncBatchRequests(const CommunicatorFlu { list> adapters; { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); adapters = _adapters; } diff --git a/cpp/src/Ice/ObjectAdapterFactory.h b/cpp/src/Ice/ObjectAdapterFactory.h index 55ad0f0bf76..0c5443da9fd 100644 --- a/cpp/src/Ice/ObjectAdapterFactory.h +++ b/cpp/src/Ice/ObjectAdapterFactory.h @@ -6,16 +6,15 @@ #define ICE_OBJECT_ADAPTER_FACTORY_H #include -#include -#include #include +#include +#include namespace IceInternal { -class ObjectAdapterFactory : public ::IceUtil::Monitor< ::IceUtil::RecMutex>, - public std::enable_shared_from_this +class ObjectAdapterFactory : public std::enable_shared_from_this { public: @@ -42,6 +41,8 @@ class ObjectAdapterFactory : public ::IceUtil::Monitor< ::IceUtil::RecMutex>, ::Ice::CommunicatorPtr _communicator; std::set _adapterNamesInUse; std::list> _adapters; + mutable std::recursive_mutex _mutex; + std::condition_variable_any _conditionVariable; }; } diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp index 70a93181c03..706156357a6 100644 --- a/cpp/src/Ice/ObjectAdapterI.cpp +++ b/cpp/src/Ice/ObjectAdapterI.cpp @@ -87,7 +87,7 @@ Ice::ObjectAdapterI::activate() bool printAdapterReady = false; { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); checkForDeactivation(); @@ -137,9 +137,9 @@ Ice::ObjectAdapterI::activate() // later. // { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); _state = StateUninitialized; - notifyAll(); + _conditionVariable.notify_all(); } throw; } @@ -150,7 +150,7 @@ Ice::ObjectAdapterI::activate() } { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); assert(_state == StateActivating); for_each(_incomingConnectionFactories.begin(), _incomingConnectionFactories.end(), [](const IncomingConnectionFactoryPtr& factory) @@ -158,14 +158,14 @@ Ice::ObjectAdapterI::activate() factory->activate(); }); _state = StateActive; - notifyAll(); + _conditionVariable.notify_all(); } } void Ice::ObjectAdapterI::hold() { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); checkForDeactivation(); _state = StateHeld; @@ -181,7 +181,7 @@ Ice::ObjectAdapterI::waitForHold() { vector incomingConnectionFactories; { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); checkForDeactivation(); @@ -199,16 +199,14 @@ void Ice::ObjectAdapterI::deactivate() noexcept { { - IceUtil::Monitor::Lock sync(*this); + unique_lock lock(_mutex); // // Wait for activation to complete. This is necessary to not // get out of order locator updates. // - while(_state == StateActivating || _state == StateDeactivating) - { - wait(); - } + _conditionVariable.wait(lock, [this] { return _state != StateActivating && _state != StateDeactivating; }); + if(_state >= StateDeactivated) { return; @@ -255,10 +253,10 @@ Ice::ObjectAdapterI::deactivate() noexcept _instance->outgoingConnectionFactory()->removeAdapter(shared_from_this()); { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); assert(_state == StateDeactivating); _state = StateDeactivated; - notifyAll(); + _conditionVariable.notify_all(); } } @@ -268,16 +266,13 @@ Ice::ObjectAdapterI::waitForDeactivate() noexcept vector incomingConnectionFactories; { - IceUtil::Monitor::Lock sync(*this); + unique_lock lock(_mutex); // // Wait for deactivation of the adapter itself, and for // the return of all direct method calls using this adapter. // - while((_state < StateDeactivated) || _directCount > 0) - { - wait(); - } + _conditionVariable.wait(lock, [this] { return _state >= StateDeactivated && _directCount == 0; }); if(_state > StateDeactivated) { return; @@ -296,7 +291,7 @@ Ice::ObjectAdapterI::waitForDeactivate() noexcept bool Ice::ObjectAdapterI::isDeactivated() const noexcept { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); return _state >= StateDeactivated; } @@ -311,7 +306,7 @@ Ice::ObjectAdapterI::destroy() noexcept waitForDeactivate(); { - IceUtil::Monitor::Lock sync(*this); + unique_lock lock(_mutex); assert(_state >= StateDeactivated); // @@ -319,10 +314,7 @@ Ice::ObjectAdapterI::destroy() noexcept // adapter. Other threads wait for the destruction to be // completed. // - while(_state == StateDestroying) - { - wait(); - } + _conditionVariable.wait(lock, [this] { return _state != StateDestroying; }); if(_state == StateDestroyed) { return; @@ -351,7 +343,7 @@ Ice::ObjectAdapterI::destroy() noexcept } { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); // // We're done, now we can throw away all incoming connection @@ -371,7 +363,7 @@ Ice::ObjectAdapterI::destroy() noexcept _objectAdapterFactory = 0; _state = StateDestroyed; - notifyAll(); + _conditionVariable.notify_all(); } } @@ -384,7 +376,7 @@ Ice::ObjectAdapterI::add(const shared_ptr& object, const Identity& ident ObjectPrxPtr Ice::ObjectAdapterI::addFacet(const shared_ptr& object, const Identity& ident, const string& facet) { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); checkForDeactivation(); checkServant(object); @@ -414,7 +406,7 @@ Ice::ObjectAdapterI::addDefaultServant(const shared_ptr& servant, const { checkServant(servant); - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); checkForDeactivation(); _servantManager->addDefaultServant(servant, category); @@ -429,7 +421,7 @@ Ice::ObjectAdapterI::remove(const Identity& ident) shared_ptr Ice::ObjectAdapterI::removeFacet(const Identity& ident, const string& facet) { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); checkForDeactivation(); checkIdentity(ident); @@ -440,7 +432,7 @@ Ice::ObjectAdapterI::removeFacet(const Identity& ident, const string& facet) FacetMap Ice::ObjectAdapterI::removeAllFacets(const Identity& ident) { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); checkForDeactivation(); checkIdentity(ident); @@ -451,7 +443,7 @@ Ice::ObjectAdapterI::removeAllFacets(const Identity& ident) shared_ptr Ice::ObjectAdapterI::removeDefaultServant(const string& category) { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); checkForDeactivation(); @@ -467,7 +459,7 @@ Ice::ObjectAdapterI::find(const Identity& ident) const shared_ptr Ice::ObjectAdapterI::findFacet(const Identity& ident, const string& facet) const { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); checkForDeactivation(); checkIdentity(ident); @@ -478,7 +470,7 @@ Ice::ObjectAdapterI::findFacet(const Identity& ident, const string& facet) const FacetMap Ice::ObjectAdapterI::findAllFacets(const Identity& ident) const { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); checkForDeactivation(); checkIdentity(ident); @@ -489,7 +481,7 @@ Ice::ObjectAdapterI::findAllFacets(const Identity& ident) const shared_ptr Ice::ObjectAdapterI::findByProxy(const ObjectPrxPtr& proxy) const { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); checkForDeactivation(); @@ -500,7 +492,7 @@ Ice::ObjectAdapterI::findByProxy(const ObjectPrxPtr& proxy) const shared_ptr Ice::ObjectAdapterI::findDefaultServant(const string& category) const { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); checkForDeactivation(); @@ -510,7 +502,7 @@ Ice::ObjectAdapterI::findDefaultServant(const string& category) const void Ice::ObjectAdapterI::addServantLocator(const shared_ptr& locator, const string& prefix) { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); checkForDeactivation(); @@ -520,7 +512,7 @@ Ice::ObjectAdapterI::addServantLocator(const shared_ptr& locator shared_ptr Ice::ObjectAdapterI::removeServantLocator(const string& prefix) { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); checkForDeactivation(); @@ -530,7 +522,7 @@ Ice::ObjectAdapterI::removeServantLocator(const string& prefix) shared_ptr Ice::ObjectAdapterI::findServantLocator(const string& prefix) const { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); checkForDeactivation(); @@ -540,7 +532,7 @@ Ice::ObjectAdapterI::findServantLocator(const string& prefix) const ObjectPrxPtr Ice::ObjectAdapterI::createProxy(const Identity& ident) const { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); checkForDeactivation(); checkIdentity(ident); @@ -551,7 +543,7 @@ Ice::ObjectAdapterI::createProxy(const Identity& ident) const ObjectPrxPtr Ice::ObjectAdapterI::createDirectProxy(const Identity& ident) const { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); checkForDeactivation(); checkIdentity(ident); @@ -562,7 +554,7 @@ Ice::ObjectAdapterI::createDirectProxy(const Identity& ident) const ObjectPrxPtr Ice::ObjectAdapterI::createIndirectProxy(const Identity& ident) const { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); checkForDeactivation(); checkIdentity(ident); @@ -573,7 +565,7 @@ Ice::ObjectAdapterI::createIndirectProxy(const Identity& ident) const void Ice::ObjectAdapterI::setLocator(const LocatorPrxPtr& locator) { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); checkForDeactivation(); @@ -583,7 +575,7 @@ Ice::ObjectAdapterI::setLocator(const LocatorPrxPtr& locator) LocatorPrxPtr Ice::ObjectAdapterI::getLocator() const noexcept { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); if(!_locatorInfo) { @@ -598,7 +590,7 @@ Ice::ObjectAdapterI::getLocator() const noexcept EndpointSeq Ice::ObjectAdapterI::getEndpoints() const noexcept { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); EndpointSeq endpoints; transform(_incomingConnectionFactories.begin(), _incomingConnectionFactories.end(), @@ -617,7 +609,7 @@ Ice::ObjectAdapterI::refreshPublishedEndpoints() vector oldPublishedEndpoints; { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); checkForDeactivation(); oldPublishedEndpoints = _publishedEndpoints; @@ -634,7 +626,7 @@ Ice::ObjectAdapterI::refreshPublishedEndpoints() } catch(const Ice::LocalException&) { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); // // Restore the old published endpoints. @@ -647,7 +639,7 @@ Ice::ObjectAdapterI::refreshPublishedEndpoints() EndpointSeq Ice::ObjectAdapterI::getPublishedEndpoints() const noexcept { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); return EndpointSeq(_publishedEndpoints.begin(), _publishedEndpoints.end()); } @@ -657,7 +649,7 @@ Ice::ObjectAdapterI::setPublishedEndpoints(const EndpointSeq& newEndpoints) LocatorInfoPtr locatorInfo; vector oldPublishedEndpoints; { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); checkForDeactivation(); if(_routerInfo) @@ -681,7 +673,7 @@ Ice::ObjectAdapterI::setPublishedEndpoints(const EndpointSeq& newEndpoints) } catch(const Ice::LocalException&) { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); // // Restore the old published endpoints. @@ -695,7 +687,7 @@ Ice::ObjectAdapterI::setPublishedEndpoints(const EndpointSeq& newEndpoints) dispatch_queue_t Ice::ObjectAdapterI::getDispatchQueue() const { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); checkForDeactivation(); @@ -732,7 +724,7 @@ Ice::ObjectAdapterI::isLocal(const ObjectPrxPtr& proxy) const { vector endpoints = ref->getEndpoints(); - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); checkForDeactivation(); // @@ -769,7 +761,7 @@ Ice::ObjectAdapterI::flushAsyncBatchRequests(const CommunicatorFlushBatchAsyncPt { vector f; { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); f = _incomingConnectionFactories; } @@ -784,7 +776,7 @@ Ice::ObjectAdapterI::updateConnectionObservers() { vector f; { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); f = _incomingConnectionFactories; } for_each(f.begin(), f.end(), @@ -799,7 +791,7 @@ Ice::ObjectAdapterI::updateThreadObservers() { ThreadPoolPtr threadPool; { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); threadPool = _threadPool; } if(threadPool) @@ -811,7 +803,7 @@ Ice::ObjectAdapterI::updateThreadObservers() void Ice::ObjectAdapterI::incDirectCount() { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); checkForDeactivation(); @@ -822,7 +814,7 @@ Ice::ObjectAdapterI::incDirectCount() void Ice::ObjectAdapterI::decDirectCount() { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); // Not check for deactivation here! @@ -831,7 +823,7 @@ Ice::ObjectAdapterI::decDirectCount() assert(_directCount > 0); if(--_directCount == 0) { - notifyAll(); + _conditionVariable.notify_all(); } } @@ -877,7 +869,7 @@ Ice::ObjectAdapterI::getACM() const void Ice::ObjectAdapterI::setAdapterOnConnection(const Ice::ConnectionIPtr& connection) { - IceUtil::Monitor::Lock sync(*this); + lock_guard lock(_mutex); checkForDeactivation(); connection->setAdapterAndServantManager(shared_from_this(), _servantManager); } diff --git a/cpp/src/Ice/ObjectAdapterI.h b/cpp/src/Ice/ObjectAdapterI.h index 561509fcde5..4b299b8ce1d 100644 --- a/cpp/src/Ice/ObjectAdapterI.h +++ b/cpp/src/Ice/ObjectAdapterI.h @@ -6,8 +6,6 @@ #define ICE_OBJECT_ADAPTER_I_H #include -#include -#include #include #include #include @@ -25,14 +23,14 @@ #include #include #include + #include +#include namespace Ice { -class ObjectAdapterI final : public ObjectAdapter, - public IceUtil::Monitor, - public std::enable_shared_from_this +class ObjectAdapterI final : public ObjectAdapter, public std::enable_shared_from_this { public: @@ -146,6 +144,8 @@ class ObjectAdapterI final : public ObjectAdapter, int _directCount; // The number of direct proxies dispatching on this object adapter. bool _noConfig; size_t _messageSizeMax; + mutable std::recursive_mutex _mutex; + std::condition_variable_any _conditionVariable; }; } diff --git a/cpp/src/Ice/PropertiesAdminI.cpp b/cpp/src/Ice/PropertiesAdminI.cpp index 969331a0c23..4116315e13c 100644 --- a/cpp/src/Ice/PropertiesAdminI.cpp +++ b/cpp/src/Ice/PropertiesAdminI.cpp @@ -35,21 +35,21 @@ PropertiesAdminI::PropertiesAdminI(const InstancePtr& instance) : string PropertiesAdminI::getProperty(string name, const Current&) { - Lock sync(*this); + lock_guard lock(_mutex); return _properties->getProperty(name); } PropertyDict PropertiesAdminI::getPropertiesForPrefix(string prefix, const Current&) { - Lock sync(*this); + lock_guard lock(_mutex); return _properties->getPropertiesForPrefix(prefix); } void PropertiesAdminI::setProperties(PropertyDict props, const Current&) { - Lock sync(*this); + lock_guard lock(_mutex); PropertyDict old = _properties->getPropertiesForPrefix(""); PropertyDict::const_iterator p; @@ -199,7 +199,7 @@ PropertiesAdminI::setProperties(PropertyDict props, const Current&) std::function PropertiesAdminI::addUpdateCallback(std::function cb) { - Lock sync(*this); + lock_guard lock(_mutex); auto p = _updateCallbacks.insert(_updateCallbacks.end(), std::move(cb)); auto propertiesAdmin = shared_from_this(); @@ -210,7 +210,7 @@ PropertiesAdminI::addUpdateCallback(std::function>::iterator p) { - Lock sync(*this); + lock_guard lock(_mutex); _updateCallbacks.erase(p); } diff --git a/cpp/src/Ice/PropertiesAdminI.h b/cpp/src/Ice/PropertiesAdminI.h index fffc17661c2..9f326320815 100644 --- a/cpp/src/Ice/PropertiesAdminI.h +++ b/cpp/src/Ice/PropertiesAdminI.h @@ -5,20 +5,20 @@ #ifndef ICE_PROPERTIES_ADMIN_I_H #define ICE_PROPERTIES_ADMIN_I_H -#include #include #include #include #include #include +#include + namespace IceInternal { class PropertiesAdminI final : public Ice::PropertiesAdmin, public Ice::NativePropertiesAdmin, - public std::enable_shared_from_this, - private IceUtil::RecMutex + public std::enable_shared_from_this { public: @@ -36,6 +36,7 @@ class PropertiesAdminI final : public Ice::PropertiesAdmin, const Ice::PropertiesPtr _properties; const Ice::LoggerPtr _logger; + std::recursive_mutex _mutex; std::list> _updateCallbacks; }; diff --git a/cpp/src/Ice/Selector.cpp b/cpp/src/Ice/Selector.cpp index 601786a9898..16559fb11c9 100644 --- a/cpp/src/Ice/Selector.cpp +++ b/cpp/src/Ice/Selector.cpp @@ -1264,11 +1264,8 @@ Selector::Selector(const InstancePtr& instance) : _instance(instance), _destroye _thread = new SelectorHelperThread(*this); _thread->start(); - Lock sync(*this); - while(!_runLoop) - { - wait(); - } + unique_lock lock(_mutex); + _conditionVariable.wait(lock, [this] { return _runLoop != 0; }); } Selector::~Selector() @@ -1279,7 +1276,7 @@ void Selector::destroy() { { - Lock sync(*this); + lock_guard lock(_mutex); // // Make sure any pending changes are processed to ensure remaining @@ -1301,7 +1298,7 @@ Selector::destroy() _thread->getThreadControl().join(); _thread = 0; - Lock sync(*this); + lock_guard lock(_mutex); _source.reset(0); //assert(_wrappers.empty()); @@ -1312,26 +1309,26 @@ Selector::destroy() void Selector::initialize(EventHandler* handler) { - Lock sync(*this); + lock_guard lock(_mutex); _wrappers[handler] = new EventHandlerWrapper(handler, *this); } void Selector::update(EventHandler* handler, SocketOperation remove, SocketOperation add) { - Lock sync(*this); + lock_guard lock(_mutex); const EventHandlerWrapperPtr& wrapper = _wrappers[handler]; if(wrapper->update(remove, add)) { _changes.insert(wrapper); - notify(); + _conditionVariable.notify_one(); } } void Selector::enable(EventHandler* handler, SocketOperation op) { - Lock sync(*this); + lock_guard lock(_mutex); if(!(handler->_disabled & op)) { return; @@ -1347,7 +1344,7 @@ Selector::enable(EventHandler* handler, SocketOperation op) void Selector::disable(EventHandler* handler, SocketOperation op) { - Lock sync(*this); + lock_guard lock(_mutex); if(handler->_disabled & op) { return; @@ -1358,14 +1355,14 @@ Selector::disable(EventHandler* handler, SocketOperation op) bool Selector::finish(EventHandler* handler, bool closeNow) { - Lock sync(*this); + lock_guard lock(_mutex); std::map::iterator p = _wrappers.find(handler); assert(p != _wrappers.end()); EventHandlerWrapperPtr wrapper = p->second; if(wrapper->finish()) { _changes.insert(wrapper); - notify(); + _conditionVariable.notify_one(); } _wrappers.erase(p); return closeNow; @@ -1388,7 +1385,7 @@ Selector::ready(EventHandler* handler, SocketOperation status, bool value) handler->_ready = static_cast(handler->_ready & ~status); } - Lock sync(*this); + lock_guard lock(_mutex); std::map::iterator p = _wrappers.find(handler); assert(p != _wrappers.end()); p->second->checkReady(); @@ -1397,7 +1394,7 @@ Selector::ready(EventHandler* handler, SocketOperation status, bool value) void Selector::startSelect() { - Lock sync(*this); + lock_guard lock(_mutex); // // Re-enable callbacks for previously selected handlers. @@ -1416,7 +1413,7 @@ Selector::startSelect() void Selector::finishSelect(std::vector >& handlers) { - Lock sync(*this); + lock_guard lock(_mutex); handlers.clear(); for(set::const_iterator p = _readyHandlers.begin(); p != _readyHandlers.end(); ++p) { @@ -1436,7 +1433,7 @@ Selector::select(int timeout) // // Wait for handlers to be ready. // - Lock sync(*this); + unique_lock lock(_mutex); while(!_destroyed) { while(!_changes.empty()) @@ -1444,23 +1441,20 @@ Selector::select(int timeout) CFRunLoopSourceSignal(_source.get()); CFRunLoopWakeUp(_runLoop); - wait(); + _conditionVariable.wait(lock); } - if(_readyHandlers.empty()) + if(timeout > 0) { - if(timeout > 0) - { - if(!timedWait(IceUtil::Time::seconds(timeout))) - { - break; - } - } - else + if(_conditionVariable.wait_for(chrono::seconds(timeout) == cv_status::no_timeout)) { - wait(); + break; } } + else + { + _conditionVariable.wait(lock, [this] { return !_readyHandlers.empty(); }); + } if(_changes.empty()) { @@ -1472,7 +1466,7 @@ Selector::select(int timeout) void Selector::processInterrupt() { - Lock sync(*this); + lock_guard lock(_mutex); if(!_changes.empty()) { for(set::const_iterator p = _changes.begin(); p != _changes.end(); ++p) @@ -1480,7 +1474,7 @@ Selector::processInterrupt() (*p)->updateRunLoop(); } _changes.clear(); - notify(); + _conditionVariable.notify_one(); } if(_destroyed) { @@ -1492,9 +1486,9 @@ void Selector::run() { { - Lock sync(*this); + lock_guard lock(_mutex); _runLoop = CFRunLoopGetCurrent(); - notify(); + _conditionVariable.notify_one(); } CFRunLoopAddSource(CFRunLoopGetCurrent(), _source.get(), kCFRunLoopDefaultMode); @@ -1505,7 +1499,7 @@ Selector::run() void Selector::ready(EventHandlerWrapper* wrapper, SocketOperation op, int error) { - Lock sync(*this); + lock_guard lock(_mutex); wrapper->ready(op, error); } @@ -1516,7 +1510,7 @@ Selector::addReadyHandler(EventHandlerWrapper* wrapper) _readyHandlers.insert(wrapper); if(_readyHandlers.size() == 1) { - notify(); + _conditionVariable.notify_one(); } } diff --git a/cpp/src/Ice/Selector.h b/cpp/src/Ice/Selector.h index c44f6ac28c8..e7acc6ff5ae 100644 --- a/cpp/src/Ice/Selector.h +++ b/cpp/src/Ice/Selector.h @@ -6,8 +6,6 @@ #define ICE_SELECTOR_H #include -#include -#include #include #include @@ -25,7 +23,6 @@ #endif #if defined(ICE_USE_CFSTREAM) -# include # include # include @@ -241,7 +238,7 @@ class EventHandlerWrapper : public SelectorReadyCallback }; typedef IceUtil::Handle EventHandlerWrapperPtr; -class Selector : IceUtil::Monitor +class Selector { public: @@ -284,6 +281,8 @@ class Selector : IceUtil::Monitor std::set _readyHandlers; std::vector > _selectedHandlers; std::map _wrappers; + std::recursive_mutex _mutex; + std::condition_variable_any; }; #endif diff --git a/cpp/src/Ice/msbuild/ice/ice.vcxproj b/cpp/src/Ice/msbuild/ice/ice.vcxproj index ced469e5e29..a6a9f8a78c3 100644 --- a/cpp/src/Ice/msbuild/ice/ice.vcxproj +++ b/cpp/src/Ice/msbuild/ice/ice.vcxproj @@ -495,7 +495,6 @@ - @@ -935,4 +934,4 @@ - \ No newline at end of file + diff --git a/cpp/src/Ice/msbuild/ice/ice.vcxproj.filters b/cpp/src/Ice/msbuild/ice/ice.vcxproj.filters index 288b5fa28df..e17a6b618cd 100644 --- a/cpp/src/Ice/msbuild/ice/ice.vcxproj.filters +++ b/cpp/src/Ice/msbuild/ice/ice.vcxproj.filters @@ -234,9 +234,6 @@ Source Files - - Source Files - Source Files @@ -835,4 +832,4 @@ Slice Files - \ No newline at end of file + diff --git a/cpp/src/IceUtil/Options.cpp b/cpp/src/IceUtil/Options.cpp index cd4575ea6b3..63515b664a1 100644 --- a/cpp/src/IceUtil/Options.cpp +++ b/cpp/src/IceUtil/Options.cpp @@ -132,8 +132,6 @@ IceUtilInternal::Options::checkArgs(const string& shortOpt, const string& longOp void IceUtilInternal::Options::addOpt(const string& shortOpt, const string& longOpt, ArgType at, string dflt, RepeatType rt) { - RecMutex::Lock sync(_m); - if(parseCalled) { throw APIException(__FILE__, __LINE__, "cannot add options after parse() was called"); @@ -550,8 +548,6 @@ IceUtilInternal::Options::split(const string& line) IceUtilInternal::Options::StringVector IceUtilInternal::Options::parse(const StringVector& args) { - RecMutex::Lock sync(_m); - if(parseCalled) { throw APIException(__FILE__, __LINE__, "cannot call parse() more than once on the same Option instance"); @@ -738,8 +734,6 @@ IceUtilInternal::Options::parse(int argc, const char* const argv[]) bool IceUtilInternal::Options::isSet(const string& opt) const { - RecMutex::Lock sync(_m); - if(!parseCalled) { throw APIException(__FILE__, __LINE__, "cannot lookup options before calling parse()"); @@ -752,8 +746,6 @@ IceUtilInternal::Options::isSet(const string& opt) const string IceUtilInternal::Options::optArg(const string& opt) const { - RecMutex::Lock sync(_m); - if(!parseCalled) { throw APIException(__FILE__, __LINE__, "cannot lookup options before calling parse()"); @@ -784,8 +776,6 @@ IceUtilInternal::Options::optArg(const string& opt) const IceUtilInternal::Options::StringVector IceUtilInternal::Options::argVec(const string& opt) const { - RecMutex::Lock sync(_m); - if(!parseCalled) { throw APIException(__FILE__, __LINE__, "cannot lookup options before calling parse()"); diff --git a/cpp/src/IceUtil/RecMutex.cpp b/cpp/src/IceUtil/RecMutex.cpp deleted file mode 100644 index 94a61b3070b..00000000000 --- a/cpp/src/IceUtil/RecMutex.cpp +++ /dev/null @@ -1,238 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#include -#include - -using namespace std; - -IceUtil::RecMutex::RecMutex() : - _count(0) -{ -#ifdef _WIN32 - init(PrioNone); -#else - init(getDefaultMutexProtocol()); -#endif -} - -IceUtil::RecMutex::RecMutex(const IceUtil::MutexProtocol protocol) : - _count(0) -{ - init(protocol); -} - -#ifdef _WIN32 - -void -IceUtil::RecMutex::init(const MutexProtocol) -{ - InitializeCriticalSection(&_mutex); -} - -IceUtil::RecMutex::~RecMutex() -{ - assert(_count == 0); - DeleteCriticalSection(&_mutex); -} - -void -IceUtil::RecMutex::lock() const -{ - EnterCriticalSection(&_mutex); - if(++_count > 1) - { - LeaveCriticalSection(&_mutex); - } -} - -bool -IceUtil::RecMutex::tryLock() const -{ - if(!TryEnterCriticalSection(&_mutex)) - { - return false; - } - if(++_count > 1) - { - LeaveCriticalSection(&_mutex); - } - return true; -} - -void -IceUtil::RecMutex::unlock() const -{ - if(--_count == 0) - { - LeaveCriticalSection(&_mutex); - } -} - -# ifdef ICE_HAS_WIN32_CONDVAR -void -IceUtil::RecMutex::unlock(LockState& state) const -{ - state.mutex = &_mutex; - state.count = _count; - _count = 0; -} - -void -IceUtil::RecMutex::lock(LockState& state) const -{ - _count = state.count; -} -# else -void -IceUtil::RecMutex::unlock(LockState& state) const -{ - state.count = _count; - _count = 0; - LeaveCriticalSection(&_mutex); -} - -void -IceUtil::RecMutex::lock(LockState& state) const -{ - EnterCriticalSection(&_mutex); - _count = state.count; -} -# endif - -#else - -void -IceUtil::RecMutex::init(ICE_MAYBE_UNUSED const MutexProtocol protocol) -{ - int rc; - pthread_mutexattr_t attr; - rc = pthread_mutexattr_init(&attr); - assert(rc == 0); - if(rc != 0) - { - pthread_mutexattr_destroy(&attr); - throw ThreadSyscallException(__FILE__, __LINE__, rc); - } - - rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); - assert(rc == 0); - if(rc != 0) - { - pthread_mutexattr_destroy(&attr); - throw ThreadSyscallException(__FILE__, __LINE__, rc); - } - -#if defined(_POSIX_THREAD_PRIO_INHERIT) && _POSIX_THREAD_PRIO_INHERIT > 0 - if(PrioInherit == protocol) - { - rc = pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT); - assert(rc == 0); - if(rc != 0) - { - throw ThreadSyscallException(__FILE__, __LINE__, rc); - } - } -#endif - - rc = pthread_mutex_init(&_mutex, &attr); - assert(rc == 0); - if(rc != 0) - { - pthread_mutexattr_destroy(&attr); - throw ThreadSyscallException(__FILE__, __LINE__, rc); - } - - rc = pthread_mutexattr_destroy(&attr); - assert(rc == 0); - if(rc != 0) - { - throw ThreadSyscallException(__FILE__, __LINE__, rc); - } -} - -IceUtil::RecMutex::~RecMutex() -{ - assert(_count == 0); -#ifndef NDEBUG - int rc = pthread_mutex_destroy(&_mutex); - assert(rc == 0); -#else - pthread_mutex_destroy(&_mutex); -#endif -} - -void -IceUtil::RecMutex::lock() const -{ - int rc = pthread_mutex_lock(&_mutex); - if(rc != 0) - { - throw ThreadSyscallException(__FILE__, __LINE__, rc); - } - if(++_count > 1) - { - rc = pthread_mutex_unlock(&_mutex); - assert(rc == 0); - } -} - -bool -IceUtil::RecMutex::tryLock() const -{ - int rc = pthread_mutex_trylock(&_mutex); - bool result = (rc == 0); - if(!result) - { - if(rc != EBUSY) - { - throw ThreadSyscallException(__FILE__, __LINE__, rc); - } - } - else if(++_count > 1) - { - rc = pthread_mutex_unlock(&_mutex); - if(rc != 0) - { - throw ThreadSyscallException(__FILE__, __LINE__, rc); - } - } - return result; -} - -void -IceUtil::RecMutex::unlock() const -{ - if(--_count == 0) - { -#ifndef NDEBUG - int rc = pthread_mutex_unlock(&_mutex); - assert(rc == 0); -#else - pthread_mutex_unlock(&_mutex); -#endif - } -} - -void -IceUtil::RecMutex::unlock(LockState& state) const -{ - state.mutex = &_mutex; - state.count = _count; - _count = 0; -} - -void -IceUtil::RecMutex::lock(LockState& state) const -{ - _count = state.count; -} - -#endif - -bool -IceUtil::RecMutex::willUnlock() const -{ - return _count == 1; -} diff --git a/cpp/src/IceUtil/msbuild/iceutil/iceutil.vcxproj b/cpp/src/IceUtil/msbuild/iceutil/iceutil.vcxproj index 66254ccd03a..185f733b203 100644 --- a/cpp/src/IceUtil/msbuild/iceutil/iceutil.vcxproj +++ b/cpp/src/IceUtil/msbuild/iceutil/iceutil.vcxproj @@ -90,7 +90,6 @@ - @@ -126,7 +125,6 @@ - diff --git a/cpp/src/IceUtil/msbuild/iceutil/iceutil.vcxproj.filters b/cpp/src/IceUtil/msbuild/iceutil/iceutil.vcxproj.filters index c502072cadf..701a393df67 100644 --- a/cpp/src/IceUtil/msbuild/iceutil/iceutil.vcxproj.filters +++ b/cpp/src/IceUtil/msbuild/iceutil/iceutil.vcxproj.filters @@ -46,9 +46,6 @@ Source Files - - Source Files - Source Files @@ -127,9 +124,6 @@ Header Files - - Header Files - Header Files diff --git a/cpp/test/IceUtil/priority/Client.cpp b/cpp/test/IceUtil/priority/Client.cpp deleted file mode 100644 index ce621805637..00000000000 --- a/cpp/test/IceUtil/priority/Client.cpp +++ /dev/null @@ -1,51 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#include - -#include -#include -#include -#include - -using namespace std; - -#ifndef _WIN32 - -namespace IceUtil -{ - -ICE_API MutexProtocol -getDefaultMutexProtocol() -{ -# if defined(_POSIX_THREAD_PRIO_INHERIT) && _POSIX_THREAD_PRIO_INHERIT > 0 - return PrioInherit; -# else - return PrioNone; -# endif -} - -} - -#endif - -class Client : public Test::TestHelper -{ -public: - - void run(int, char**); -}; - -void -Client::run(int, char**) -{ - initializeTestSuite(); - - for(list::const_iterator p = allTests.begin(); p != allTests.end(); ++p) - { - (*p)->start(); - } -} - -DEFINE_TEST(Client) diff --git a/cpp/test/IceUtil/priority/Makefile.mk b/cpp/test/IceUtil/priority/Makefile.mk deleted file mode 100644 index c1ce456b3c9..00000000000 --- a/cpp/test/IceUtil/priority/Makefile.mk +++ /dev/null @@ -1,7 +0,0 @@ -# -# Copyright (c) ZeroC, Inc. All rights reserved. -# - -$(test)_client_sources := $(notdir $(wildcard $(currentdir)/*.cpp)) - -tests += $(test) diff --git a/cpp/test/IceUtil/priority/PriorityInversion.cpp b/cpp/test/IceUtil/priority/PriorityInversion.cpp deleted file mode 100644 index 4666dde268b..00000000000 --- a/cpp/test/IceUtil/priority/PriorityInversion.cpp +++ /dev/null @@ -1,441 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#ifndef _WIN32 -#include -#endif - -using namespace std; -using namespace IceUtil; - -class TaskCollector : public IceUtil::Shared -{ -public: - - TaskCollector(int cores, int high, int medium, int low, Monitor& monitor) : - _lowBegin(0), - _lowEnd(0), - _mediumBegin(0), - _mediumEnd(0), - _highBegin(0), - _cores(cores), - _high(high), - _medium(medium), - _low(low), - _acquired(0), - _monitor(monitor) - { - } - - void waitAcquired() - { - Monitor::Lock lock(_monitor); - while(_acquired == 0) - { - _monitor.wait(); - } - } - - void acquired() - { - Monitor::Lock lock(_monitor); - ++_acquired; - _monitor.notifyAll(); - } - - void waitAll() - { - Monitor::Lock lock(_monitor); - while(_mediumBegin < _cores || _highBegin == 0) - { - //Wait until all task are ready to compete by processors - _monitor.wait(); - } - } - - void taskBegin(int priority) - { - Monitor::Lock lock(_monitor); - if(priority == _low) - { - _lowBegin++; - } - else if(priority == _medium) - { - _mediumBegin++; - } - else if(priority == _high) - { - _highBegin++; - } - _monitor.notifyAll(); - } - - void taskEnd(int priority) - { - Monitor::Lock lock(_monitor); - // - // Test all task begin run before any task ends. - // - test(_lowBegin == 1); - test(_highBegin == 1); - test(_mediumBegin == _cores); - if(priority == _low) - { - // - // Low priority thread should end before all medium priority threads. - // - test(_mediumEnd == 0); - _lowEnd++; - } - else if(priority == _medium) - { - // - // When the first medium priority task end the - // low priority task completed. - // - test(_lowEnd > 0); - _mediumEnd++; - } - } - -private: - - int _lowBegin; - int _lowEnd; - int _mediumBegin; - int _mediumEnd; - int _highBegin; - int _cores; - int _high; - int _medium; - int _low; - int _acquired; - Monitor& _monitor; - IceUtil::Mutex _mutex; -}; -typedef IceUtil::Handle TaskCollectorPtr; - -class SharedResource : public IceUtil::Shared -{ -public: - - SharedResource(const TaskCollectorPtr& taskCollector) : - _taskCollector(taskCollector) - { - } - - TaskCollectorPtr taskCollector() const { return _taskCollector; } - - virtual void run(int priority) = 0; - -private: - - TaskCollectorPtr _taskCollector; -}; -typedef IceUtil::Handle SharedResourcePtr; - -class SharedResourceMutex : public SharedResource -{ -public: - - SharedResourceMutex(const TaskCollectorPtr& taskCollector) : - SharedResource(taskCollector) - { - } - - virtual void run(int priority) - { - taskCollector()->taskBegin(priority); - Mutex::Lock lock(_mutex); - taskCollector()->acquired(); - taskCollector()->waitAll(); - // - // If this is the low priority thread we ensure the test runs at least timeout - // seconds this ensure that it doesn't terminate righ away and medium priority - // threads will take over all available cores - // - IceUtil::Time t = IceUtil::Time::now(IceUtil::Time::Monotonic); - IceUtil::Time timeout = IceUtil::Time::seconds(2); - if(priority == 1) - { - while(true) - { - if(IceUtil::Time::now(IceUtil::Time::Monotonic) - t > timeout) - { - break; - } - } - } - taskCollector()->taskEnd(priority); - } - -private: - - IceUtil::Mutex _mutex; -}; - -class SharedResourceRecMutex : public SharedResource -{ -public: - - SharedResourceRecMutex(const TaskCollectorPtr& taskCollector) : - SharedResource(taskCollector) - { - } - - void run(int priority) - { - taskCollector()->taskBegin(priority); - RecMutex::Lock lock(_mutex); - taskCollector()->acquired(); - taskCollector()->waitAll(); - // - // If this is the low priority thread we ensure the test runs at least timeout - // seconds this ensure that it doesn't terminate righ away and medium priority - // threads will take over all available cores - // - IceUtil::Time t = IceUtil::Time::now(IceUtil::Time::Monotonic); - IceUtil::Time timeout = IceUtil::Time::seconds(2); - if(priority == 1) - { - while(true) - { - if(IceUtil::Time::now(IceUtil::Time::Monotonic) - t > timeout) - { - break; - } - } - } - taskCollector()->taskEnd(priority); - } - -private: - - IceUtil::RecMutex _mutex; -}; - -class ThreadCommon : public IceUtil::Thread -{ -public: - - virtual void run() = 0; - int getPriority() - { -#ifdef _WIN32_WCE - return CeGetThreadPriority(GetCurrentThread()); -#elif defined _WIN32 - return GetThreadPriority(GetCurrentThread()); -#else - sched_param param; - int sched_policy; - pthread_t thread = pthread_self(); - pthread_getschedparam(thread, &sched_policy, ¶m); - return param.sched_priority; -#endif - } -}; - -class Task : public ThreadCommon -{ -public: - - Task(const SharedResourcePtr& shared) : - _shared(shared) - { - } - - virtual void run() - { - _shared->run(getPriority()); - } - - void waitAcquired() - { - _shared->taskCollector()->waitAcquired(); - } - -private: - - SharedResourcePtr _shared; -}; -typedef IceUtil::Handle TaskPtr; - -class MediumPriorityThread : public ThreadCommon -{ -public: - - MediumPriorityThread(const TaskCollectorPtr& taskCollector, const ThreadPtr& highPriorityThread, int timeout) : - _taskCollector(taskCollector), - _highPriorityThread(highPriorityThread), - _timeout(IceUtil::Time::seconds(timeout)) - { - } - - virtual void run() - { - IceUtil::Time timestamp = IceUtil::Time::now(IceUtil::Time::Monotonic); - _taskCollector->taskBegin(getPriority()); - while(true) - { - if(IceUtil::Time::now(IceUtil::Time::Monotonic) - timestamp > _timeout) - { - // If high priority task do not end with the specific timeout means - // that the low priority task priority was not bosted so we are having - // the clasic priority inversion issue. - test(false); - } - if(!_highPriorityThread->isAlive()) - { - break; - } - } - _taskCollector->taskEnd(getPriority()); - } - -private: - - const TaskCollectorPtr _taskCollector; - const ThreadPtr _highPriorityThread; - const IceUtil::Time _timeout; -}; - -static const string priorityTestName("priority inversion"); - -PriorityInversionTest::PriorityInversionTest() : - TestBase(priorityTestName) -{ -} - -void -PriorityInversionTest::run() -{ - -#ifdef _WIN32 - return; //Priority inversion is not supported by WIN32 -#else - int cores, high, medium, low, timeout; - timeout = 30; - try - { - IceUtil::Mutex m; - } - catch(const IceUtil::ThreadSyscallException&) - { - return; // Mutex protocol PrioInherit not supported - } - cores = static_cast(sysconf(_SC_NPROCESSORS_ONLN)); - high = 45; - medium = 35; - low = 1; - - { - Monitor monitor; - TaskCollectorPtr collector = new TaskCollector(cores, high, medium, low, monitor); - vector threads; - - SharedResourcePtr shared = new SharedResourceMutex(collector); - - // - // Create one low priority thread. - // - TaskPtr lowThread = new Task(shared); - threads.push_back(lowThread->start(128, low)); - lowThread->waitAcquired(); - - // - // Create one high priority thread that use the same shared resource - // as the previous low priority thread - // - TaskPtr highThread = new Task(shared); - threads.push_back(highThread->start(128, high)); - - // - // Create one medium priority thread per core. - // - for(int cont = 0; cont < cores; ++cont) - { - ThreadPtr t = new MediumPriorityThread(collector, highThread, timeout); - threads.push_back(t->start(128, medium)); - } - // - // Join with all the threads. - // - vector::iterator it; - for(it = threads.begin(); it != threads.end(); ++it) - { - try - { - (*it).join(); - } - catch(...) - { - } - } - } - - // - // Same test with a recursive mutex. - // - { - Monitor monitor; - TaskCollectorPtr collector = new TaskCollector(cores, high, medium, low, monitor); - - SharedResourcePtr shared = new SharedResourceRecMutex(collector); - - vector threads; - - // - // Create one low priority thread. - // - TaskPtr lowThread = new Task(shared); - threads.push_back(lowThread->start(128, low)); - lowThread->waitAcquired(); - - // - // Create one high priority thread that use the same shared resource - // as the previous low priority thread. - // - ThreadPtr highThread = new Task(shared); - threads.push_back(highThread->start(128, high)); - - // - // Create one medium priority tasks per core that runs until - // the high priority thread is running. - // - for(int cont = 0; cont < cores; ++cont) - { - ThreadPtr t = new MediumPriorityThread(collector, highThread, timeout); - threads.push_back(t->start(128, medium)); - } - - // - // Join with all the threads. - // - vector::iterator it; - for(it = threads.begin(); it != threads.end(); ++it) - { - try - { - (*it).join(); - } - catch(...) - { - } - } - } -#endif -} diff --git a/cpp/test/IceUtil/priority/PriorityInversion.h b/cpp/test/IceUtil/priority/PriorityInversion.h deleted file mode 100644 index b1f9e16571d..00000000000 --- a/cpp/test/IceUtil/priority/PriorityInversion.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#ifndef PRIORITY_INVERSION_TEST_H -#define PRIORITY_INVERSION_TEST_H - -#include - -class PriorityInversionTest : public TestBase -{ -public: - - PriorityInversionTest(); - -private: - - virtual void run(); -}; - -#endif diff --git a/cpp/test/IceUtil/priority/TestBase.cpp b/cpp/test/IceUtil/priority/TestBase.cpp deleted file mode 100644 index 7d5de7d864b..00000000000 --- a/cpp/test/IceUtil/priority/TestBase.cpp +++ /dev/null @@ -1,41 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#include - -#include - -using namespace std; - -TestFailed::TestFailed(const std::string& n) : - name(n) -{ -} - -TestBase::TestBase(const std::string& n) : - _name(n) -{ -} - -string -TestBase::name() const -{ - return _name; -} - -void -TestBase::start() -{ - cout << "running " << _name << " test... " << flush; - try - { - run(); - } - catch(const IceUtil::Exception& e) - { - cout << e << " failed" << endl; - throw TestFailed(_name); - } - cout << "ok" << endl; -} diff --git a/cpp/test/IceUtil/priority/TestBase.h b/cpp/test/IceUtil/priority/TestBase.h deleted file mode 100644 index 0d76d3612db..00000000000 --- a/cpp/test/IceUtil/priority/TestBase.h +++ /dev/null @@ -1,38 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#ifndef TEST_BASE_H -#define TEST_BASE_H - -#include -#include - -class TestFailed -{ -public: - - TestFailed(const std::string&); - - const std::string name; -}; - -class TestBase : public IceUtil::Shared -{ -public: - - TestBase(const std::string&); - - std::string name() const; - void start(); - -protected: - - virtual void run() = 0; - - const std::string _name; -}; - -typedef IceUtil::Handle TestBasePtr; - -#endif diff --git a/cpp/test/IceUtil/priority/TestSuite.cpp b/cpp/test/IceUtil/priority/TestSuite.cpp deleted file mode 100644 index 2e59564b809..00000000000 --- a/cpp/test/IceUtil/priority/TestSuite.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#include - -#include -#include -#include -#include - -std::list allTests; - -void -initializeTestSuite() -{ - allTests.push_back(new ThreadPriorityTest); - allTests.push_back(new TimerPriorityTest); - if(IceUtil::getDefaultMutexProtocol() == IceUtil::PrioInherit) - { - allTests.push_back(new PriorityInversionTest); - } -} diff --git a/cpp/test/IceUtil/priority/TestSuite.h b/cpp/test/IceUtil/priority/TestSuite.h deleted file mode 100644 index f4a7543dfde..00000000000 --- a/cpp/test/IceUtil/priority/TestSuite.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#ifndef TEST_SUITE_H -#define TEST_SUITE_H - -#include -#include - -extern std::list allTests; - -void initializeTestSuite(); - -#endif diff --git a/cpp/test/IceUtil/priority/ThreadPriority.cpp b/cpp/test/IceUtil/priority/ThreadPriority.cpp deleted file mode 100644 index 796f08bac2a..00000000000 --- a/cpp/test/IceUtil/priority/ThreadPriority.cpp +++ /dev/null @@ -1,198 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#include - -#include -#include - -using namespace std; -using namespace IceUtil; - -class PriorityTestThread : public Thread -{ -public: - - PriorityTestThread() : - _priority(-1024) //Initialize to some strange value, so by default is not a valid priority - { - } - - virtual void run() - { -#ifdef _WIN32 - _priority = GetThreadPriority(GetCurrentThread()); -#else - sched_param param; - int sched_policy; - pthread_t thread = pthread_self(); - pthread_getschedparam(thread, &sched_policy, ¶m); - _priority = param.sched_priority; -#endif - } - - int getPriority() - { - return _priority; - } - -private: - - int _priority; -}; - -typedef Handle PriorityTestThreadPtr; - -static const string priorityTestName("priority"); - -ThreadPriorityTest::ThreadPriorityTest() : - TestBase(priorityTestName) -{ -#ifdef _WIN32 - ThreadControl c; - try - { - PriorityTestThreadPtr t1 = new PriorityTestThread(); - c = t1->start(128, THREAD_PRIORITY_IDLE); - c.join(); - test(t1->getPriority() == THREAD_PRIORITY_IDLE); - - t1 = new PriorityTestThread(); - c = t1->start(128, THREAD_PRIORITY_LOWEST); - c.join(); - test(t1->getPriority() == THREAD_PRIORITY_LOWEST); - - t1 = new PriorityTestThread(); - c = t1->start(128, THREAD_PRIORITY_BELOW_NORMAL); - c.join(); - test(t1->getPriority() == THREAD_PRIORITY_BELOW_NORMAL); - - t1 = new PriorityTestThread(); - c = t1->start(128, THREAD_PRIORITY_NORMAL); - c.join(); - test(t1->getPriority() == THREAD_PRIORITY_NORMAL); - - t1 = new PriorityTestThread(); - c = t1->start(128, THREAD_PRIORITY_ABOVE_NORMAL); - c.join(); - test(t1->getPriority() == THREAD_PRIORITY_ABOVE_NORMAL); - - t1 = new PriorityTestThread(); - c = t1->start(128, THREAD_PRIORITY_HIGHEST); - c.join(); - test(t1->getPriority() == THREAD_PRIORITY_HIGHEST); - - t1 = new PriorityTestThread(); - c = t1->start(128, THREAD_PRIORITY_TIME_CRITICAL); - c.join(); - test(t1->getPriority() == THREAD_PRIORITY_TIME_CRITICAL); - } - catch(...) - { - test(false); - } - - // - // Test to set invalid priorities too high - // - try - { - PriorityTestThreadPtr t1 = new PriorityTestThread(); - c = t1->start(128, THREAD_PRIORITY_TIME_CRITICAL + 10); - test(false); - } - catch(const ThreadSyscallException&) - { - //Expected - } - catch(...) - { - test(false); - } - - // - // Test to set invalid priorities too low - // - try - { - PriorityTestThreadPtr t1 = new PriorityTestThread(); - c = t1->start(128, THREAD_PRIORITY_IDLE - 10); - test(false); - } - catch(const ThreadSyscallException&) - { - //Expected - } - catch(...) - { - test(false); - } - -#else - - ThreadControl c; - try - { - for(int cont = 1; cont < 10; ++cont) - { - PriorityTestThreadPtr t1 = new PriorityTestThread(); - c = t1->start(128, cont); - c.join(); - test(t1->getPriority() == cont); - } - } - catch(...) - { - test(false); - } - - // - // Test to set invalid priorities too high - // - for(int cont = 1; cont < 10; ++cont) - { - try - { - PriorityTestThreadPtr t1 = new PriorityTestThread(); - c = t1->start(128, 300 * cont); - test(false); - } - catch(const ThreadSyscallException& e) - { - //Expected - } - catch(...) - { - test(false); - } - } - - // - // Test to set invalid priorities too low - // - for(int cont = 1; cont < 10; ++cont) - { - try - { - PriorityTestThreadPtr t1 = new PriorityTestThread(); - c = t1->start(128, -10 * cont); - test(false); - } - catch(const ThreadSyscallException& e) - { - //Expected - } - catch(...) - { - test(false); - } - } - -#endif -} - -void -ThreadPriorityTest::run() -{ -} diff --git a/cpp/test/IceUtil/priority/ThreadPriority.h b/cpp/test/IceUtil/priority/ThreadPriority.h deleted file mode 100644 index 7da0d44fd52..00000000000 --- a/cpp/test/IceUtil/priority/ThreadPriority.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#ifndef THREAD_PRIORITY_TEST_H -#define THREAD_PRIORITY_TEST_H - -#include - -class ThreadPriorityTest : public TestBase -{ -public: - - ThreadPriorityTest(); - -private: - - virtual void run(); -}; - -#endif diff --git a/cpp/test/IceUtil/priority/TimerPriority.cpp b/cpp/test/IceUtil/priority/TimerPriority.cpp deleted file mode 100644 index 43c1624a845..00000000000 --- a/cpp/test/IceUtil/priority/TimerPriority.cpp +++ /dev/null @@ -1,147 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#include -#include -#include -#include - -using namespace std; -using namespace IceUtil; - -static const string priorityTestName("timer priority"); - -TimerPriorityTest::TimerPriorityTest() : - TestBase(priorityTestName) -{ -} - -void -TimerPriorityTest::run() -{ -#ifdef _WIN32 - // - // Test to create a timer with a given priority - // - try - { - TimerPtr t = new Timer(THREAD_PRIORITY_IDLE); - t->destroy(); - - t = new Timer(THREAD_PRIORITY_LOWEST); - t->destroy(); - - t = new Timer(THREAD_PRIORITY_BELOW_NORMAL); - t->destroy(); - - t = new Timer(THREAD_PRIORITY_NORMAL); - t->destroy(); - - t = new Timer(THREAD_PRIORITY_ABOVE_NORMAL); - t->destroy(); - - t = new Timer(THREAD_PRIORITY_HIGHEST); - t->destroy(); - - t = new Timer(THREAD_PRIORITY_TIME_CRITICAL); - t->destroy(); - } - catch(...) - { - test(false); - } - - // - // Test to create a timer with priorities too high - // - try - { - TimerPtr t = new Timer(THREAD_PRIORITY_TIME_CRITICAL + 10); - test(false); - } - catch(const ThreadSyscallException&) - { - //Expected - } - catch(...) - { - test(false); - } - - // - // Test to create a timer with priorities too low - // - try - { - TimerPtr t = new Timer(THREAD_PRIORITY_IDLE - 10); - test(false); - } - catch(const ThreadSyscallException&) - { - //Expected - } - catch(...) - { - test(false); - } - -#else - - // - // Test to create a timer with a given priority - // - ThreadControl c; - try - { - for(int cont = 1; cont < 10; ++cont) - { - TimerPtr t = new Timer(cont); - } - } - catch(...) - { - test(false); - } - - // - // Test to create a timer with priorities too high - // - for(int cont = 1; cont < 10; ++cont) - { - try - { - TimerPtr t = new Timer(300 * cont); - test(false); - } - catch(const ThreadSyscallException& e) - { - //Expected - } - catch(...) - { - test(false); - } - } - - // - // Test to create a timer with priorities too low - // - for(int cont = 1; cont < 10; ++cont) - { - try - { - TimerPtr t = new Timer(-10 * cont); - test(false); - } - catch(const ThreadSyscallException& e) - { - //Expected - } - catch(...) - { - test(false); - } - } -#endif -} diff --git a/cpp/test/IceUtil/priority/TimerPriority.h b/cpp/test/IceUtil/priority/TimerPriority.h deleted file mode 100644 index ba77a579474..00000000000 --- a/cpp/test/IceUtil/priority/TimerPriority.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#ifndef TIMER_PRIORITY_TEST_H -#define TIMER_PRIORITY_TEST_H - -#include - -class TimerPriorityTest : public TestBase -{ -public: - - TimerPriorityTest(); - -private: - - virtual void run(); -}; - -#endif diff --git a/cpp/test/IceUtil/priority/msbuild/client.vcxproj b/cpp/test/IceUtil/priority/msbuild/client.vcxproj deleted file mode 100644 index 40297817b46..00000000000 --- a/cpp/test/IceUtil/priority/msbuild/client.vcxproj +++ /dev/null @@ -1,112 +0,0 @@ - - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - {2C646634-969C-4A25-B9F2-ACE22302A89C} - - - - - - Application - true - $(DefaultPlatformToolset) - - - Application - false - $(DefaultPlatformToolset) - - - Application - true - $(DefaultPlatformToolset) - - - Application - false - $(DefaultPlatformToolset) - - - - - - - - - - - - - - - - - - - - - - ..;%(AdditionalIncludeDirectories) - - - - - ..;%(AdditionalIncludeDirectories) - - - - - ..;%(AdditionalIncludeDirectories) - - - - - ..;%(AdditionalIncludeDirectories) - - - - - - - - - - - - - - - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - \ No newline at end of file diff --git a/cpp/test/IceUtil/priority/msbuild/client.vcxproj.filters b/cpp/test/IceUtil/priority/msbuild/client.vcxproj.filters deleted file mode 100644 index a0e8bef091c..00000000000 --- a/cpp/test/IceUtil/priority/msbuild/client.vcxproj.filters +++ /dev/null @@ -1,55 +0,0 @@ - - - - - {0eb7f317-f0fc-4668-85a3-c490e778ef19} - - - {e33471b0-a0c7-4613-933d-e3130aad7f84} - - - {04233ee8-0448-45f4-b7f1-3370d06cf22a} - ice - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - - - - \ No newline at end of file diff --git a/cpp/test/IceUtil/priority/msbuild/packages.config b/cpp/test/IceUtil/priority/msbuild/packages.config deleted file mode 100644 index 71004b51d1b..00000000000 --- a/cpp/test/IceUtil/priority/msbuild/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/cpp/test/IceUtil/priority/test.py b/cpp/test/IceUtil/priority/test.py deleted file mode 100644 index 154576aa7cf..00000000000 --- a/cpp/test/IceUtil/priority/test.py +++ /dev/null @@ -1,13 +0,0 @@ -# -# Copyright (c) ZeroC, Inc. All rights reserved. -# - - -import os -from Util import TestSuite, platform, Windows, Darwin - - -if not isinstance(platform, Darwin) and ( - isinstance(platform, Windows) or os.getuid() == 0 -): - TestSuite(__name__) diff --git a/cpp/test/IceUtil/thread/AliveTest.cpp b/cpp/test/IceUtil/thread/AliveTest.cpp deleted file mode 100644 index 1e2f191aa5f..00000000000 --- a/cpp/test/IceUtil/thread/AliveTest.cpp +++ /dev/null @@ -1,94 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#include -#include -#include - -using namespace std; -using namespace IceUtil; - -static const string createTestName("thread alive"); - -class CondVar : public IceUtil::Monitor -{ -public: - - CondVar() : - _done(false) - { - } - - void waitForSignal() - { - IceUtil::Monitor::Lock lock(*this); - while(!_done) - { - wait(); - } - } - - void signal() - { - IceUtil::Monitor::Lock lock(*this); - _done = true; - notify(); - } - -private: - - bool _done; -}; - -class AliveTestThread : public Thread -{ -public: - - AliveTestThread(CondVar& childCreated, CondVar& parentReady) : - _childCreated(childCreated), _parentReady(parentReady) - { - } - - virtual void run() - { - try - { - _childCreated.signal(); - _parentReady.waitForSignal(); - } - catch(const IceUtil::ThreadLockedException&) - { - } - } - -private: - - CondVar& _childCreated; - CondVar& _parentReady; -}; - -typedef Handle AliveTestThreadPtr; - -AliveTest::AliveTest() : - TestBase(createTestName) -{ -} - -void -AliveTest::run() -{ - // - // Check that calling isAlive() returns the correct result for alive and - // and dead threads. - // - CondVar childCreated; - CondVar parentReady; - AliveTestThreadPtr t = new AliveTestThread(childCreated, parentReady); - IceUtil::ThreadControl c = t->start(); - childCreated.waitForSignal(); - test(t->isAlive()); - parentReady.signal(); - c.join(); - test(!t->isAlive()); -} diff --git a/cpp/test/IceUtil/thread/AliveTest.h b/cpp/test/IceUtil/thread/AliveTest.h deleted file mode 100644 index 3ba5d6514ed..00000000000 --- a/cpp/test/IceUtil/thread/AliveTest.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#ifndef ALIVE_TEST_H -#define ALIVE_TEST_H - -#include - -class AliveTest : public TestBase -{ -public: - - AliveTest(); - -private: - - virtual void run(); -}; - -#endif diff --git a/cpp/test/IceUtil/thread/MonitorRecMutexTest.cpp b/cpp/test/IceUtil/thread/MonitorRecMutexTest.cpp deleted file mode 100644 index fd2dcc1f948..00000000000 --- a/cpp/test/IceUtil/thread/MonitorRecMutexTest.cpp +++ /dev/null @@ -1,177 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#include - -#include -#include - -using namespace std; -using namespace IceUtil; - -class MonitorRecMutexTestThread : public Thread -{ -public: - - MonitorRecMutexTestThread(Monitor& m) : - _monitor(m), - _tryLock(false) - { - } - - virtual void run() - { - - Monitor::TryLock tlock(_monitor); - test(!tlock.acquired()); - - { - Mutex::Lock lock(_tryLockMutex); - _tryLock = true; - } - _tryLockCond.signal(); - - Monitor::Lock lock(_monitor); - } - - void - waitTryLock() - { - Mutex::Lock lock(_tryLockMutex); - while(!_tryLock) - { - _tryLockCond.wait(lock); - } - } - -private: - - Monitor& _monitor; - bool _tryLock; - // - // Use native Condition variable here, not Monitor. - // - Cond _tryLockCond; - Mutex _tryLockMutex; -}; - -typedef Handle MonitorRecMutexTestThreadPtr; - -class MonitorRecMutexTestThread2 : public Thread, public Monitor -{ -public: - - MonitorRecMutexTestThread2(Monitor& monitor) : - finished(false), - _monitor(monitor) - { - } - - virtual void run() - { - Monitor::Lock lock(_monitor); - _monitor.wait(); - finished = true; - } - - bool finished; - -private: - - Monitor& _monitor; -}; - -typedef Handle MonitorRecMutexTestThread2Ptr; - -static const string monitorRecMutexTestName("monitor"); - -MonitorRecMutexTest::MonitorRecMutexTest() : - TestBase(monitorRecMutexTestName) -{ -} - -void -MonitorRecMutexTest::run() -{ - Monitor monitor; - MonitorRecMutexTestThreadPtr t; - MonitorRecMutexTestThread2Ptr t2; - MonitorRecMutexTestThread2Ptr t3; - ThreadControl control; - ThreadControl control2; - - { - Monitor::Lock lock(monitor); - - Monitor::TryLock lock2(monitor); - test(lock2.acquired()); - - // TEST: TryLock - - Monitor::TryLock tlock(monitor); - test(tlock.acquired()); - - // TEST: Start thread, try to acquire the mutex. - t = new MonitorRecMutexTestThread(monitor); - control = t->start(); - - // TEST: Wait until the tryLock has been tested. - t->waitTryLock(); - } - - // - // TEST: Once the mutex has been released, the thread should - // acquire the mutex and then terminate. - // - control.join(); - - // TEST: notify() wakes one consumer. - t2 = new MonitorRecMutexTestThread2(monitor); - control = t2->start(); - t3 = new MonitorRecMutexTestThread2(monitor); - control2 = t3->start(); - - // Give the thread time to start waiting. - ThreadControl::sleep(Time::seconds(1)); - - { - Monitor::Lock lock(monitor); - monitor.notify(); - } - - // Give one thread time to terminate - ThreadControl::sleep(Time::seconds(1)); - - test((t2->finished && !t3->finished) || (t3->finished && !t2->finished)); - - { - Monitor::Lock lock(monitor); - monitor.notify(); - } - control.join(); - control2.join(); - - // TEST: notifyAll() wakes one consumer. - t2 = new MonitorRecMutexTestThread2(monitor); - control = t2->start(); - t3 = new MonitorRecMutexTestThread2(monitor); - control2 = t3->start(); - - // Give the threads time to start waiting. - ThreadControl::sleep(Time::seconds(1)); - - { - Monitor::Lock lock(monitor); - monitor.notifyAll(); - } - - control.join(); - control2.join(); - - // TEST: timedWait - { - Monitor::Lock lock(monitor); - test(!monitor.timedWait(Time::milliSeconds(500))); - } -} diff --git a/cpp/test/IceUtil/thread/MonitorRecMutexTest.h b/cpp/test/IceUtil/thread/MonitorRecMutexTest.h deleted file mode 100644 index 7a12b18adaa..00000000000 --- a/cpp/test/IceUtil/thread/MonitorRecMutexTest.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#ifndef MONITOR_REC_MUTEX_TEST_H -#define MONITOR_REC_MUTEX_TEST_H - -#include - -class MonitorRecMutexTest : public TestBase -{ -public: - - MonitorRecMutexTest(); - -private: - - virtual void run(); -}; - -#endif diff --git a/cpp/test/IceUtil/thread/RecMutexTest.cpp b/cpp/test/IceUtil/thread/RecMutexTest.cpp deleted file mode 100644 index 47c751236aa..00000000000 --- a/cpp/test/IceUtil/thread/RecMutexTest.cpp +++ /dev/null @@ -1,101 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#include - -#include -#include - -using namespace std; -using namespace IceUtil; - -static const string recMutexTestName("recursive mutex"); - -class RecMutexTestThread : public Thread -{ -public: - - RecMutexTestThread(RecMutex& m) : - _mutex(m), - _tryLock(false) - { - } - - virtual void run() - { - - RecMutex::TryLock tlock(_mutex); - test(!tlock.acquired()); - - { - Mutex::Lock lock(_tryLockMutex); - _tryLock = true; - } - _tryLockCond.signal(); - - RecMutex::Lock lock(_mutex); - } - - void - waitTryLock() - { - Mutex::Lock lock(_tryLockMutex); - while(!_tryLock) - { - _tryLockCond.wait(lock); - } - } - -private: - - RecMutex& _mutex; - bool _tryLock; - // - // Use native Condition variable here, not Monitor. - // - Cond _tryLockCond; - Mutex _tryLockMutex; -}; - -typedef Handle RecMutexTestThreadPtr; - -RecMutexTest::RecMutexTest() : - TestBase(recMutexTestName) -{ -} - -void -RecMutexTest::run() -{ - RecMutex mutex; - RecMutexTestThreadPtr t; - ThreadControl control; - - { - RecMutex::Lock lock(mutex); - - // TEST: lock twice - RecMutex::Lock lock2(mutex); - - // TEST: TryLock - RecMutex::TryLock lock3(mutex); - test(lock3.acquired()); - - // TEST: Start thread, try to acquire the mutex. - t = new RecMutexTestThread(mutex); - control = t->start(); - - // TEST: Wait until the tryLock has been tested. - t->waitTryLock(); - - } - - // - // TEST: Once the recursive mutex has been released, the thread - // should acquire the mutex and then terminate. - // - - control.join(); - -} diff --git a/cpp/test/IceUtil/thread/RecMutexTest.h b/cpp/test/IceUtil/thread/RecMutexTest.h deleted file mode 100644 index 4b8a980ff48..00000000000 --- a/cpp/test/IceUtil/thread/RecMutexTest.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#ifndef REC_MUTEX_TEST_H -#define REC_MUTEX_TEST_H - -#include - -class RecMutexTest : public TestBase -{ -public: - - RecMutexTest(); - -private: - - virtual void run(); -}; - -#endif diff --git a/cpp/test/IceUtil/thread/TestSuite.cpp b/cpp/test/IceUtil/thread/TestSuite.cpp index 2bc2c7e2ef0..164d34f9fb2 100644 --- a/cpp/test/IceUtil/thread/TestSuite.cpp +++ b/cpp/test/IceUtil/thread/TestSuite.cpp @@ -6,13 +6,10 @@ #include #include #include -#include #include -#include #include #include #include -#include std::list allTests; @@ -24,8 +21,5 @@ initializeTestSuite() allTests.push_back(new StartTest); allTests.push_back(new SleepTest); allTests.push_back(new CreateTest); - allTests.push_back(new AliveTest); - allTests.push_back(new RecMutexTest); allTests.push_back(new MonitorMutexTest); - allTests.push_back(new MonitorRecMutexTest); } diff --git a/cpp/test/IceUtil/thread/msbuild/client.vcxproj b/cpp/test/IceUtil/thread/msbuild/client.vcxproj index b1949c4fbb4..aa7ddfde8a9 100644 --- a/cpp/test/IceUtil/thread/msbuild/client.vcxproj +++ b/cpp/test/IceUtil/thread/msbuild/client.vcxproj @@ -84,27 +84,21 @@ - - - - - - diff --git a/cpp/test/IceUtil/thread/msbuild/client.vcxproj.filters b/cpp/test/IceUtil/thread/msbuild/client.vcxproj.filters index c4c2ec95e98..ab69c6c2318 100644 --- a/cpp/test/IceUtil/thread/msbuild/client.vcxproj.filters +++ b/cpp/test/IceUtil/thread/msbuild/client.vcxproj.filters @@ -16,9 +16,6 @@ Source Files - - Source Files - Source Files @@ -28,15 +25,9 @@ Source Files - - Source Files - Source Files - - Source Files - Source Files @@ -51,9 +42,6 @@ - - Header Files - Header Files @@ -63,15 +51,9 @@ Header Files - - Header Files - Header Files - - Header Files - Header Files