Backported thread teardown fix
authorJohannes Schanda <schanda@itestra.de>
Wed, 7 Aug 2013 13:28:23 +0000 (15:28 +0200)
committerStefan Laner <laner@itestra.de>
Wed, 7 Aug 2013 13:28:23 +0000 (15:28 +0200)
src/CommonAPI/DBus/DBusConnection.cpp
src/CommonAPI/DBus/DBusConnection.h

index df77e95..3b58241 100644 (file)
@@ -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, 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;
 
index 81c8cfa..cefc37e 100644 (file)
@@ -115,7 +115,7 @@ 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 suspendDispatching() const;
     void resumeDispatching() const;