Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hash implementation to not use a global mutex #1707

Merged
merged 2 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 1 addition & 26 deletions cpp/src/Ice/IPEndpointI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,6 @@ using namespace Ice;
using namespace Ice::Instrumentation;
using namespace IceInternal;

namespace
{

IceUtil::Mutex* hashMutex = 0;

class Init
{
public:

Init()
{
hashMutex = new IceUtil::Mutex;
}

~Init()
{
delete hashMutex;
hashMutex = 0;
}
};

Init init;

}

#ifndef ICE_CPP11_MAPPING
IceUtil::Shared* IceInternal::upCast(IPEndpointI* p) { return p; }
#endif
Expand Down Expand Up @@ -213,7 +188,7 @@ IceInternal::IPEndpointI::equivalent(const EndpointIPtr& endpoint) const
Ice::Int
IceInternal::IPEndpointI::hash() const
{
IceUtilInternal::MutexPtrLock<IceUtil::Mutex> lock(hashMutex);
lock_guard lock(_hashMutex);
if(!_hashInitialized)
{
_hashValue = 5381;
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/Ice/IPEndpointI.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <Ice/ObserverHelper.h>

#include <deque>
#include <mutex>

namespace IceInternal
{
Expand Down Expand Up @@ -100,6 +101,7 @@ class ICE_API IPEndpointI : public EndpointI

mutable bool _hashInitialized;
mutable Ice::Int _hashValue;
mutable std::mutex _hashMutex;
};

class ICE_API EndpointHostResolver : public IceUtil::Thread, public IceUtil::Monitor<IceUtil::Mutex>
Expand Down
32 changes: 3 additions & 29 deletions cpp/src/Ice/Reference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <Ice/StringUtil.h>

#include <IceUtil/Random.h>
#include <IceUtil/MutexPtrLock.h>

#include <functional>
#include <algorithm>
Expand All @@ -36,31 +35,6 @@ using namespace IceInternal;

IceUtil::Shared* IceInternal::upCast(IceInternal::Reference* p) { return p; }

namespace
{

IceUtil::Mutex* hashMutex = 0;

class Init
{
public:

Init()
{
hashMutex = new IceUtil::Mutex;
}

~Init()
{
delete hashMutex;
hashMutex = 0;
}
};

Init init;

}

CommunicatorPtr
IceInternal::Reference::getCommunicator() const
{
Expand Down Expand Up @@ -182,7 +156,7 @@ IceInternal::Reference::getCompressOverride(bool& compress) const
Int
Reference::hash() const
{
IceUtilInternal::MutexPtrLock<IceUtil::Mutex> lock(hashMutex);
lock_guard lock(_hashMutex);
if(!_hashInitialized)
{
_hashValue = hashInit();
Expand Down Expand Up @@ -503,14 +477,14 @@ IceInternal::Reference::Reference(const InstancePtr& instance,
const EncodingVersion& encoding,
int invocationTimeout,
const Ice::Context& ctx) :
_hashInitialized(false),
_instance(instance),
_communicator(communicator),
_mode(mode),
_secure(secure),
_identity(id),
_context(new SharedContext(ctx)),
_facet(facet),
_hashInitialized(false),
_protocol(protocol),
_encoding(encoding),
_invocationTimeout(invocationTimeout),
Expand All @@ -521,14 +495,14 @@ IceInternal::Reference::Reference(const InstancePtr& instance,

IceInternal::Reference::Reference(const Reference& r) :
IceUtil::Shared(),
_hashInitialized(false),
_instance(r._instance),
_communicator(r._communicator),
_mode(r._mode),
_secure(r._secure),
_identity(r._identity),
_context(r._context),
_facet(r._facet),
_hashInitialized(false),
_protocol(r._protocol),
_encoding(r._encoding),
_invocationTimeout(r._invocationTimeout),
Expand Down
8 changes: 5 additions & 3 deletions cpp/src/Ice/Reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <Ice/Protocol.h>
#include <Ice/Properties.h>

#include <mutex>

namespace Ice
{

Expand Down Expand Up @@ -158,9 +160,6 @@ class Reference : public IceUtil::Shared

virtual Ice::Int hashInit() const;

mutable Ice::Int _hashValue;
mutable bool _hashInitialized;

private:

const InstancePtr _instance;
Expand All @@ -171,6 +170,9 @@ class Reference : public IceUtil::Shared
Ice::Identity _identity;
SharedContextPtr _context;
std::string _facet;
mutable Ice::Int _hashValue;
mutable bool _hashInitialized;
mutable std::mutex _hashMutex;
Ice::ProtocolVersion _protocol;
Ice::EncodingVersion _encoding;
int _invocationTimeout;
Expand Down