@@ -49,7 +49,8 @@ bool DBusObjectManager::registerDBusStubAdapter(std::shared_ptr<DBusStubAdapter>
4949 DBusInterfaceHandlerPath dbusStubAdapterHandlerPath (dbusStubAdapterObjectPath, dbusStubAdapterInterfaceName);
5050 bool isRegistrationSuccessful = false ;
5151
52- objectPathLock_.lock ();
52+ std::lock_guard<std::recursive_mutex> itsLock (objectPathLock_);
53+
5354 isRegistrationSuccessful = addDBusInterfaceHandler (dbusStubAdapterHandlerPath, dbusStubAdapter);
5455
5556 if (isRegistrationSuccessful && dbusStubAdapter->hasFreedesktopProperties ()) {
@@ -109,7 +110,6 @@ bool DBusObjectManager::registerDBusStubAdapter(std::shared_ptr<DBusStubAdapter>
109110 dbusConnection->registerObjectPath (dbusStubAdapterObjectPath);
110111 }
111112 }
112- objectPathLock_.unlock ();
113113
114114 return isRegistrationSuccessful;
115115}
@@ -121,7 +121,8 @@ bool DBusObjectManager::unregisterDBusStubAdapter(std::shared_ptr<DBusStubAdapte
121121 DBusInterfaceHandlerPath dbusStubAdapterHandlerPath (dbusStubAdapterObjectPath, dbusStubAdapterInterfaceName);
122122 bool isDeregistrationSuccessful = false ;
123123
124- objectPathLock_.lock ();
124+ std::lock_guard<std::recursive_mutex> itsLock (objectPathLock_);
125+
125126 isDeregistrationSuccessful = removeDBusInterfaceHandler (dbusStubAdapterHandlerPath, dbusStubAdapter);
126127
127128 if (isDeregistrationSuccessful && dbusStubAdapter->isManaging ()) {
@@ -162,13 +163,13 @@ bool DBusObjectManager::unregisterDBusStubAdapter(std::shared_ptr<DBusStubAdapte
162163 }
163164 }
164165
165- objectPathLock_.unlock ();
166-
167166 return isDeregistrationSuccessful;
168167}
169168
170169
171170bool DBusObjectManager::exportManagedDBusStubAdapter (const std::string& parentObjectPath, std::shared_ptr<DBusStubAdapter> dbusStubAdapter) {
171+ std::lock_guard<std::recursive_mutex> itsLock (objectPathLock_);
172+
172173 auto foundManagerStubIterator = managerStubs_.find (parentObjectPath);
173174
174175 if (managerStubs_.end () == foundManagerStubIterator) {
@@ -182,6 +183,8 @@ bool DBusObjectManager::exportManagedDBusStubAdapter(const std::string& parentOb
182183
183184
184185bool DBusObjectManager::unexportManagedDBusStubAdapter (const std::string& parentObjectPath, std::shared_ptr<DBusStubAdapter> dbusStubAdapter) {
186+ std::lock_guard<std::recursive_mutex> itsLock (objectPathLock_);
187+
185188 auto foundManagerStubIterator = managerStubs_.find (parentObjectPath);
186189
187190 if (foundManagerStubIterator != managerStubs_.end ()) {
@@ -208,20 +211,20 @@ bool DBusObjectManager::handleMessage(const DBusMessage& dbusMessage) {
208211
209212 DBusInterfaceHandlerPath handlerPath (objectPath, interfaceName);
210213
211- objectPathLock_.lock ();
214+ std::unique_lock<std::recursive_mutex> itsLock (objectPathLock_);
215+
212216 auto handlerIterator = dbusRegisteredObjectsTable_.find (handlerPath);
213217 const bool foundDBusInterfaceHandler = handlerIterator != dbusRegisteredObjectsTable_.end ();
214218 bool dbusMessageHandled = false ;
215219
216220 if (foundDBusInterfaceHandler) {
217221 std::shared_ptr<DBusInterfaceHandler> dbusStubAdapterBase = handlerIterator->second .front ();
218- objectPathLock_ .unlock ();
222+ itsLock .unlock ();
219223 dbusMessageHandled = dbusStubAdapterBase->onInterfaceDBusMessage (dbusMessage);
220224 return dbusMessageHandled;
221225 } else if (dbusMessage.hasInterfaceName (" org.freedesktop.DBus.Introspectable" )) {
222226 dbusMessageHandled = onIntrospectableInterfaceDBusMessage (dbusMessage);
223227 }
224- objectPathLock_.unlock ();
225228
226229 return dbusMessageHandled;
227230}
0 commit comments