Bug 1159209: Remove template parameters from |SocketIOShutdownTask|, r=kmachulis

This patch removes the template parameters from |SocketIOShutdownTask|
and moves its methods into the C++ source file. All users have been
adapted.
This commit is contained in:
Thomas Zimmermann 2015-04-29 11:19:28 +02:00
parent 1df9dd995c
commit a076ff736c
7 changed files with 69 additions and 44 deletions

View File

@ -97,19 +97,19 @@ public:
return mConsumer == nullptr;
}
bool IsShutdownOnIOThread() const
bool IsShutdownOnIOThread() const override
{
return mShuttingDownOnIOThread;
}
void ShutdownOnMainThread()
void ShutdownOnMainThread() override
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!IsShutdownOnMainThread());
mConsumer = nullptr;
}
void ShutdownOnIOThread()
void ShutdownOnIOThread() override
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(!mShuttingDownOnIOThread);
@ -725,8 +725,8 @@ BluetoothSocket::CloseSocket()
// We sever the relationship here so any future calls to listen or connect
// will create a new implementation.
mImpl->ShutdownOnMainThread();
XRE_GetIOMessageLoop()->PostTask(
FROM_HERE, new SocketIOShutdownTask<DroidSocketImpl>(mImpl));
XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mImpl));
mImpl = nullptr;

View File

@ -44,10 +44,10 @@ public:
//
bool IsShutdownOnMainThread() const override;
void ShutdownOnMainThread();
void ShutdownOnMainThread() override;
bool IsShutdownOnIOThread() const;
void ShutdownOnIOThread();
bool IsShutdownOnIOThread() const override;
void ShutdownOnIOThread() override;
// Delayed-task handling
//
@ -756,8 +756,7 @@ BluetoothSocket::CloseSocket()
// will create a new implementation.
mIO->ShutdownOnMainThread();
XRE_GetIOMessageLoop()->PostTask(
FROM_HERE, new SocketIOShutdownTask<BluetoothSocketIO>(mIO));
XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
mIO = nullptr;

View File

@ -561,8 +561,7 @@ BluetoothDaemonConnection::CloseSocket()
return;
}
XRE_GetIOMessageLoop()->PostTask(
FROM_HERE, new SocketIOShutdownTask<BluetoothDaemonConnectionIO>(mIO));
XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
mIO = nullptr;

View File

@ -39,10 +39,10 @@ public:
//
bool IsShutdownOnMainThread() const override;
void ShutdownOnMainThread();
void ShutdownOnMainThread() override;
bool IsShutdownOnIOThread() const;
void ShutdownOnIOThread();
bool IsShutdownOnIOThread() const override;
void ShutdownOnIOThread() override;
// Task callback methods
//
@ -374,8 +374,7 @@ ListenSocket::Close()
// will create a new implementation.
mIO->ShutdownOnMainThread();
XRE_GetIOMessageLoop()->PostTask(
FROM_HERE, new SocketIOShutdownTask<ListenSocketIO>(mIO));
XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
mIO = nullptr;

View File

@ -362,5 +362,31 @@ SocketIODeleteInstanceRunnable::Run()
return NS_OK;
}
//
// SocketIOShutdownTask
//
SocketIOShutdownTask::SocketIOShutdownTask(SocketIOBase* aIO)
: SocketIOTask<SocketIOBase>(aIO)
{ }
void
SocketIOShutdownTask::Run()
{
MOZ_ASSERT(!NS_IsMainThread());
SocketIOBase* io = SocketIOTask<SocketIOBase>::GetIO();
// 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,
// which ShutdownOnIOThread will cancel for us. We are now fully
// shut down, so we can send a message to the main thread to delete
// |io| safely knowing that it's not reference any longer.
MOZ_ASSERT(!io->IsShutdownOnIOThread());
io->ShutdownOnIOThread();
NS_DispatchToMainThread(new SocketIODeleteInstanceRunnable(io));
}
}
}

View File

@ -331,6 +331,14 @@ public:
*/
virtual SocketBase* GetSocketBase() = 0;
/**
* Implemented by socket I/O classes to signal that the socket I/O class has
* been shut down.
*
* @return True if the socket I/O class has been shut down, false otherwise.
*/
virtual bool IsShutdownOnIOThread() const = 0;
/**
* Implemented by socket I/O classes to signal that socket class has
* been shut down.
@ -339,6 +347,17 @@ public:
*/
virtual bool IsShutdownOnMainThread() const = 0;
/**
* Signals to the socket I/O classes that it has been shut down.
*/
virtual void ShutdownOnIOThread() = 0;
/**
* Signals to the socket I/O classes that the socket class has been
* shut down.
*/
virtual void ShutdownOnMainThread() = 0;
protected:
SocketIOBase();
};
@ -452,7 +471,7 @@ public:
protected:
SocketIOTask(Tio* aIO)
: mIO(aIO)
: mIO(aIO)
{
MOZ_ASSERT(mIO);
}
@ -461,32 +480,16 @@ private:
Tio* mIO;
};
/* |SocketIOShutdownTask| signals shutdown to the Socket I/O object on
/**
* |SocketIOShutdownTask| signals shutdown to the socket I/O class on
* the I/O thread and sends it to the main thread for destruction.
*/
template<typename Tio>
class SocketIOShutdownTask final : public SocketIOTask<Tio>
class SocketIOShutdownTask final : public SocketIOTask<SocketIOBase>
{
public:
SocketIOShutdownTask(Tio* aIO)
: SocketIOTask<Tio>(aIO)
{ }
SocketIOShutdownTask(SocketIOBase* aIO);
void Run() override
{
MOZ_ASSERT(!NS_IsMainThread());
Tio* io = SocketIOTask<Tio>::GetIO();
// 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,
// which ShutdownOnIOThread will cancel for us. We are now fully
// shut down, so we can send a message to the main thread to delete
// |io| safely knowing that it's not reference any longer.
io->ShutdownOnIOThread();
NS_DispatchToMainThread(new SocketIODeleteInstanceRunnable(io));
}
void Run() override;
};
}

View File

@ -56,10 +56,10 @@ public:
//
bool IsShutdownOnMainThread() const override;
void ShutdownOnMainThread();
void ShutdownOnMainThread() override;
bool IsShutdownOnIOThread() const;
void ShutdownOnIOThread();
bool IsShutdownOnIOThread() const override;
void ShutdownOnIOThread() override;
// Delayed-task handling
//
@ -669,8 +669,7 @@ StreamSocket::Close()
// will create a new implementation.
mIO->ShutdownOnMainThread();
XRE_GetIOMessageLoop()->PostTask(
FROM_HERE, new SocketIOShutdownTask<StreamSocketIO>(mIO));
XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
mIO = nullptr;