mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-29 20:07:30 +09:00
[network] Make CacheIOThread::ThreadFunc hold reference to thread.
This commit is contained in:
parent
43f7d3e27a
commit
6b11c3f299
1 changed files with 13 additions and 1 deletions
|
|
@ -215,6 +215,11 @@ nsresult CacheIOThread::Init()
|
||||||
mBlockingIOWatcher = MakeUnique<detail::BlockingIOWatcher>();
|
mBlockingIOWatcher = MakeUnique<detail::BlockingIOWatcher>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Increase the reference count while spawning a new thread.
|
||||||
|
// If PR_CreateThread succeeds, we will forget this reference and the thread
|
||||||
|
// will be responsible to release it when it completes.
|
||||||
|
RefPtr<CacheIOThread> self = this;
|
||||||
|
|
||||||
mThread = PR_CreateThread(PR_USER_THREAD, ThreadFunc, this,
|
mThread = PR_CreateThread(PR_USER_THREAD, ThreadFunc, this,
|
||||||
PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
|
PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
|
||||||
PR_JOINABLE_THREAD, 128 * 1024);
|
PR_JOINABLE_THREAD, 128 * 1024);
|
||||||
|
|
@ -222,6 +227,11 @@ nsresult CacheIOThread::Init()
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IMPORTANT: The thread now owns this reference, so it's important that we
|
||||||
|
// leak it here, otherwise we'll end up with a bad refcount.
|
||||||
|
// See the dont_AddRef in ThreadFunc().
|
||||||
|
Unused << self.forget().take();
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -382,7 +392,9 @@ void CacheIOThread::ThreadFunc(void* aClosure)
|
||||||
{
|
{
|
||||||
PR_SetCurrentThreadName("Cache2 I/O");
|
PR_SetCurrentThreadName("Cache2 I/O");
|
||||||
mozilla::IOInterposer::RegisterCurrentThread();
|
mozilla::IOInterposer::RegisterCurrentThread();
|
||||||
CacheIOThread* thread = static_cast<CacheIOThread*>(aClosure);
|
// We hold on to this reference for the duration of the thread.
|
||||||
|
RefPtr<CacheIOThread> thread =
|
||||||
|
dont_AddRef(static_cast<CacheIOThread*>(aClosure));
|
||||||
thread->ThreadFunc();
|
thread->ThreadFunc();
|
||||||
mozilla::IOInterposer::UnregisterCurrentThread();
|
mozilla::IOInterposer::UnregisterCurrentThread();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue