Bug 981239 - Use atomic ref-counting for |UnixSocketConsumer|. r=kyle, a=1.3+
authorThomas Zimmermann <tdz@users.sourceforge.net>
Tue, 08 Apr 2014 09:27:47 +0200
changeset 192703 a66f9902be7c56e4568c4f82e2fa28f1763ab771
parent 192702 011dca98f06a186149e3542acb70f3413ab71ff0
child 192704 57ff0e0d37b7f20dc9d0adb4497fef4d88993fa0
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskyle, 1
bugs981239
milestone30.0a2
Bug 981239 - Use atomic ref-counting for |UnixSocketConsumer|. r=kyle, a=1.3+ |SocketSendTask| acquires a reference to |UnixSocketConsumer| on the main thread and releases this reference on the I/O thread; leading to race-conditions. This patch adds - atomicity for ref-counting of |UnixSocketConsumer|, and - stricter tests in the destructor of this class.
ipc/unixsocket/UnixSocket.cpp
ipc/unixsocket/UnixSocket.h
--- a/ipc/unixsocket/UnixSocket.cpp
+++ b/ipc/unixsocket/UnixSocket.cpp
@@ -734,16 +734,18 @@ UnixSocketConsumer::UnixSocketConsumer()
                                          , mConnectionStatus(SOCKET_DISCONNECTED)
                                          , mConnectTimestamp(0)
                                          , mConnectDelayMs(0)
 {
 }
 
 UnixSocketConsumer::~UnixSocketConsumer()
 {
+  MOZ_ASSERT(mConnectionStatus == SOCKET_DISCONNECTED);
+  MOZ_ASSERT(!mImpl);
 }
 
 bool
 UnixSocketConsumer::SendSocketData(UnixSocketRawData* aData)
 {
   MOZ_ASSERT(NS_IsMainThread());
   if (!mImpl) {
     return false;
--- a/ipc/unixsocket/UnixSocket.h
+++ b/ipc/unixsocket/UnixSocket.h
@@ -130,17 +130,17 @@ public:
 
 enum SocketConnectionStatus {
   SOCKET_DISCONNECTED = 0,
   SOCKET_LISTENING = 1,
   SOCKET_CONNECTING = 2,
   SOCKET_CONNECTED = 3
 };
 
-class UnixSocketConsumer : public RefCounted<UnixSocketConsumer>
+class UnixSocketConsumer : public AtomicRefCounted<UnixSocketConsumer>
 {
 public:
   MOZ_DECLARE_REFCOUNTED_TYPENAME(UnixSocketConsumer)
   UnixSocketConsumer();
 
   virtual ~UnixSocketConsumer();
 
   SocketConnectionStatus GetConnectionStatus() const