Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
externl committed Jan 18, 2024
1 parent 50e186f commit ac47fd1
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions php/src/Communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ typedef map<string, ActiveCommunicatorPtr> RegisteredCommunicatorMap;
RegisteredCommunicatorMap _registeredCommunicators;

// std::mutex constructor is constexpr so it is statically initialized
// _registeredCommunicatorsMutex protects _registeredCommunicators and _reapThread
// _reapMutex protects _reapingFinished
std::mutex _registeredCommunicatorsMutex;
std::mutex _reapMutex;
std::condition_variable _reapCond;
std::thread _reapThread;
bool _reapingFinished = true;
Expand All @@ -239,13 +242,7 @@ reapRegisteredCommunicators()
{
if(p->second->lastAccess + std::chrono::hours(p->second->expires) <= now)
{
try
{
p->second->communicator->destroy();
}
catch(...)
{
}
p->second->communicator->destroy();
_registeredCommunicators.erase(p++);
}
else
Expand Down Expand Up @@ -1303,7 +1300,7 @@ ZEND_FUNCTION(Ice_register)
{
_reapThread = std::thread([&]
{
std::unique_lock lock(_registeredCommunicatorsMutex);
std::unique_lock lock(_reapMutex);
_reapCond.wait_for(lock, std::chrono::minutes(5), [&] { return _reapingFinished; });
if (_reapingFinished)
{
Expand Down Expand Up @@ -1819,17 +1816,19 @@ IcePHP::communicatorShutdown(void)
{
_profiles.clear();

lock_guard lock(_registeredCommunicatorsMutex);
//
// Clearing the map releases the last remaining reference counts of the ActiveCommunicator
// objects. The ActiveCommunicator destructor destroys its communicator.
//
_registeredCommunicators.clear();

{
lock_guard lock(_registeredCommunicatorsMutex);
lock_guard lock(_reapMutex);
_reapingFinished = true;
//
// Clearing the map releases the last remaining reference counts of the ActiveCommunicator
// objects. The ActiveCommunicator destructor destroys its communicator.
//
_registeredCommunicators.clear();
_reapCond.notify_one();
}

_reapCond.notify_one();
if(_reapThread.joinable())
{
_reapThread.join();
Expand Down

0 comments on commit ac47fd1

Please sign in to comment.