Bug 1229235 - Make RedirectChannelRegistrar thread-safe. r=jduell

This commit is contained in:
Honza Bambas 2015-12-04 09:55:00 +01:00
parent 86899e610d
commit 5a7f903046
2 changed files with 12 additions and 0 deletions

View File

@ -13,6 +13,7 @@ RedirectChannelRegistrar::RedirectChannelRegistrar()
: mRealChannels(32)
, mParentChannels(32)
, mId(1)
, mLock("RedirectChannelRegistrar")
{
}
@ -20,6 +21,8 @@ NS_IMETHODIMP
RedirectChannelRegistrar::RegisterChannel(nsIChannel *channel,
uint32_t *_retval)
{
MutexAutoLock lock(mLock);
mRealChannels.Put(mId, channel);
*_retval = mId;
@ -36,6 +39,8 @@ NS_IMETHODIMP
RedirectChannelRegistrar::GetRegisteredChannel(uint32_t id,
nsIChannel **_retval)
{
MutexAutoLock lock(mLock);
if (!mRealChannels.Get(id, _retval))
return NS_ERROR_NOT_AVAILABLE;
@ -47,6 +52,8 @@ RedirectChannelRegistrar::LinkChannels(uint32_t id,
nsIParentChannel *channel,
nsIChannel** _retval)
{
MutexAutoLock lock(mLock);
if (!mRealChannels.Get(id, _retval))
return NS_ERROR_NOT_AVAILABLE;
@ -58,6 +65,8 @@ NS_IMETHODIMP
RedirectChannelRegistrar::GetParentChannel(uint32_t id,
nsIParentChannel **_retval)
{
MutexAutoLock lock(mLock);
if (!mParentChannels.Get(id, _retval))
return NS_ERROR_NOT_AVAILABLE;
@ -67,6 +76,8 @@ RedirectChannelRegistrar::GetParentChannel(uint32_t id,
NS_IMETHODIMP
RedirectChannelRegistrar::DeregisterChannels(uint32_t id)
{
MutexAutoLock lock(mLock);
mRealChannels.Remove(id);
mParentChannels.Remove(id);
return NS_OK;

View File

@ -34,6 +34,7 @@ protected:
ChannelHashtable mRealChannels;
ParentChannelHashtable mParentChannels;
uint32_t mId;
Mutex mLock;
};
} // namespace net