Bug 1168806: Use 'consumer thread' in socket interface, r=kmachulis

The socket IPC interfaces still use 'main thread' in a number of
places. This patch changes all such interfaces and documentation
to speak of 'consumer thread' instead.
This commit is contained in:
Thomas Zimmermann 2015-06-02 10:01:58 +02:00
Родитель 7c1faa403c
Коммит 974a0b5beb
15 изменённых файлов: 94 добавлений и 91 удалений

Просмотреть файл

@ -123,8 +123,8 @@ public:
/** /**
* Consumer pointer. Non-thread safe RefPtr, so should only be manipulated * Consumer pointer. Non-thread safe RefPtr, so should only be manipulated
* directly from main thread. All non-main-thread accesses should happen with * directly from consumer thread. All non-consumer-thread accesses should
* mImpl as container. * happen with mImpl as container.
*/ */
RefPtr<BluetoothSocket> mConsumer; RefPtr<BluetoothSocket> mConsumer;
@ -143,7 +143,7 @@ public:
return GetDataSocket(); return GetDataSocket();
} }
bool IsShutdownOnMainThread() const override bool IsShutdownOnConsumerThread() const override
{ {
MOZ_ASSERT(IsConsumerThread()); MOZ_ASSERT(IsConsumerThread());
@ -155,10 +155,11 @@ public:
return mShuttingDownOnIOThread; return mShuttingDownOnIOThread;
} }
void ShutdownOnMainThread() override void ShutdownOnConsumerThread() override
{ {
MOZ_ASSERT(IsConsumerThread()); MOZ_ASSERT(IsConsumerThread());
MOZ_ASSERT(!IsShutdownOnMainThread()); MOZ_ASSERT(!IsShutdownOnConsumerThread());
mConsumer = nullptr; mConsumer = nullptr;
} }
@ -392,7 +393,7 @@ public:
mozilla::ScopedClose fd(aFd); // Close received socket fd on error mozilla::ScopedClose fd(aFd); // Close received socket fd on error
if (mImpl->IsShutdownOnMainThread()) { if (mImpl->IsShutdownOnConsumerThread()) {
BT_LOGD("mConsumer is null, aborting receive!"); BT_LOGD("mConsumer is null, aborting receive!");
return; return;
} }
@ -412,7 +413,7 @@ public:
MOZ_ASSERT(mImpl->IsConsumerThread()); MOZ_ASSERT(mImpl->IsConsumerThread());
BT_LOGR("BluetoothSocketInterface::Accept failed: %d", (int)aStatus); BT_LOGR("BluetoothSocketInterface::Accept failed: %d", (int)aStatus);
if (!mImpl->IsShutdownOnMainThread()) { if (!mImpl->IsShutdownOnConsumerThread()) {
// Instead of NotifyError(), call NotifyDisconnect() to trigger // Instead of NotifyError(), call NotifyDisconnect() to trigger
// BluetoothOppManager::OnSocketDisconnect() as // BluetoothOppManager::OnSocketDisconnect() as
// DroidSocketImpl::OnFileCanReadWithoutBlocking() in Firefox OS 2.0 in // DroidSocketImpl::OnFileCanReadWithoutBlocking() in Firefox OS 2.0 in
@ -534,7 +535,7 @@ DroidSocketImpl::QueryReceiveBuffer(
/** /**
* |ReceiveRunnable| transfers data received on the I/O thread * |ReceiveRunnable| transfers data received on the I/O thread
* to an instance of |BluetoothSocket| on the main thread. * to an instance of |BluetoothSocket| on the consumer thread.
*/ */
class DroidSocketImpl::ReceiveRunnable final class DroidSocketImpl::ReceiveRunnable final
: public SocketIORunnable<DroidSocketImpl> : public SocketIORunnable<DroidSocketImpl>
@ -551,7 +552,7 @@ public:
MOZ_ASSERT(io->IsConsumerThread()); MOZ_ASSERT(io->IsConsumerThread());
if (NS_WARN_IF(io->IsShutdownOnMainThread())) { if (NS_WARN_IF(io->IsShutdownOnConsumerThread())) {
// Since we've already explicitly closed and the close // Since we've already explicitly closed and the close
// happened before this, this isn't really an error. // happened before this, this isn't really an error.
return NS_OK; return NS_OK;
@ -611,7 +612,7 @@ public:
{ {
MOZ_ASSERT(mImpl->IsConsumerThread()); MOZ_ASSERT(mImpl->IsConsumerThread());
if (mImpl->IsShutdownOnMainThread()) { if (mImpl->IsShutdownOnConsumerThread()) {
BT_LOGD("mConsumer is null, aborting send!"); BT_LOGD("mConsumer is null, aborting send!");
return; return;
} }
@ -631,7 +632,7 @@ public:
MOZ_ASSERT(mImpl->IsConsumerThread()); MOZ_ASSERT(mImpl->IsConsumerThread());
BT_WARNING("Connect failed: %d", (int)aStatus); BT_WARNING("Connect failed: %d", (int)aStatus);
if (!mImpl->IsShutdownOnMainThread()) { if (!mImpl->IsShutdownOnConsumerThread()) {
// Instead of NotifyError(), call NotifyDisconnect() to trigger // Instead of NotifyError(), call NotifyDisconnect() to trigger
// BluetoothOppManager::OnSocketDisconnect() as // BluetoothOppManager::OnSocketDisconnect() as
// DroidSocketImpl::OnFileCanReadWithoutBlocking() in Firefox OS 2.0 in // DroidSocketImpl::OnFileCanReadWithoutBlocking() in Firefox OS 2.0 in
@ -772,7 +773,7 @@ BluetoothSocket::SendSocketData(UnixSocketIOBuffer* aBuffer)
{ {
MOZ_ASSERT(mImpl); MOZ_ASSERT(mImpl);
MOZ_ASSERT(mImpl->IsConsumerThread()); MOZ_ASSERT(mImpl->IsConsumerThread());
MOZ_ASSERT(!mImpl->IsShutdownOnMainThread()); MOZ_ASSERT(!mImpl->IsShutdownOnConsumerThread());
mImpl->GetIOLoop()->PostTask( mImpl->GetIOLoop()->PostTask(
FROM_HERE, FROM_HERE,
@ -800,7 +801,7 @@ BluetoothSocket::Close()
// From this point on, we consider mImpl as being deleted. // From this point on, we consider mImpl as being deleted.
// We sever the relationship here so any future calls to listen or connect // We sever the relationship here so any future calls to listen or connect
// will create a new implementation. // will create a new implementation.
mImpl->ShutdownOnMainThread(); mImpl->ShutdownOnConsumerThread();
mImpl->GetIOLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mImpl)); mImpl->GetIOLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mImpl));
mImpl = nullptr; mImpl = nullptr;

Просмотреть файл

@ -54,7 +54,7 @@ public:
/** /**
* Method to be called whenever data is received. This is only called on the * Method to be called whenever data is received. This is only called on the
* main thread. * consumer thread.
* *
* @param aBuffer Data received from the socket. * @param aBuffer Data received from the socket.
*/ */

Просмотреть файл

@ -83,10 +83,10 @@ public:
SocketBase* GetSocketBase() override; SocketBase* GetSocketBase() override;
bool IsShutdownOnMainThread() const override; bool IsShutdownOnConsumerThread() const override;
bool IsShutdownOnIOThread() const override; bool IsShutdownOnIOThread() const override;
void ShutdownOnMainThread() override; void ShutdownOnConsumerThread() override;
void ShutdownOnIOThread() override; void ShutdownOnIOThread() override;
private: private:
@ -96,8 +96,8 @@ private:
/** /**
* Consumer pointer. Non-thread safe RefPtr, so should only be manipulated * Consumer pointer. Non-thread safe RefPtr, so should only be manipulated
* directly from main thread. All non-main-thread accesses should happen with * directly from consumer thread. All non-consumer-thread accesses should
* mIO as container. * happen with mIO as container.
*/ */
RefPtr<BluetoothSocket> mConsumer; RefPtr<BluetoothSocket> mConsumer;
@ -122,7 +122,8 @@ private:
struct sockaddr_storage mAddress; struct sockaddr_storage mAddress;
/** /**
* Task member for delayed connect task. Should only be access on main thread. * Task member for delayed connect task. Should only be access on consumer
* thread.
*/ */
CancelableTask* mDelayedConnectTask; CancelableTask* mDelayedConnectTask;
@ -152,7 +153,7 @@ BluetoothSocket::BluetoothSocketIO::BluetoothSocketIO(
BluetoothSocket::BluetoothSocketIO::~BluetoothSocketIO() BluetoothSocket::BluetoothSocketIO::~BluetoothSocketIO()
{ {
MOZ_ASSERT(IsConsumerThread()); MOZ_ASSERT(IsConsumerThread());
MOZ_ASSERT(IsShutdownOnMainThread()); MOZ_ASSERT(IsShutdownOnConsumerThread());
} }
void void
@ -380,7 +381,7 @@ BluetoothSocket::BluetoothSocketIO::FireSocketError()
// Clean up watchers, statuses, fds // Clean up watchers, statuses, fds
Close(); Close();
// Tell the main thread we've errored // Tell the consumer thread we've errored
GetConsumerThread()->Dispatch( GetConsumerThread()->Dispatch(
new SocketIOEventRunnable(this, SocketIOEventRunnable::CONNECT_ERROR), new SocketIOEventRunnable(this, SocketIOEventRunnable::CONNECT_ERROR),
NS_DISPATCH_NORMAL); NS_DISPATCH_NORMAL);
@ -405,7 +406,7 @@ BluetoothSocket::BluetoothSocketIO::QueryReceiveBuffer(
/** /**
* |ReceiveRunnable| transfers data received on the I/O thread * |ReceiveRunnable| transfers data received on the I/O thread
* to an instance of |BluetoothSocket| on the main thread. * to an instance of |BluetoothSocket| on the consumer thread.
*/ */
class BluetoothSocket::BluetoothSocketIO::ReceiveRunnable final class BluetoothSocket::BluetoothSocketIO::ReceiveRunnable final
: public SocketIORunnable<BluetoothSocketIO> : public SocketIORunnable<BluetoothSocketIO>
@ -422,7 +423,7 @@ public:
MOZ_ASSERT(io->IsConsumerThread()); MOZ_ASSERT(io->IsConsumerThread());
if (NS_WARN_IF(io->IsShutdownOnMainThread())) { if (NS_WARN_IF(io->IsShutdownOnConsumerThread())) {
// Since we've already explicitly closed and the close // Since we've already explicitly closed and the close
// happened before this, this isn't really an error. // happened before this, this isn't really an error.
return NS_OK; return NS_OK;
@ -462,7 +463,7 @@ BluetoothSocket::BluetoothSocketIO::GetSocketBase()
} }
bool bool
BluetoothSocket::BluetoothSocketIO::IsShutdownOnMainThread() const BluetoothSocket::BluetoothSocketIO::IsShutdownOnConsumerThread() const
{ {
MOZ_ASSERT(IsConsumerThread()); MOZ_ASSERT(IsConsumerThread());
@ -470,10 +471,10 @@ BluetoothSocket::BluetoothSocketIO::IsShutdownOnMainThread() const
} }
void void
BluetoothSocket::BluetoothSocketIO::ShutdownOnMainThread() BluetoothSocket::BluetoothSocketIO::ShutdownOnConsumerThread()
{ {
MOZ_ASSERT(IsConsumerThread()); MOZ_ASSERT(IsConsumerThread());
MOZ_ASSERT(!IsShutdownOnMainThread()); MOZ_ASSERT(!IsShutdownOnConsumerThread());
mConsumer = nullptr; mConsumer = nullptr;
} }
@ -551,7 +552,7 @@ public:
} }
BluetoothSocketIO* io = GetIO(); BluetoothSocketIO* io = GetIO();
if (io->IsShutdownOnMainThread()) { if (io->IsShutdownOnConsumerThread()) {
return; return;
} }
@ -730,7 +731,7 @@ BluetoothSocket::SendSocketData(UnixSocketIOBuffer* aBuffer)
{ {
MOZ_ASSERT(mIO); MOZ_ASSERT(mIO);
MOZ_ASSERT(mIO->IsConsumerThread()); MOZ_ASSERT(mIO->IsConsumerThread());
MOZ_ASSERT(!mIO->IsShutdownOnMainThread()); MOZ_ASSERT(!mIO->IsShutdownOnConsumerThread());
mIO->GetIOLoop()->PostTask( mIO->GetIOLoop()->PostTask(
FROM_HERE, FROM_HERE,
@ -753,7 +754,7 @@ BluetoothSocket::Close()
// From this point on, we consider mIO as being deleted. // From this point on, we consider mIO as being deleted.
// We sever the relationship here so any future calls to listen or connect // We sever the relationship here so any future calls to listen or connect
// will create a new implementation. // will create a new implementation.
mIO->ShutdownOnMainThread(); mIO->ShutdownOnConsumerThread();
mIO->GetIOLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO)); mIO->GetIOLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
mIO = nullptr; mIO = nullptr;

Просмотреть файл

@ -43,7 +43,7 @@ public:
/** /**
* Method to be called whenever data is received. This is only called on the * Method to be called whenever data is received. This is only called on the
* main thread. * consumer thread.
* *
* @param aBuffer Data received from the socket. * @param aBuffer Data received from the socket.
*/ */

Просмотреть файл

@ -242,10 +242,10 @@ public:
SocketBase* GetSocketBase() override; SocketBase* GetSocketBase() override;
bool IsShutdownOnMainThread() const override; bool IsShutdownOnConsumerThread() const override;
bool IsShutdownOnIOThread() const override; bool IsShutdownOnIOThread() const override;
void ShutdownOnMainThread() override; void ShutdownOnConsumerThread() override;
void ShutdownOnIOThread() override; void ShutdownOnIOThread() override;
private: private:
@ -332,7 +332,7 @@ BluetoothDaemonConnectionIO::OnError(const char* aFunction, int aErrno)
// Clean up watchers, status, fd // Clean up watchers, status, fd
Close(); Close();
// Tell the main thread we've errored // Tell the consumer thread we've errored
GetConsumerThread()->Dispatch( GetConsumerThread()->Dispatch(
new SocketIOEventRunnable(this, SocketIOEventRunnable::CONNECT_ERROR), new SocketIOEventRunnable(this, SocketIOEventRunnable::CONNECT_ERROR),
NS_DISPATCH_NORMAL); NS_DISPATCH_NORMAL);
@ -403,7 +403,7 @@ BluetoothDaemonConnectionIO::GetSocketBase()
} }
bool bool
BluetoothDaemonConnectionIO::IsShutdownOnMainThread() const BluetoothDaemonConnectionIO::IsShutdownOnConsumerThread() const
{ {
MOZ_ASSERT(IsConsumerThread()); MOZ_ASSERT(IsConsumerThread());
@ -417,10 +417,10 @@ BluetoothDaemonConnectionIO::IsShutdownOnIOThread() const
} }
void void
BluetoothDaemonConnectionIO::ShutdownOnMainThread() BluetoothDaemonConnectionIO::ShutdownOnConsumerThread()
{ {
MOZ_ASSERT(IsConsumerThread()); MOZ_ASSERT(IsConsumerThread());
MOZ_ASSERT(!IsShutdownOnMainThread()); MOZ_ASSERT(!IsShutdownOnConsumerThread());
mConnection = nullptr; mConnection = nullptr;
} }
@ -505,7 +505,7 @@ BluetoothDaemonConnection::Close()
MOZ_ASSERT(mIO->IsConsumerThread()); MOZ_ASSERT(mIO->IsConsumerThread());
mIO->ShutdownOnMainThread(); mIO->ShutdownOnConsumerThread();
mIO->GetIOLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO)); mIO->GetIOLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
mIO = nullptr; mIO = nullptr;

Просмотреть файл

@ -94,7 +94,7 @@ private:
/* /*
* |BluetoothDaemonPDUConsumer| processes incoming PDUs from the Bluetooth * |BluetoothDaemonPDUConsumer| processes incoming PDUs from the Bluetooth
* daemon. Please note that its method |Handle| runs on a different than the * daemon. Please note that its method |Handle| runs on a different than the
* main thread. * consumer thread.
*/ */
class BluetoothDaemonPDUConsumer class BluetoothDaemonPDUConsumer
{ {

Просмотреть файл

@ -22,21 +22,21 @@ class BluetoothDaemonConnectionConsumer
{ {
public: public:
/** /**
* Callback for socket success. Main-thread only. * Callback for socket success. Consumer-thread only.
* *
* @param aIndex The index that has been given to the stream socket. * @param aIndex The index that has been given to the stream socket.
*/ */
virtual void OnConnectSuccess(int aIndex) = 0; virtual void OnConnectSuccess(int aIndex) = 0;
/** /**
* Callback for socket errors. Main-thread only. * Callback for socket errors. Consumer-thread only.
* *
* @param aIndex The index that has been given to the stream socket. * @param aIndex The index that has been given to the stream socket.
*/ */
virtual void OnConnectError(int aIndex) = 0; virtual void OnConnectError(int aIndex) = 0;
/** /**
* Callback for socket disconnect. Main-thread only. * Callback for socket disconnect. Consumer-thread only.
* *
* @param aIndex The index that has been given to the stream socket. * @param aIndex The index that has been given to the stream socket.
*/ */

Просмотреть файл

@ -19,7 +19,7 @@ class UnixSocketConnector;
/* /*
* |ConnectionOrientedSocketIO| and |ConnectionOrientedSocket| define * |ConnectionOrientedSocketIO| and |ConnectionOrientedSocket| define
* interfaces for implementing stream sockets on I/O and main thread. * interfaces for implementing stream sockets on I/O and consumer thread.
* |ListenSocket| uses these classes to handle accepted sockets. * |ListenSocket| uses these classes to handle accepted sockets.
*/ */
@ -39,7 +39,7 @@ class ConnectionOrientedSocket : public DataSocket
public: public:
/** /**
* Prepares an instance of |ConnectionOrientedSocket| in DISCONNECTED * Prepares an instance of |ConnectionOrientedSocket| in DISCONNECTED
* state for accepting a connection. Main-thread only. * state for accepting a connection. Consumer-thread only.
* *
* @param aConnector The new connector object, owned by the * @param aConnector The new connector object, owned by the
* connection-oriented socket. * connection-oriented socket.

Просмотреть файл

@ -56,10 +56,10 @@ public:
SocketBase* GetSocketBase() override; SocketBase* GetSocketBase() override;
bool IsShutdownOnMainThread() const override; bool IsShutdownOnConsumerThread() const override;
bool IsShutdownOnIOThread() const override; bool IsShutdownOnIOThread() const override;
void ShutdownOnMainThread() override; void ShutdownOnConsumerThread() override;
void ShutdownOnIOThread() override; void ShutdownOnIOThread() override;
private: private:
@ -67,8 +67,8 @@ private:
/** /**
* Consumer pointer. Non-thread safe RefPtr, so should only be manipulated * Consumer pointer. Non-thread safe RefPtr, so should only be manipulated
* directly from main thread. All non-main-thread accesses should happen with * directly from consumer thread. All non-consumer-thread accesses should
* mIO as container. * happen with mIO as container.
*/ */
RefPtr<ListenSocket> mListenSocket; RefPtr<ListenSocket> mListenSocket;
@ -114,7 +114,7 @@ ListenSocketIO::ListenSocketIO(nsIThread* aConsumerThread,
ListenSocketIO::~ListenSocketIO() ListenSocketIO::~ListenSocketIO()
{ {
MOZ_ASSERT(IsConsumerThread()); MOZ_ASSERT(IsConsumerThread());
MOZ_ASSERT(IsShutdownOnMainThread()); MOZ_ASSERT(IsShutdownOnConsumerThread());
} }
UnixSocketConnector* UnixSocketConnector*
@ -190,7 +190,7 @@ ListenSocketIO::FireSocketError()
// Clean up watchers, statuses, fds // Clean up watchers, statuses, fds
Close(); Close();
// Tell the main thread we've errored // Tell the consumer thread we've errored
GetConsumerThread()->Dispatch( GetConsumerThread()->Dispatch(
new SocketIOEventRunnable(this, SocketIOEventRunnable::CONNECT_ERROR), new SocketIOEventRunnable(this, SocketIOEventRunnable::CONNECT_ERROR),
NS_DISPATCH_NORMAL); NS_DISPATCH_NORMAL);
@ -232,7 +232,7 @@ ListenSocketIO::GetSocketBase()
} }
bool bool
ListenSocketIO::IsShutdownOnMainThread() const ListenSocketIO::IsShutdownOnConsumerThread() const
{ {
MOZ_ASSERT(IsConsumerThread()); MOZ_ASSERT(IsConsumerThread());
@ -246,10 +246,10 @@ ListenSocketIO::IsShutdownOnIOThread() const
} }
void void
ListenSocketIO::ShutdownOnMainThread() ListenSocketIO::ShutdownOnConsumerThread()
{ {
MOZ_ASSERT(IsConsumerThread()); MOZ_ASSERT(IsConsumerThread());
MOZ_ASSERT(!IsShutdownOnMainThread()); MOZ_ASSERT(!IsShutdownOnConsumerThread());
mListenSocket = nullptr; mListenSocket = nullptr;
} }
@ -391,7 +391,7 @@ ListenSocket::Close()
// From this point on, we consider mIO as being deleted. We sever // From this point on, we consider mIO as being deleted. We sever
// the relationship here so any future calls to listen or connect // the relationship here so any future calls to listen or connect
// will create a new implementation. // will create a new implementation.
mIO->ShutdownOnMainThread(); mIO->ShutdownOnConsumerThread();
mIO->GetIOLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO)); mIO->GetIOLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
mIO = nullptr; mIO = nullptr;

Просмотреть файл

@ -19,21 +19,21 @@ public:
virtual ~ListenSocketConsumer(); virtual ~ListenSocketConsumer();
/** /**
* Callback for socket success. Main-thread only. * Callback for socket success. Consumer-thread only.
* *
* @param aIndex The index that has been given to the listening socket. * @param aIndex The index that has been given to the listening socket.
*/ */
virtual void OnConnectSuccess(int aIndex) = 0; virtual void OnConnectSuccess(int aIndex) = 0;
/** /**
* Callback for socket errors. Main-thread only. * Callback for socket errors. Consumer-thread only.
* *
* @param aIndex The index that has been given to the listening socket. * @param aIndex The index that has been given to the listening socket.
*/ */
virtual void OnConnectError(int aIndex) = 0; virtual void OnConnectError(int aIndex) = 0;
/** /**
* Callback for socket disconnect. Main-thread only. * Callback for socket disconnect. Consumer-thread only.
* *
* @param aIndex The index that has been given to the listeing socket. * @param aIndex The index that has been given to the listeing socket.
*/ */

Просмотреть файл

@ -302,7 +302,7 @@ SocketIOEventRunnable::Run()
MOZ_ASSERT(io->IsConsumerThread()); MOZ_ASSERT(io->IsConsumerThread());
if (NS_WARN_IF(io->IsShutdownOnMainThread())) { if (NS_WARN_IF(io->IsShutdownOnConsumerThread())) {
// Since we've already explicitly closed and the close // Since we've already explicitly closed and the close
// happened before this, this isn't really an error. // happened before this, this isn't really an error.
return NS_OK; return NS_OK;
@ -338,7 +338,7 @@ SocketIORequestClosingRunnable::Run()
MOZ_ASSERT(io->IsConsumerThread()); MOZ_ASSERT(io->IsConsumerThread());
if (NS_WARN_IF(io->IsShutdownOnMainThread())) { if (NS_WARN_IF(io->IsShutdownOnConsumerThread())) {
// Since we've already explicitly closed and the close // Since we've already explicitly closed and the close
// happened before this, this isn't really an error. // happened before this, this isn't really an error.
return NS_OK; return NS_OK;
@ -388,8 +388,8 @@ SocketIOShutdownTask::Run()
// At this point, there should be no new events on the I/O thread // At this point, there should be no new events on the I/O thread
// after this one with the possible exception of an accept task, // after this one with the possible exception of an accept task,
// which ShutdownOnIOThread will cancel for us. We are now fully // which ShutdownOnIOThread will cancel for us. We are now fully
// shut down, so we can send a message to the main thread to delete // shut down, so we can send a message to the consumer thread to
// |io| safely knowing that it's not reference any longer. // delete |io| safely knowing that it's not reference any longer.
io->ShutdownOnIOThread(); io->ShutdownOnIOThread();
io->GetConsumerThread()->Dispatch(new SocketIODeleteInstanceRunnable(io), io->GetConsumerThread()->Dispatch(new SocketIODeleteInstanceRunnable(io),
NS_DISPATCH_NORMAL); NS_DISPATCH_NORMAL);

Просмотреть файл

@ -256,23 +256,23 @@ public:
/** /**
* Queues the internal representation of socket for deletion. Can be called * Queues the internal representation of socket for deletion. Can be called
* from main thread. * from consumer thread.
*/ */
virtual void Close() = 0; virtual void Close() = 0;
/** /**
* Callback for socket connect/accept success. Called after connect/accept has * Callback for socket connect/accept success. Called after connect/accept has
* finished. Will be run on main thread, before any reads take place. * finished. Will be run on consumer thread before any reads take place.
*/ */
virtual void OnConnectSuccess() = 0; virtual void OnConnectSuccess() = 0;
/** /**
* Callback for socket connect/accept error. Will be run on main thread. * Callback for socket connect/accept error. Will be run on consumer thread.
*/ */
virtual void OnConnectError() = 0; virtual void OnConnectError() = 0;
/** /**
* Callback for socket disconnect. Will be run on main thread. * Callback for socket disconnect. Will be run on consumer thread.
*/ */
virtual void OnDisconnect() = 0; virtual void OnDisconnect() = 0;
@ -340,7 +340,7 @@ public:
* *
* @return True if the socket class has been shut down, false otherwise. * @return True if the socket class has been shut down, false otherwise.
*/ */
virtual bool IsShutdownOnMainThread() const = 0; virtual bool IsShutdownOnConsumerThread() const = 0;
/** /**
* Signals to the socket I/O classes that it has been shut down. * Signals to the socket I/O classes that it has been shut down.
@ -351,7 +351,7 @@ public:
* Signals to the socket I/O classes that the socket class has been * Signals to the socket I/O classes that the socket class has been
* shut down. * shut down.
*/ */
virtual void ShutdownOnMainThread() = 0; virtual void ShutdownOnConsumerThread() = 0;
/** /**
* Returns the consumer thread. * Returns the consumer thread.
@ -378,7 +378,7 @@ private:
// //
/* |SocketIORunnable| is a runnable for sending a message from /* |SocketIORunnable| is a runnable for sending a message from
* the I/O thread to the main thread. * the I/O thread to the consumer thread.
*/ */
template <typename T> template <typename T>
class SocketIORunnable : public nsRunnable class SocketIORunnable : public nsRunnable
@ -405,7 +405,7 @@ private:
/** /**
* |SocketIOEventRunnable| reports the connection state on the * |SocketIOEventRunnable| reports the connection state on the
* I/O thread back to the main thread. * I/O thread back to the consumer thread.
*/ */
class SocketIOEventRunnable final : public SocketIORunnable<SocketIOBase> class SocketIOEventRunnable final : public SocketIORunnable<SocketIOBase>
{ {
@ -426,7 +426,7 @@ private:
/** /**
* |SocketIORequestClosingRunnable| closes an instance of |SocketBase| * |SocketIORequestClosingRunnable| closes an instance of |SocketBase|
* to the main thread. * to the consumer thread.
*/ */
class SocketIORequestClosingRunnable final class SocketIORequestClosingRunnable final
: public SocketIORunnable<SocketIOBase> : public SocketIORunnable<SocketIOBase>
@ -438,7 +438,7 @@ public:
}; };
/** /**
* |SocketIODeleteInstanceRunnable| deletes an object on the main thread. * |SocketIODeleteInstanceRunnable| deletes an object on the consumer thread.
*/ */
class SocketIODeleteInstanceRunnable final : public nsRunnable class SocketIODeleteInstanceRunnable final : public nsRunnable
{ {
@ -493,7 +493,7 @@ private:
/** /**
* |SocketIOShutdownTask| signals shutdown to the socket I/O class on * |SocketIOShutdownTask| signals shutdown to the socket I/O class on
* the I/O thread and sends it to the main thread for destruction. * the I/O thread and sends it to the consumer thread for destruction.
*/ */
class SocketIOShutdownTask final : public SocketIOTask<SocketIOBase> class SocketIOShutdownTask final : public SocketIOTask<SocketIOBase>
{ {

Просмотреть файл

@ -88,10 +88,10 @@ public:
SocketBase* GetSocketBase() override; SocketBase* GetSocketBase() override;
bool IsShutdownOnMainThread() const override; bool IsShutdownOnConsumerThread() const override;
bool IsShutdownOnIOThread() const override; bool IsShutdownOnIOThread() const override;
void ShutdownOnMainThread() override; void ShutdownOnConsumerThread() override;
void ShutdownOnIOThread() override; void ShutdownOnIOThread() override;
private: private:
@ -99,8 +99,8 @@ private:
/** /**
* Consumer pointer. Non-thread safe RefPtr, so should only be manipulated * Consumer pointer. Non-thread safe RefPtr, so should only be manipulated
* directly from main thread. All non-main-thread accesses should happen with * directly from consumer thread. All non-consumer-thread accesses should
* mIO as container. * happen with mIO as container.
*/ */
RefPtr<StreamSocket> mStreamSocket; RefPtr<StreamSocket> mStreamSocket;
@ -125,7 +125,8 @@ private:
struct sockaddr_storage mAddress; struct sockaddr_storage mAddress;
/** /**
* Task member for delayed connect task. Should only be access on main thread. * Task member for delayed connect task. Should only be access on consumer
* thread.
*/ */
CancelableTask* mDelayedConnectTask; CancelableTask* mDelayedConnectTask;
@ -171,7 +172,7 @@ StreamSocketIO::StreamSocketIO(nsIThread* aConsumerThread,
StreamSocketIO::~StreamSocketIO() StreamSocketIO::~StreamSocketIO()
{ {
MOZ_ASSERT(IsConsumerThread()); MOZ_ASSERT(IsConsumerThread());
MOZ_ASSERT(IsShutdownOnMainThread()); MOZ_ASSERT(IsShutdownOnConsumerThread());
} }
StreamSocket* StreamSocket*
@ -319,7 +320,7 @@ StreamSocketIO::FireSocketError()
// Clean up watchers, statuses, fds // Clean up watchers, statuses, fds
Close(); Close();
// Tell the main thread we've errored // Tell the consumer thread we've errored
GetConsumerThread()->Dispatch( GetConsumerThread()->Dispatch(
new SocketIOEventRunnable(this, SocketIOEventRunnable::CONNECT_ERROR), new SocketIOEventRunnable(this, SocketIOEventRunnable::CONNECT_ERROR),
NS_DISPATCH_NORMAL); NS_DISPATCH_NORMAL);
@ -371,7 +372,7 @@ StreamSocketIO::QueryReceiveBuffer(UnixSocketIOBuffer** aBuffer)
/** /**
* |ReceiveRunnable| transfers data received on the I/O thread * |ReceiveRunnable| transfers data received on the I/O thread
* to an instance of |StreamSocket| on the main thread. * to an instance of |StreamSocket| on the consumer thread.
*/ */
class StreamSocketIO::ReceiveRunnable final class StreamSocketIO::ReceiveRunnable final
: public SocketIORunnable<StreamSocketIO> : public SocketIORunnable<StreamSocketIO>
@ -388,7 +389,7 @@ public:
MOZ_ASSERT(io->IsConsumerThread()); MOZ_ASSERT(io->IsConsumerThread());
if (NS_WARN_IF(io->IsShutdownOnMainThread())) { if (NS_WARN_IF(io->IsShutdownOnConsumerThread())) {
// Since we've already explicitly closed and the close // Since we've already explicitly closed and the close
// happened before this, this isn't really an error. // happened before this, this isn't really an error.
return NS_OK; return NS_OK;
@ -428,7 +429,7 @@ StreamSocketIO::GetSocketBase()
} }
bool bool
StreamSocketIO::IsShutdownOnMainThread() const StreamSocketIO::IsShutdownOnConsumerThread() const
{ {
MOZ_ASSERT(IsConsumerThread()); MOZ_ASSERT(IsConsumerThread());
@ -442,10 +443,10 @@ StreamSocketIO::IsShutdownOnIOThread() const
} }
void void
StreamSocketIO::ShutdownOnMainThread() StreamSocketIO::ShutdownOnConsumerThread()
{ {
MOZ_ASSERT(IsConsumerThread()); MOZ_ASSERT(IsConsumerThread());
MOZ_ASSERT(!IsShutdownOnMainThread()); MOZ_ASSERT(!IsShutdownOnConsumerThread());
mStreamSocket = nullptr; mStreamSocket = nullptr;
} }
@ -498,7 +499,7 @@ public:
} }
StreamSocketIO* io = GetIO(); StreamSocketIO* io = GetIO();
if (io->IsShutdownOnMainThread()) { if (io->IsShutdownOnConsumerThread()) {
return; return;
} }
@ -591,7 +592,7 @@ StreamSocket::SendSocketData(UnixSocketIOBuffer* aBuffer)
{ {
MOZ_ASSERT(mIO); MOZ_ASSERT(mIO);
MOZ_ASSERT(mIO->IsConsumerThread()); MOZ_ASSERT(mIO->IsConsumerThread());
MOZ_ASSERT(!mIO->IsShutdownOnMainThread()); MOZ_ASSERT(!mIO->IsShutdownOnConsumerThread());
mIO->GetIOLoop()->PostTask( mIO->GetIOLoop()->PostTask(
FROM_HERE, FROM_HERE,
@ -611,7 +612,7 @@ StreamSocket::Close()
// From this point on, we consider |mIO| as being deleted. We sever // From this point on, we consider |mIO| as being deleted. We sever
// the relationship here so any future calls to |Connect| will create // the relationship here so any future calls to |Connect| will create
// a new I/O object. // a new I/O object.
mIO->ShutdownOnMainThread(); mIO->ShutdownOnConsumerThread();
mIO->GetIOLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO)); mIO->GetIOLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
mIO = nullptr; mIO = nullptr;

Просмотреть файл

@ -30,7 +30,7 @@ public:
StreamSocket(StreamSocketConsumer* aConsumer, int aIndex); StreamSocket(StreamSocketConsumer* aConsumer, int aIndex);
/** /**
* Method to be called whenever data is received. Main-thread only. * Method to be called whenever data is received. Consumer-thread only.
* *
* @param aBuffer Data received from the socket. * @param aBuffer Data received from the socket.
*/ */

Просмотреть файл

@ -21,7 +21,7 @@ class StreamSocketConsumer
{ {
public: public:
/** /**
* Method to be called whenever data is received. Main-thread only. * Method to be called whenever data is received. Consumer-thread only.
* *
* @param aIndex The index that has been given to the stream socket. * @param aIndex The index that has been given to the stream socket.
* @param aBuffer Data received from the socket. * @param aBuffer Data received from the socket.
@ -30,21 +30,21 @@ public:
nsAutoPtr<UnixSocketBuffer>& aBuffer) = 0; nsAutoPtr<UnixSocketBuffer>& aBuffer) = 0;
/** /**
* Callback for socket success. Main-thread only. * Callback for socket success. Consumer-thread only.
* *
* @param aIndex The index that has been given to the stream socket. * @param aIndex The index that has been given to the stream socket.
*/ */
virtual void OnConnectSuccess(int aIndex) = 0; virtual void OnConnectSuccess(int aIndex) = 0;
/** /**
* Callback for socket errors. Main-thread only. * Callback for socket errors. Consumer-thread only.
* *
* @param aIndex The index that has been given to the stream socket. * @param aIndex The index that has been given to the stream socket.
*/ */
virtual void OnConnectError(int aIndex) = 0; virtual void OnConnectError(int aIndex) = 0;
/** /**
* Callback for socket disconnect. Main-thread only. * Callback for socket disconnect. Consumer-thread only.
* *
* @param aIndex The index that has been given to the stream socket. * @param aIndex The index that has been given to the stream socket.
*/ */