diff options
author | Johannes Schanda <schanda@itestra.de> | 2013-06-10 14:28:39 +0200 |
---|---|---|
committer | Johannes Schanda <schanda@itestra.de> | 2013-06-10 14:28:39 +0200 |
commit | 60863026435438540d9981748f4671342c4137d7 (patch) | |
tree | e37bccf1f506d7ec06dae433a8511182dc7fc511 | |
parent | 303b63fbd7bfbf71d519e735bcbd6b6566685afb (diff) | |
download | genivi-common-api-dbus-runtime-60863026435438540d9981748f4671342c4137d7.tar.gz |
Correct thread teardown failure
-Correct thread teardown failure on smart pointer destruction for
internal dispatch
- Correct incorrect service async functionality due to empty master
service list
-rw-r--r-- | src/CommonAPI/DBus/DBusConnection.cpp | 11 | ||||
-rw-r--r-- | src/CommonAPI/DBus/DBusConnection.h | 3 | ||||
-rw-r--r-- | src/CommonAPI/DBus/DBusServiceRegistry.cpp | 6 |
3 files changed, 13 insertions, 7 deletions
diff --git a/src/CommonAPI/DBus/DBusConnection.cpp b/src/CommonAPI/DBus/DBusConnection.cpp index c46334d..8b69e7c 100644 --- a/src/CommonAPI/DBus/DBusConnection.cpp +++ b/src/CommonAPI/DBus/DBusConnection.cpp @@ -29,13 +29,17 @@ DBusObjectPathVTable DBusConnection::libdbusObjectPathVTable_ = { &DBusConnection::onLibdbusObjectPathMessageThunk }; -void DBusConnection::dispatch(std::shared_ptr<DBusConnection>& selfReference) { - while (!stopDispatching_ && readWriteDispatch(10) && !selfReference.unique()) { +void DBusConnection::dispatch(std::shared_ptr<DBusConnection>* selfReference) { +//void DBusConnection::dispatch() { + //auto selfReference = this->shared_from_this(); + while (!stopDispatching_ && readWriteDispatch(10) && !selfReference->unique()) { if(pauseDispatching_) { dispatchSuspendLock_.lock(); dispatchSuspendLock_.unlock(); } } + delete selfReference; + } bool DBusConnection::readWriteDispatch(int timeoutMilliseconds) { @@ -259,7 +263,8 @@ bool DBusConnection::connect(DBusError& dbusError, bool startDispatchThread) { initLibdbusSignalFilterAfterConnect(); if(startDispatchThread) { - dispatchThread_ = new std::thread(&DBusConnection::dispatch, this, std::move(this->shared_from_this())); + std::shared_ptr<DBusConnection>* ptr = new std::shared_ptr<DBusConnection>(this->shared_from_this()); + dispatchThread_ = new std::thread(&DBusConnection::dispatch, this, ptr); } stopDispatching_ = !startDispatchThread; diff --git a/src/CommonAPI/DBus/DBusConnection.h b/src/CommonAPI/DBus/DBusConnection.h index 145d653..5f19d7b 100644 --- a/src/CommonAPI/DBus/DBusConnection.h +++ b/src/CommonAPI/DBus/DBusConnection.h @@ -115,7 +115,8 @@ class DBusConnection: public DBusProxyConnection, public std::enable_shared_from bool singleDispatch(); private: - void dispatch(std::shared_ptr<DBusConnection>& selfReference); + void dispatch(std::shared_ptr<DBusConnection>* selfReference); + //void dispatch(); void suspendDispatching() const; void resumeDispatching() const; diff --git a/src/CommonAPI/DBus/DBusServiceRegistry.cpp b/src/CommonAPI/DBus/DBusServiceRegistry.cpp index a25b819..ed2fa52 100644 --- a/src/CommonAPI/DBus/DBusServiceRegistry.cpp +++ b/src/CommonAPI/DBus/DBusServiceRegistry.cpp @@ -182,17 +182,17 @@ void DBusServiceRegistry::getAvailableServiceInstancesAsync(Factory::GetAvailabl size_t stillResolvingCount = getResolvedServiceInstances(interfaceName, availableServiceInstances); - if(stillResolvingCount == 0) { + if(stillResolvingCount == 0 && !dbusServices_.empty()) { callback(availableServiceInstances); } else { //This is a necessary hack, because libdbus never returns from async calls if a //service handles it's answers the wrong way. Here an artificial timeout is //added to circumvent this limitation. std::thread( - [this, callback, interfaceName, domainName]() { + [this, callback, interfaceName, domainName](std::shared_ptr<DBusServiceRegistry> selfRef) { auto availableServiceInstances = getAvailableServiceInstances(interfaceName, domainName); callback(availableServiceInstances); - } + }, this->shared_from_this() ).detach(); } } |