diff --git a/cpp/include/IceUtil/CountDownLatch.h b/cpp/include/IceUtil/CountDownLatch.h deleted file mode 100644 index 7622df6ca6b..00000000000 --- a/cpp/include/IceUtil/CountDownLatch.h +++ /dev/null @@ -1,45 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#ifndef ICE_UTIL_COUNT_DOWN_LATCH_H -#define ICE_UTIL_COUNT_DOWN_LATCH_H - -#include - -namespace IceUtilInternal -{ - -// -// See java.util.concurrent.CountDownLatch in Java 1.5 -// - -class ICE_API CountDownLatch -{ -public: - - CountDownLatch(int); - ~CountDownLatch(); - - void await() const; - void countDown(); - int getCount() const; - -private: - -#ifdef _WIN32 - mutable LONG _count; - HANDLE _event; -#else - int _count; - mutable pthread_mutex_t _mutex; - mutable pthread_cond_t _cond; - - inline void lock() const; - inline void unlock() const; -#endif -}; - -} - -#endif diff --git a/cpp/src/Glacier2Lib/SessionHelper.cpp b/cpp/src/Glacier2Lib/SessionHelper.cpp index 0bcb21dc193..b170f1803e7 100644 --- a/cpp/src/Glacier2Lib/SessionHelper.cpp +++ b/cpp/src/Glacier2Lib/SessionHelper.cpp @@ -5,7 +5,6 @@ #include #include -#include #include #include // required by max @@ -683,48 +682,21 @@ SessionHelperI::dispatchCallback(const Ice::DispatcherCallPtr& call, const Ice:: } } -namespace -{ - -class DispatcherCallWait : public Ice::DispatcherCall -{ - -public: - - DispatcherCallWait(IceUtilInternal::CountDownLatch& cdl, const Ice::DispatcherCallPtr& call) : - _cdl(cdl), - _call(call) - { - } - - virtual void - run() - { - _call->run(); - _cdl.countDown(); - } - -private: - - IceUtilInternal::CountDownLatch& _cdl; - const Ice::DispatcherCallPtr _call; -}; - -} - void SessionHelperI::dispatchCallbackAndWait(const Ice::DispatcherCallPtr& call, const Ice::ConnectionPtr& conn) { if(_initData.dispatcher) { - IceUtilInternal::CountDownLatch cdl(1); - auto callWait = make_shared(cdl, call); - _initData.dispatcher([callWait]() + promise dispatchPromise; + + _initData.dispatcher( + [&dispatchPromise, call = std::move(call)]() { - callWait->run(); + call->run(); + dispatchPromise.set_value(); }, conn); - cdl.await(); + dispatchPromise.get_future().wait(); } else { diff --git a/cpp/src/Ice/CountDownLatch.cpp b/cpp/src/Ice/CountDownLatch.cpp deleted file mode 100644 index f67ba23c55d..00000000000 --- a/cpp/src/Ice/CountDownLatch.cpp +++ /dev/null @@ -1,171 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#include -#include - -IceUtilInternal::CountDownLatch::CountDownLatch(int count) : - _count(count) -{ - if(count < 0) - { - throw IceUtil::IllegalArgumentException(__FILE__, __LINE__, "count must be greater than 0"); - } - -#ifdef _WIN32 - _event = CreateEvent(0, TRUE, FALSE, 0); - if(_event == 0) - { - throw IceUtil::ThreadSyscallException(__FILE__, __LINE__, GetLastError()); - } -#else - int rc = pthread_mutex_init(&_mutex, 0); - if(rc != 0) - { - throw IceUtil::ThreadSyscallException(__FILE__, __LINE__, rc); - } - - rc = pthread_cond_init(&_cond, 0); - if(rc != 0) - { - throw IceUtil::ThreadSyscallException(__FILE__, __LINE__, rc); - } -#endif -} - -IceUtilInternal::CountDownLatch::~CountDownLatch() -{ -#ifdef _WIN32 - CloseHandle(_event); -#else -# ifndef NDEBUG - int rc = pthread_mutex_destroy(&_mutex); - assert(rc == 0); - rc = pthread_cond_destroy(&_cond); - assert(rc == 0); -# else - pthread_mutex_destroy(&_mutex); - pthread_cond_destroy(&_cond); -# endif -#endif -} - -void -IceUtilInternal::CountDownLatch::await() const -{ -#ifdef _WIN32 - while(InterlockedExchangeAdd(&_count, 0) > 0) - { - DWORD rc = WaitForSingleObject(_event, INFINITE); - assert(rc == WAIT_OBJECT_0 || rc == WAIT_FAILED); - - if(rc == WAIT_FAILED) - { - throw IceUtil::ThreadSyscallException(__FILE__, __LINE__, GetLastError()); - } - } -#else - lock(); - while(_count > 0) - { - int rc = pthread_cond_wait(&_cond, &_mutex); - if(rc != 0) - { - pthread_mutex_unlock(&_mutex); - throw IceUtil::ThreadSyscallException(__FILE__, __LINE__, rc); - } - } - unlock(); - -#endif -} - -void -IceUtilInternal::CountDownLatch::countDown() -{ -#ifdef _WIN32 - if(InterlockedDecrement(&_count) == 0) - { - if(SetEvent(_event) == 0) - { - throw IceUtil::ThreadSyscallException(__FILE__, __LINE__, GetLastError()); - } - } -#else - bool broadcast = false; - - lock(); - if(_count > 0 && --_count == 0) - { - broadcast = true; - } -#if defined(__APPLE__) - // - // On macOS we do the broadcast with the mutex held. This seems to - // be necessary to prevent the broadcast call to hang (spinning in - // an infinite loop). - // - if(broadcast) - { - int rc = pthread_cond_broadcast(&_cond); - if(rc != 0) - { - pthread_mutex_unlock(&_mutex); - throw IceUtil::ThreadSyscallException(__FILE__, __LINE__, rc); - } - } - unlock(); - -#else - unlock(); - - if(broadcast) - { - int rc = pthread_cond_broadcast(&_cond); - if(rc != 0) - { - throw IceUtil::ThreadSyscallException(__FILE__, __LINE__, rc); - } - } -#endif - -#endif -} - -int -IceUtilInternal::CountDownLatch::getCount() const -{ -#ifdef _WIN32 - int count = InterlockedExchangeAdd(&_count, 0); - return count > 0 ? count : 0; -#else - lock(); - int result = _count; - unlock(); - return result; -#endif -} - -#ifndef _WIN32 -void -IceUtilInternal::CountDownLatch::lock() const -{ - int rc = pthread_mutex_lock(&_mutex); - if(rc != 0) - { - throw IceUtil::ThreadSyscallException(__FILE__, __LINE__, rc); - } -} - -void -IceUtilInternal::CountDownLatch::unlock() const -{ - int rc = pthread_mutex_unlock(&_mutex); - if(rc != 0) - { - throw IceUtil::ThreadSyscallException(__FILE__, __LINE__, rc); - } -} - -#endif diff --git a/cpp/src/Ice/msbuild/ice/ice.vcxproj b/cpp/src/Ice/msbuild/ice/ice.vcxproj index dbcd2df8663..74fa2e6c0d6 100644 --- a/cpp/src/Ice/msbuild/ice/ice.vcxproj +++ b/cpp/src/Ice/msbuild/ice/ice.vcxproj @@ -515,7 +515,6 @@ - diff --git a/cpp/src/Ice/msbuild/ice/ice.vcxproj.filters b/cpp/src/Ice/msbuild/ice/ice.vcxproj.filters index 4f45632476b..5979d80246c 100644 --- a/cpp/src/Ice/msbuild/ice/ice.vcxproj.filters +++ b/cpp/src/Ice/msbuild/ice/ice.vcxproj.filters @@ -285,9 +285,6 @@ Source Files - - Source Files - Source Files diff --git a/cpp/src/IceUtil/msbuild/iceutil/iceutil.vcxproj b/cpp/src/IceUtil/msbuild/iceutil/iceutil.vcxproj index f9f57806e2c..1de0cf3dacf 100644 --- a/cpp/src/IceUtil/msbuild/iceutil/iceutil.vcxproj +++ b/cpp/src/IceUtil/msbuild/iceutil/iceutil.vcxproj @@ -102,7 +102,6 @@ - @@ -119,7 +118,6 @@ - @@ -128,4 +126,4 @@ - \ No newline at end of file + diff --git a/cpp/src/IceUtil/msbuild/iceutil/iceutil.vcxproj.filters b/cpp/src/IceUtil/msbuild/iceutil/iceutil.vcxproj.filters index 58001877149..657d3defee4 100644 --- a/cpp/src/IceUtil/msbuild/iceutil/iceutil.vcxproj.filters +++ b/cpp/src/IceUtil/msbuild/iceutil/iceutil.vcxproj.filters @@ -56,9 +56,6 @@ Header Files - - Header Files - Header Files @@ -126,4 +123,4 @@ Header Files - \ No newline at end of file +