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.

--HG--
extra : rebase_source : fb24472b3b55e77abc7354f17ef679661f62b7fb
This commit is contained in:
Thomas Zimmermann 2013-07-22 13:30:22 +02:00
parent 25402e86aa
commit a0003d5854
4 changed files with 12 additions and 9 deletions

View File

@ -148,7 +148,7 @@ static const char* sBluetoothDBusSignals[] =
* 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;

View File

@ -486,8 +486,8 @@ private:
DBusThread* mConnection;
};
static StaticAutoPtr<DBusThread> gDBusThread;
static StaticRefPtr<nsIThread> gDBusServiceThread;
static StaticRefPtr<DBusThread> gDBusThread;
static StaticRefPtr<nsIThread> gDBusServiceThread;
// Startup/Shutdown utility functions
@ -497,7 +497,7 @@ 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);
@ -521,7 +521,7 @@ StartDBus()
rv = gDBusServiceThread->Dispatch(pollTask, NS_DISPATCH_NORMAL);
NS_ENSURE_SUCCESS(rv, false);
gDBusThread = dbusThread.forget();
gDBusThread = dbusThread;
return true;
}

View File

@ -11,10 +11,12 @@ using namespace mozilla::ipc;
bool RawDBusConnection::sDBusIsInit(false);
RawDBusConnection::RawDBusConnection() {
RawDBusConnection::RawDBusConnection()
{
}
RawDBusConnection::~RawDBusConnection() {
RawDBusConnection::~RawDBusConnection()
{
}
nsresult RawDBusConnection::EstablishDBusConnection()

View File

@ -14,6 +14,7 @@
#include <stdlib.h>
#include "nscore.h"
#include "mozilla/Scoped.h"
#include <mozilla/RefPtr.h>
#include <mozilla/Mutex.h>
struct DBusConnection;
@ -21,7 +22,7 @@ struct DBusConnection;
namespace mozilla {
namespace ipc {
class RawDBusConnection
class RawDBusConnection : public detail::RefCounted<RawDBusConnection, detail::AtomicRefCount>
{
struct ScopedDBusConnectionPtrTraits : ScopedFreePtrTraits<DBusConnection>
{
@ -30,7 +31,7 @@ class RawDBusConnection
public:
RawDBusConnection();
~RawDBusConnection();
virtual ~RawDBusConnection();
nsresult EstablishDBusConnection();
DBusConnection* GetConnection() {
return mConnection;