Skip to content

Commit

Permalink
Replace C++ CountDownLatch with std::promise
Browse files Browse the repository at this point in the history
  • Loading branch information
pepone committed Feb 26, 2024
1 parent 885ad85 commit 732fd08
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 262 deletions.
45 changes: 0 additions & 45 deletions cpp/include/IceUtil/CountDownLatch.h

This file was deleted.

42 changes: 7 additions & 35 deletions cpp/src/Glacier2Lib/SessionHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <Glacier2/SessionHelper.h>

#include <IceUtil/IceUtil.h>
#include <IceUtil/CountDownLatch.h>
#include <Ice/Ice.h>

#include <algorithm> // required by max
Expand Down Expand Up @@ -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<DispatcherCallWait>(cdl, call);
_initData.dispatcher([callWait]()
promise<void> dispatchPromise;

_initData.dispatcher(
[&dispatchPromise, call = std::move(call)]()
{
callWait->run();
call->run();
dispatchPromise.set_value();
},
conn);
cdl.await();
dispatchPromise.get_future().wait();
}
else
{
Expand Down
171 changes: 0 additions & 171 deletions cpp/src/Ice/CountDownLatch.cpp

This file was deleted.

1 change: 0 additions & 1 deletion cpp/src/Ice/msbuild/ice/ice.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,6 @@
<ClCompile Include="..\..\FixedRequestHandler.cpp" />
<ClCompile Include="..\..\Connector.cpp" />
<ClCompile Include="..\..\ConnectRequestHandler.cpp" />
<ClCompile Include="..\..\CountDownLatch.cpp" />
<ClCompile Include="..\..\DefaultsAndOverrides.cpp" />
<ClCompile Include="..\..\DispatchInterceptor.cpp" />
<ClCompile Include="..\..\DLLMain.cpp" />
Expand Down
3 changes: 0 additions & 3 deletions cpp/src/Ice/msbuild/ice/ice.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,6 @@
<ClCompile Include="..\..\ConnectRequestHandler.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\CountDownLatch.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\DefaultsAndOverrides.cpp">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down
4 changes: 1 addition & 3 deletions cpp/src/IceUtil/msbuild/iceutil/iceutil.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
<ItemGroup>
<ClInclude Include="..\..\..\..\include\IceUtil\Config.h" />
<ClInclude Include="..\..\..\..\include\IceUtil\ConsoleUtil.h" />
<ClInclude Include="..\..\..\..\include\IceUtil\CountDownLatch.h" />
<ClInclude Include="..\..\..\..\include\IceUtil\CtrlCHandler.h" />
<ClInclude Include="..\..\..\..\include\IceUtil\DisableWarnings.h" />
<ClInclude Include="..\..\..\..\include\IceUtil\Exception.h" />
Expand All @@ -119,7 +118,6 @@
<ClInclude Include="..\..\..\..\include\IceUtil\ScannerConfig.h" />
<ClInclude Include="..\..\..\..\include\IceUtil\StringConverter.h" />
<ClInclude Include="..\..\..\..\include\IceUtil\StringUtil.h" />
<ClInclude Include="..\..\..\..\include\IceUtil\Thread.h" />
<ClInclude Include="..\..\..\..\include\IceUtil\ThreadException.h" />
<ClInclude Include="..\..\..\..\include\IceUtil\Timer.h" />
<ClInclude Include="..\..\..\..\include\IceUtil\UndefSysMacros.h" />
Expand All @@ -128,4 +126,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
5 changes: 1 addition & 4 deletions cpp/src/IceUtil/msbuild/iceutil/iceutil.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@
<ClInclude Include="..\..\..\..\include\IceUtil\Config.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\IceUtil\CountDownLatch.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\IceUtil\CtrlCHandler.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -126,4 +123,4 @@
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
</Project>

0 comments on commit 732fd08

Please sign in to comment.