Bug 1138620 - Part 1: Allow binary modules to create unmonitored threads that doesn't keep the Nuwa process from stabalization. r=nfroyd

This commit is contained in:
Cervantes Yu 2015-04-21 18:23:09 +08:00
Родитель e4ca3516dc
Коммит d827320379
2 изменённых файлов: 72 добавлений и 0 удалений

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

@ -93,6 +93,67 @@ NS_NewThread(nsIThread** aResult, nsIRunnable* aEvent, uint32_t aStackSize)
return NS_OK;
}
#if defined(MOZ_NUWA_PROCESS) && !defined(XPCOM_GLUE_AVOID_NSPR)
namespace {
class IgnoreThreadStatusRunnable : public nsIRunnable
{
public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIRUNNABLE
private:
virtual ~IgnoreThreadStatusRunnable() = default;
};
NS_IMPL_ISUPPORTS(IgnoreThreadStatusRunnable, nsIRunnable)
NS_IMETHODIMP IgnoreThreadStatusRunnable::Run(void)
{
#ifdef MOZILLA_INTERNAL_API
nsThreadManager::get()->SetIgnoreThreadStatus();
return NS_OK;
#endif
return NS_ERROR_NOT_IMPLEMENTED;
}
} // Anonymous namespace.
#endif // defined(MOZ_NUWA_PROCESS) && !defined(XPCOM_GLUE_AVOID_NSPR)
NS_METHOD
NS_NewUnmonitoredThread(nsIThread** aResult,
nsIRunnable* aEvent,
uint32_t aStackSize)
{
#if defined(MOZ_NUWA_PROCESS) && !defined(XPCOM_GLUE_AVOID_NSPR)
// Hold a ref while dispatching the initial event to match NS_NewThread()
nsCOMPtr<nsIThread> thread;
nsresult rv = NS_NewThread(getter_AddRefs(thread), nullptr, aStackSize);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
nsCOMPtr<nsIRunnable> ignoreme = new IgnoreThreadStatusRunnable();
rv = thread->Dispatch(ignoreme, NS_DISPATCH_NORMAL);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if (aEvent) {
rv = thread->Dispatch(aEvent, NS_DISPATCH_NORMAL);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
*aResult = nullptr;
thread.swap(*aResult);
return rv;
#else
return NS_NewThread(aResult, aEvent, aStackSize);
#endif
}
NS_METHOD
NS_GetCurrentThread(nsIThread** aResult)
{

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

@ -61,6 +61,17 @@ NS_NewThread(nsIThread** aResult,
nsIRunnable* aInitialEvent = nullptr,
uint32_t aStackSize = nsIThreadManager::DEFAULT_STACK_SIZE);
/**
* Create a new thread that is ignored in thread status monitoring by default on
* platforms with Nuwa process enabled. On non-Nuwa platforms, this function is
* identical to NS_NewThread().
*/
extern NS_METHOD
NS_NewUnmonitoredThread(nsIThread** aResult,
nsIRunnable* aInitialEvent = nullptr,
uint32_t aStackSize =
nsIThreadManager::DEFAULT_STACK_SIZE);
/**
* Creates a named thread, otherwise the same as NS_NewThread
*/