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

Replace IceUtil::Mutex with std::mutex #1763

Merged
merged 11 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 2 additions & 2 deletions cpp/include/Glacier2/SessionHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <IceUtil/Shared.h>
#include <IceUtil/Handle.h>
#include <IceUtil/Thread.h>
#include <IceUtil/Mutex.h>

#include <Ice/Initialize.h>
#include <Ice/Properties.h>
Expand All @@ -21,6 +20,7 @@

#include <map>
#include <string>
#include <mutex>

namespace Glacier2
{
Expand Down Expand Up @@ -283,7 +283,7 @@ class GLACIER2_API SessionFactoryHelper : public std::enable_shared_from_this<Se
std::string createProxyStr(const Ice::Identity& ident);
void setDefaultProperties();

IceUtil::Mutex _mutex;
mutable std::mutex _mutex;
std::string _routerHost;
Ice::Identity _identity;
std::string _protocol;
Expand Down
1 change: 1 addition & 0 deletions cpp/include/IceUtil/Monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <IceUtil/Config.h>
#include <IceUtil/Lock.h>
#include <IceUtil/Cond.h>
#include <IceUtil/Mutex.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still use Mutex and Monitor? If not, I would remove them entirely.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still have to fix the tests, Application and Timer classes.


namespace IceUtil
{
Expand Down
5 changes: 3 additions & 2 deletions cpp/include/IceUtil/Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#include <IceUtil/Config.h>
#include <IceUtil/Shared.h>
#include <IceUtil/Handle.h>
#include <IceUtil/Mutex.h>

#include <mutex>

namespace IceUtil
{
Expand Down Expand Up @@ -131,7 +132,7 @@ class ICE_API Thread : public virtual IceUtil::Shared

protected:
const std::string _name;
Mutex _stateMutex;
mutable std::mutex _stateMutex;
bool _started;
bool _running;

Expand Down
70 changes: 35 additions & 35 deletions cpp/src/Glacier2Lib/SessionHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class SessionHelperI : public Glacier2::SessionHelper, public std::enable_shared
void dispatchCallback(const Ice::DispatcherCallPtr&, const Ice::ConnectionPtr&);
void dispatchCallbackAndWait(const Ice::DispatcherCallPtr&, const Ice::ConnectionPtr&);

IceUtil::Mutex _mutex;
mutable std::mutex _mutex;
Ice::CommunicatorPtr _communicator;
Ice::ObjectAdapterPtr _adapter;
Glacier2::RouterPrxPtr _router;
Expand Down Expand Up @@ -210,7 +210,7 @@ SessionHelperI::SessionHelperI(const Glacier2::SessionThreadCallbackPtr& threadC
void
SessionHelperI::destroy()
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
if(_destroy)
{
return;
Expand Down Expand Up @@ -244,14 +244,14 @@ SessionHelperI::destroy()
Ice::CommunicatorPtr
SessionHelperI::communicator() const
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
return _communicator;
}

string
SessionHelperI::categoryForClient() const
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
if(!_router)
{
throw Glacier2::SessionNotExistException();
Expand All @@ -262,7 +262,7 @@ SessionHelperI::categoryForClient() const
Ice::ObjectPrxPtr
SessionHelperI::addWithUUID(const Ice::ObjectPtr& servant)
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
if(!_router)
{
throw Glacier2::SessionNotExistException();
Expand All @@ -276,21 +276,21 @@ SessionHelperI::addWithUUID(const Ice::ObjectPtr& servant)
Glacier2::SessionPrxPtr
SessionHelperI::session() const
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
return _session;
}

bool
SessionHelperI::isConnected() const
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
return _connected;
}

Ice::ObjectAdapterPtr
SessionHelperI::objectAdapter()
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
return internalObjectAdapter();
}

Expand Down Expand Up @@ -373,14 +373,14 @@ class ConnectStrategyUserPassword final : public ConnectStrategy
void
SessionHelperI::connect(const map<string, string>& context)
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
connectImpl(make_shared<ConnectStrategySecureConnection>(context));
}

void
SessionHelperI::connect(const string& user, const string& password, const map<string, string>& context)
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
connectImpl(make_shared<ConnectStrategyUserPassword>(user, password, context));
}

Expand All @@ -391,7 +391,7 @@ SessionHelperI::destroyInternal(const Ice::DispatcherCallPtr& disconnected)
Ice::CommunicatorPtr communicator;
Glacier2::RouterPrxPtr router;
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
router = _router;
_router = nullptr;
_connected = false;
Expand Down Expand Up @@ -442,7 +442,7 @@ SessionHelperI::destroyCommunicator()
{
Ice::CommunicatorPtr communicator;
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
communicator = _communicator;
}

Expand All @@ -457,7 +457,7 @@ SessionHelperI::connectFailed()
{
Ice::CommunicatorPtr communicator;
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
communicator = _communicator;
}

Expand Down Expand Up @@ -540,14 +540,14 @@ class ConnectThread : public IceUtil::Thread
Ice::CommunicatorPtr communicator;
try
{
IceUtil::Mutex::Lock sync(_session->_mutex);
lock_guard lock(_session->_mutex);
communicator = Ice::initialize(_session->_initData);
_session->_communicator = communicator;
}
catch(const Ice::LocalException& ex)
{
{
IceUtil::Mutex::Lock sync(_session->_mutex);
lock_guard lock(_session->_mutex);
_session->_destroy = true;
}
_session->dispatchCallback(new ConnectFailed(_callback, _session, ex), nullptr);
Expand Down Expand Up @@ -718,7 +718,7 @@ SessionHelperI::connected(const Glacier2::RouterPrxPtr& router, const Glacier2::

bool destroy;
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
_router = router;
destroy = _destroy;

Expand Down Expand Up @@ -878,7 +878,7 @@ Glacier2::SessionFactoryHelper::SessionFactoryHelper(const Ice::PropertiesPtr& p

Glacier2::SessionFactoryHelper::~SessionFactoryHelper()
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
if(!_threads.empty() && Ice::getProcessLogger())
{
Ice::Warning warn(Ice::getProcessLogger());
Expand All @@ -894,7 +894,7 @@ Glacier2::SessionFactoryHelper::addThread(const SessionHelper* session, const Ic
// currently registered thread for the same session must be finished, so
// we just replace it. Caller must join returned thread.
//
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
IceUtil::ThreadPtr previous;
map<const SessionHelper*, IceUtil::ThreadPtr>::iterator p = _threads.find(session);
if(p != _threads.end())
Expand All @@ -912,7 +912,7 @@ Glacier2::SessionFactoryHelper::addThread(const SessionHelper* session, const Ic
void
Glacier2::SessionFactoryHelper::destroy()
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
for(map<const SessionHelper*, IceUtil::ThreadPtr>::iterator p = _threads.begin(); p != _threads.end(); ++p)
{
p->second->getThreadControl().join();
Expand All @@ -923,28 +923,28 @@ Glacier2::SessionFactoryHelper::destroy()
void
Glacier2::SessionFactoryHelper::setRouterIdentity(const Ice::Identity& identity)
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
_identity = identity;
}

Ice::Identity
Glacier2::SessionFactoryHelper::getRouterIdentity() const
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
return _identity;
}

void
Glacier2::SessionFactoryHelper::setRouterHost(const string& hostname)
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
_routerHost = hostname;
}

string
Glacier2::SessionFactoryHelper::getRouterHost() const
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
return _routerHost;
}

Expand All @@ -963,7 +963,7 @@ Glacier2::SessionFactoryHelper::getSecure() const
void
Glacier2::SessionFactoryHelper::setProtocol(const string& protocol)
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
if(protocol != "tcp" &&
protocol != "ssl" &&
protocol != "ws" &&
Expand All @@ -977,35 +977,35 @@ Glacier2::SessionFactoryHelper::setProtocol(const string& protocol)
string
Glacier2::SessionFactoryHelper::getProtocol() const
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
return _protocol;
}

void
Glacier2::SessionFactoryHelper::setTimeout(int timeout)
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
_timeout = timeout;
}

int
Glacier2::SessionFactoryHelper::getTimeout() const
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
return _timeout;
}

void
Glacier2::SessionFactoryHelper::setPort(int port)
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
_port = port;
}

int
Glacier2::SessionFactoryHelper::getPort() const
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
return getPortInternal();
}

