Bug 891866: Support nsRefPtr<RawDBusConnection>, r=qdot
authorThomas Zimmermann <tdz@users.sourceforge.net>
Mon, 22 Jul 2013 13:30:22 +0200
changeset 139420 ab10a0ab68ccfc2dab0be22c065f19ba539bece6
parent 139419 4908c35e50970441f345a76e78e9f6bcbc112adb
child 139421 f8bc8d25e15a95510852ca3eddab819b03a96ca0
push id1902
push userryanvm@gmail.com
push dateTue, 23 Jul 2013 01:50:24 +0000
treeherderfx-team@47298789df93 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs891866
milestone25.0a1
Bug 891866: Support nsRefPtr<RawDBusConnection>, r=qdot Instances of RawDBusConnection can now be contained in nsRefPtr. This allows to share the DBus connection among multiple threads.
dom/bluetooth/linux/BluetoothDBusService.cpp
ipc/dbus/DBusThread.cpp
ipc/dbus/RawDBusConnection.cpp
ipc/dbus/RawDBusConnection.h
--- a/dom/bluetooth/linux/BluetoothDBusService.cpp
+++ b/dom/bluetooth/linux/BluetoothDBusService.cpp
@@ -143,17 +143,17 @@ static const char* sBluetoothDBusSignals
   "type='signal',interface='org.bluez.AudioSink'"
 };
 
 /**
  * DBus Connection held for the BluetoothCommandThread to use. Should never be
  * used by any other thread.
  *
  */
-static nsAutoPtr<RawDBusConnection> gThreadConnection;
+static nsRefPtr<RawDBusConnection> gThreadConnection;
 static nsDataHashtable<nsStringHashKey, DBusMessage* > sPairingReqTable;
 static nsDataHashtable<nsStringHashKey, DBusMessage* > sAuthorizeReqTable;
 static Atomic<int32_t> sIsPairing;
 static nsString sAdapterPath;
 
 typedef void (*UnpackFunc)(DBusMessage*, DBusError*, BluetoothValue&, nsAString&);
 typedef bool (*FilterFunc)(const BluetoothValue&);
 typedef void (*SinkCallback)(DBusMessage*, void*);
--- a/ipc/dbus/DBusThread.cpp
+++ b/ipc/dbus/DBusThread.cpp
@@ -481,28 +481,28 @@ public:
 
     return NS_OK;
   }
 
 private:
   DBusThread* mConnection;
 };
 
-static StaticAutoPtr<DBusThread> gDBusThread;
-static StaticRefPtr<nsIThread>   gDBusServiceThread;
+static StaticRefPtr<DBusThread> gDBusThread;
+static StaticRefPtr<nsIThread>  gDBusServiceThread;
 
 // Startup/Shutdown utility functions
 
 bool
 StartDBus()
 {
   MOZ_ASSERT(!NS_IsMainThread());
   NS_ENSURE_TRUE(!gDBusThread, true);
 
-  nsAutoPtr<DBusThread> dbusThread(new DBusThread());
+  nsRefPtr<DBusThread> dbusThread(new DBusThread());
 
   bool eventLoopStarted = dbusThread->Initialize();
   NS_ENSURE_TRUE(eventLoopStarted, false);
 
   nsresult rv;
 
   if (!gDBusServiceThread) {
     nsIThread* dbusServiceThread;
@@ -516,17 +516,17 @@ StartDBus()
 #endif
 
   nsRefPtr<nsIRunnable> pollTask(new DBusPollTask(dbusThread));
   NS_ENSURE_TRUE(pollTask, false);
 
   rv = gDBusServiceThread->Dispatch(pollTask, NS_DISPATCH_NORMAL);
   NS_ENSURE_SUCCESS(rv, false);
 
-  gDBusThread = dbusThread.forget();
+  gDBusThread = dbusThread;
 
   return true;
 }
 
 bool
 StopDBus()
 {
   MOZ_ASSERT(!NS_IsMainThread());
--- a/ipc/dbus/RawDBusConnection.cpp
+++ b/ipc/dbus/RawDBusConnection.cpp
@@ -6,20 +6,22 @@
 
 #include "RawDBusConnection.h"
 #include <dbus/dbus.h>
 
 using namespace mozilla::ipc;
 
 bool RawDBusConnection::sDBusIsInit(false);
 
-RawDBusConnection::RawDBusConnection() {
+RawDBusConnection::RawDBusConnection()
+{
 }
 
-RawDBusConnection::~RawDBusConnection() {
+RawDBusConnection::~RawDBusConnection()
+{
 }
 
 nsresult RawDBusConnection::EstablishDBusConnection()
 {
   if (!sDBusIsInit) {
     dbus_bool_t success = dbus_threads_init_default();
     NS_ENSURE_TRUE(success == TRUE, NS_ERROR_FAILURE);
     sDBusIsInit = true;
--- a/ipc/dbus/RawDBusConnection.h
+++ b/ipc/dbus/RawDBusConnection.h
@@ -9,33 +9,34 @@
 
 #include <string.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <string>
 #include <stdlib.h>
 #include "nscore.h"
 #include "mozilla/Scoped.h"
+#include <mozilla/RefPtr.h>
 #include <mozilla/Mutex.h>
 
 struct DBusConnection;
 
 namespace mozilla {
 namespace ipc {
 
-class RawDBusConnection
+class RawDBusConnection : public detail::RefCounted<RawDBusConnection, detail::AtomicRefCount>
 {
   struct ScopedDBusConnectionPtrTraits : ScopedFreePtrTraits<DBusConnection>
   {
     static void release(DBusConnection* ptr);
   };
 
 public:
   RawDBusConnection();
-  ~RawDBusConnection();
+  virtual ~RawDBusConnection();
   nsresult EstablishDBusConnection();
   DBusConnection* GetConnection() {
     return mConnection;
   }
 
 protected:
   Scoped<ScopedDBusConnectionPtrTraits> mConnection;