Expand All @@ -1019,28 +1019,28 @@ Glacier2::SessionFactoryHelper::getPortInternal() const
Ice::InitializationData
Glacier2::SessionFactoryHelper::getInitializationData() const
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
return _initData;
}

void
Glacier2::SessionFactoryHelper::setConnectContext(const map<string, string>& context)
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
_context = context;
}

void
Glacier2::SessionFactoryHelper::setUseCallbacks(bool useCallbacks)
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
_useCallbacks = useCallbacks;
}

bool
Glacier2::SessionFactoryHelper::getUseCallbacks() const
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
return _useCallbacks;
}

Expand All @@ -1050,7 +1050,7 @@ Glacier2::SessionFactoryHelper::connect()
SessionHelperIPtr session;
map<string, string> context;
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
session = make_shared<SessionHelperI>(make_shared<SessionThreadCallback>(shared_from_this()),
_callback,
createInitData(),
Expand All @@ -1068,7 +1068,7 @@ Glacier2::SessionFactoryHelper::connect(const string& user, const string& passw
SessionHelperIPtr session;
map<string, string> context;
{
IceUtil::Mutex::Lock sync(_mutex);
lock_guard lock(_mutex);
session = make_shared<SessionHelperI>(make_shared<SessionThreadCallback>(shared_from_this()),
_callback,
createInitData(),
Expand Down
Loading
Loading