2014-06-30 08:39:45 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsThreadUtils.h"
|
2012-06-12 20:08:53 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-10-26 06:32:10 -07:00
|
|
|
#include "mozilla/Likely.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef MOZILLA_INTERNAL_API
|
|
|
|
# include "nsThreadManager.h"
|
|
|
|
#else
|
|
|
|
# include "nsXPCOMCIDInternal.h"
|
|
|
|
# include "nsIThreadManager.h"
|
|
|
|
# include "nsServiceManagerUtils.h"
|
|
|
|
#endif
|
|
|
|
|
2009-11-09 11:30:01 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include <windows.h>
|
2013-10-18 11:14:31 -07:00
|
|
|
#include "mozilla/WindowsVersion.h"
|
|
|
|
using mozilla::IsVistaOrLater;
|
2012-07-25 07:25:08 -07:00
|
|
|
#elif defined(XP_MACOSX)
|
|
|
|
#include <sys/resource.h>
|
2009-11-09 11:30:01 -08:00
|
|
|
#endif
|
|
|
|
|
2012-06-12 10:06:20 -07:00
|
|
|
#include <pratom.h>
|
|
|
|
#include <prthread.h>
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifndef XPCOM_GLUE_AVOID_NSPR
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsRunnable, nsIRunnable)
|
2012-12-11 10:13:29 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsRunnable::Run()
|
|
|
|
{
|
|
|
|
// Do nothing
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsCancelableRunnable, nsICancelableRunnable,
|
|
|
|
nsIRunnable)
|
2012-12-11 10:13:29 -08:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCancelableRunnable::Run()
|
|
|
|
{
|
|
|
|
// Do nothing
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCancelableRunnable::Cancel()
|
|
|
|
{
|
|
|
|
// Do nothing
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif // XPCOM_GLUE_AVOID_NSPR
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_METHOD
|
2014-06-26 18:35:39 -07:00
|
|
|
NS_NewThread(nsIThread** aResult, nsIRunnable* aEvent, uint32_t aStackSize)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIThread> thread;
|
|
|
|
#ifdef MOZILLA_INTERNAL_API
|
2014-06-26 18:35:39 -07:00
|
|
|
nsresult rv =
|
|
|
|
nsThreadManager::get()->nsThreadManager::NewThread(0, aStackSize,
|
|
|
|
getter_AddRefs(thread));
|
2007-03-22 10:30:00 -07:00
|
|
|
#else
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIThreadManager> mgr =
|
2014-06-26 18:35:39 -07:00
|
|
|
do_GetService(NS_THREADMANAGER_CONTRACTID, &rv);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2013-11-19 13:27:37 -08:00
|
|
|
return rv;
|
2014-06-26 18:35:39 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-06-26 18:35:39 -07:00
|
|
|
rv = mgr->NewThread(0, aStackSize, getter_AddRefs(thread));
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2014-06-26 18:35:39 -07:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2013-11-19 13:27:37 -08:00
|
|
|
return rv;
|
2014-06-26 18:35:39 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-06-26 18:35:39 -07:00
|
|
|
if (aEvent) {
|
|
|
|
rv = thread->Dispatch(aEvent, NS_DISPATCH_NORMAL);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2013-11-19 13:27:37 -08:00
|
|
|
return rv;
|
2014-06-26 18:35:39 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-06-26 18:35:39 -07:00
|
|
|
*aResult = nullptr;
|
|
|
|
thread.swap(*aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
2014-06-26 18:35:39 -07:00
|
|
|
NS_GetCurrentThread(nsIThread** aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
#ifdef MOZILLA_INTERNAL_API
|
2014-06-26 18:35:39 -07:00
|
|
|
return nsThreadManager::get()->nsThreadManager::GetCurrentThread(aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
#else
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIThreadManager> mgr =
|
2014-06-26 18:35:39 -07:00
|
|
|
do_GetService(NS_THREADMANAGER_CONTRACTID, &rv);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2013-11-19 13:27:37 -08:00
|
|
|
return rv;
|
2014-06-26 18:35:39 -07:00
|
|
|
}
|
|
|
|
return mgr->GetCurrentThread(aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
2014-06-26 18:35:39 -07:00
|
|
|
NS_GetMainThread(nsIThread** aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
#ifdef MOZILLA_INTERNAL_API
|
2014-06-26 18:35:39 -07:00
|
|
|
return nsThreadManager::get()->nsThreadManager::GetMainThread(aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
#else
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIThreadManager> mgr =
|
2014-06-26 18:35:39 -07:00
|
|
|
do_GetService(NS_THREADMANAGER_CONTRACTID, &rv);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2013-11-19 13:27:37 -08:00
|
|
|
return rv;
|
2014-06-26 18:35:39 -07:00
|
|
|
}
|
|
|
|
return mgr->GetMainThread(aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-07-04 03:34:15 -07:00
|
|
|
#ifndef MOZILLA_INTERNAL_API
|
2014-06-26 18:35:39 -07:00
|
|
|
bool
|
|
|
|
NS_IsMainThread()
|
2013-10-17 06:24:30 -07:00
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
nsCOMPtr<nsIThreadManager> mgr =
|
|
|
|
do_GetService(NS_THREADMANAGER_CONTRACTID);
|
2014-06-26 18:35:39 -07:00
|
|
|
if (mgr) {
|
2013-10-17 06:24:30 -07:00
|
|
|
mgr->GetIsMainThread(&result);
|
2014-06-26 18:35:39 -07:00
|
|
|
}
|
2013-10-17 06:24:30 -07:00
|
|
|
return bool(result);
|
|
|
|
}
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-15 14:29:14 -07:00
|
|
|
// It is common to call NS_DispatchToCurrentThread with a newly
|
|
|
|
// allocated runnable with a refcount of zero. To keep us from leaking
|
|
|
|
// the runnable if the dispatch method fails, we take a death grip.
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_METHOD
|
2014-06-26 18:35:39 -07:00
|
|
|
NS_DispatchToCurrentThread(nsIRunnable* aEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-15 14:29:14 -07:00
|
|
|
nsCOMPtr<nsIRunnable> deathGrip = aEvent;
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef MOZILLA_INTERNAL_API
|
2014-06-26 18:35:39 -07:00
|
|
|
nsIThread* thread = NS_GetCurrentThread();
|
|
|
|
if (!thread) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
#else
|
|
|
|
nsCOMPtr<nsIThread> thread;
|
|
|
|
nsresult rv = NS_GetCurrentThread(getter_AddRefs(thread));
|
2014-06-26 18:35:39 -07:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2013-11-19 13:27:37 -08:00
|
|
|
return rv;
|
2014-06-26 18:35:39 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2014-06-26 18:35:39 -07:00
|
|
|
return thread->Dispatch(aEvent, NS_DISPATCH_NORMAL);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-07-15 14:29:14 -07:00
|
|
|
// In the case of failure with a newly allocated runnable with a
|
|
|
|
// refcount of zero, we intentionally leak the runnable, because it is
|
|
|
|
// likely that the runnable is being dispatched to the main thread
|
|
|
|
// because it owns main thread only objects, so it is not safe to
|
|
|
|
// release them here.
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_METHOD
|
2014-06-26 18:35:39 -07:00
|
|
|
NS_DispatchToMainThread(nsIRunnable* aEvent, uint32_t aDispatchFlags)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIThread> thread;
|
|
|
|
nsresult rv = NS_GetMainThread(getter_AddRefs(thread));
|
2014-06-26 18:35:39 -07:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2013-11-19 13:27:37 -08:00
|
|
|
return rv;
|
2014-06-26 18:35:39 -07:00
|
|
|
}
|
|
|
|
return thread->Dispatch(aEvent, aDispatchFlags);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-04-02 08:29:41 -07:00
|
|
|
#ifndef XPCOM_GLUE_AVOID_NSPR
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_METHOD
|
2014-06-26 18:35:39 -07:00
|
|
|
NS_ProcessPendingEvents(nsIThread* aThread, PRIntervalTime aTimeout)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
#ifdef MOZILLA_INTERNAL_API
|
2014-06-26 18:35:39 -07:00
|
|
|
if (!aThread) {
|
|
|
|
aThread = NS_GetCurrentThread();
|
|
|
|
if (NS_WARN_IF(!aThread)) {
|
2013-11-19 13:27:37 -08:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
2014-06-26 18:35:39 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
nsCOMPtr<nsIThread> current;
|
2014-06-26 18:35:39 -07:00
|
|
|
if (!aThread) {
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = NS_GetCurrentThread(getter_AddRefs(current));
|
2014-06-26 18:35:39 -07:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2013-11-19 13:27:37 -08:00
|
|
|
return rv;
|
2014-06-26 18:35:39 -07:00
|
|
|
}
|
|
|
|
aThread = current.get();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
PRIntervalTime start = PR_IntervalNow();
|
|
|
|
for (;;) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool processedEvent;
|
2014-06-26 18:35:39 -07:00
|
|
|
rv = aThread->ProcessNextEvent(false, &processedEvent);
|
|
|
|
if (NS_FAILED(rv) || !processedEvent) {
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2014-06-26 18:35:39 -07:00
|
|
|
}
|
|
|
|
if (PR_IntervalNow() - start > aTimeout) {
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2014-06-26 18:35:39 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
2007-04-02 08:29:41 -07:00
|
|
|
#endif // XPCOM_GLUE_AVOID_NSPR
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
inline bool
|
2014-06-26 18:35:39 -07:00
|
|
|
hasPendingEvents(nsIThread* aThread)
|
2009-01-04 10:59:17 -08:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool val;
|
2014-06-26 18:35:39 -07:00
|
|
|
return NS_SUCCEEDED(aThread->HasPendingEvents(&val)) && val;
|
2009-01-04 10:59:17 -08:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2014-06-26 18:35:39 -07:00
|
|
|
NS_HasPendingEvents(nsIThread* aThread)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-06-26 18:35:39 -07:00
|
|
|
if (!aThread) {
|
2009-01-04 10:59:17 -08:00
|
|
|
#ifndef MOZILLA_INTERNAL_API
|
|
|
|
nsCOMPtr<nsIThread> current;
|
|
|
|
NS_GetCurrentThread(getter_AddRefs(current));
|
|
|
|
return hasPendingEvents(current);
|
|
|
|
#else
|
2014-06-26 18:35:39 -07:00
|
|
|
aThread = NS_GetCurrentThread();
|
|
|
|
if (NS_WARN_IF(!aThread)) {
|
2013-11-19 13:27:37 -08:00
|
|
|
return false;
|
2014-06-26 18:35:39 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2009-01-04 10:59:17 -08:00
|
|
|
}
|
2014-06-26 18:35:39 -07:00
|
|
|
return hasPendingEvents(aThread);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2014-06-26 18:35:39 -07:00
|
|
|
NS_ProcessNextEvent(nsIThread* aThread, bool aMayWait)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
#ifdef MOZILLA_INTERNAL_API
|
2014-06-26 18:35:39 -07:00
|
|
|
if (!aThread) {
|
|
|
|
aThread = NS_GetCurrentThread();
|
|
|
|
if (NS_WARN_IF(!aThread)) {
|
2013-11-19 13:27:37 -08:00
|
|
|
return false;
|
2014-06-26 18:35:39 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
nsCOMPtr<nsIThread> current;
|
2014-06-26 18:35:39 -07:00
|
|
|
if (!aThread) {
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_GetCurrentThread(getter_AddRefs(current));
|
2014-06-26 18:35:39 -07:00
|
|
|
if (NS_WARN_IF(!current)) {
|
2013-11-19 13:27:37 -08:00
|
|
|
return false;
|
2014-06-26 18:35:39 -07:00
|
|
|
}
|
|
|
|
aThread = current.get();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
2011-09-28 23:19:26 -07:00
|
|
|
bool val;
|
2014-06-26 18:35:39 -07:00
|
|
|
return NS_SUCCEEDED(aThread->ProcessNextEvent(aMayWait, &val)) && val;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-06-12 10:06:20 -07:00
|
|
|
#ifndef XPCOM_GLUE_AVOID_NSPR
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2012-06-12 20:08:53 -07:00
|
|
|
class nsNameThreadRunnable MOZ_FINAL : public nsIRunnable
|
2012-06-12 10:06:20 -07:00
|
|
|
{
|
2014-06-30 15:11:53 -07:00
|
|
|
~nsNameThreadRunnable() {}
|
|
|
|
|
2012-06-12 10:06:20 -07:00
|
|
|
public:
|
2014-07-29 17:43:56 -07:00
|
|
|
explicit nsNameThreadRunnable(const nsACString& aName) : mName(aName) {}
|
2012-06-12 10:06:20 -07:00
|
|
|
|
2013-07-18 19:31:26 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2012-06-12 10:06:20 -07:00
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const nsCString mName;
|
|
|
|
};
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsNameThreadRunnable, nsIRunnable)
|
2012-06-12 10:06:20 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNameThreadRunnable::Run()
|
|
|
|
{
|
|
|
|
PR_SetCurrentThreadName(mName.BeginReading());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
void
|
2014-06-26 18:35:39 -07:00
|
|
|
NS_SetThreadName(nsIThread* aThread, const nsACString& aName)
|
2012-06-12 10:06:20 -07:00
|
|
|
{
|
2014-06-26 18:35:39 -07:00
|
|
|
if (!aThread) {
|
2012-06-12 10:06:20 -07:00
|
|
|
return;
|
2014-06-26 18:35:39 -07:00
|
|
|
}
|
2012-06-12 10:06:20 -07:00
|
|
|
|
2014-06-26 18:35:39 -07:00
|
|
|
aThread->Dispatch(new nsNameThreadRunnable(aName),
|
|
|
|
nsIEventTarget::DISPATCH_NORMAL);
|
2012-06-12 10:06:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#else // !XPCOM_GLUE_AVOID_NSPR
|
|
|
|
|
|
|
|
void
|
2014-06-26 18:35:39 -07:00
|
|
|
NS_SetThreadName(nsIThread* aThread, const nsACString& aName)
|
2012-06-12 10:06:20 -07:00
|
|
|
{
|
|
|
|
// No NSPR, no love.
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef MOZILLA_INTERNAL_API
|
2014-06-26 18:35:39 -07:00
|
|
|
nsIThread*
|
|
|
|
NS_GetCurrentThread()
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
return nsThreadManager::get()->GetCurrentThread();
|
|
|
|
}
|
|
|
|
#endif
|
2012-06-12 10:06:20 -07:00
|
|
|
|
|
|
|
// nsThreadPoolNaming
|
|
|
|
void
|
2014-06-26 18:35:39 -07:00
|
|
|
nsThreadPoolNaming::SetThreadPoolName(const nsACString& aPoolName,
|
|
|
|
nsIThread* aThread)
|
2012-06-12 10:06:20 -07:00
|
|
|
{
|
|
|
|
nsCString name(aPoolName);
|
2014-05-21 20:48:50 -07:00
|
|
|
name.AppendLiteral(" #");
|
2012-06-12 10:06:20 -07:00
|
|
|
name.AppendInt(++mCounter, 10); // The counter is declared as volatile
|
|
|
|
|
|
|
|
if (aThread) {
|
|
|
|
// Set on the target thread
|
|
|
|
NS_SetThreadName(aThread, name);
|
2014-06-26 18:35:39 -07:00
|
|
|
} else {
|
2012-06-12 10:06:20 -07:00
|
|
|
// Set on the current thread
|
2014-07-04 03:33:56 -07:00
|
|
|
#ifndef XPCOM_GLUE_AVOID_NSPR
|
2012-06-12 10:06:20 -07:00
|
|
|
PR_SetCurrentThreadName(name.BeginReading());
|
2014-07-04 03:33:56 -07:00
|
|
|
#endif
|
2012-06-12 10:06:20 -07:00
|
|
|
}
|
|
|
|
}
|
2012-07-25 07:25:08 -07:00
|
|
|
|
|
|
|
// nsAutoLowPriorityIO
|
|
|
|
nsAutoLowPriorityIO::nsAutoLowPriorityIO()
|
|
|
|
{
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
lowIOPrioritySet = IsVistaOrLater() &&
|
|
|
|
SetThreadPriority(GetCurrentThread(),
|
|
|
|
THREAD_MODE_BACKGROUND_BEGIN);
|
|
|
|
#elif defined(XP_MACOSX)
|
|
|
|
oldPriority = getiopolicy_np(IOPOL_TYPE_DISK, IOPOL_SCOPE_THREAD);
|
|
|
|
lowIOPrioritySet = oldPriority != -1 &&
|
|
|
|
setiopolicy_np(IOPOL_TYPE_DISK,
|
|
|
|
IOPOL_SCOPE_THREAD,
|
|
|
|
IOPOL_THROTTLE) != -1;
|
|
|
|
#else
|
|
|
|
lowIOPrioritySet = false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoLowPriorityIO::~nsAutoLowPriorityIO()
|
|
|
|
{
|
|
|
|
#if defined(XP_WIN)
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_LIKELY(lowIOPrioritySet)) {
|
2012-07-25 07:25:08 -07:00
|
|
|
// On Windows the old thread priority is automatically restored
|
|
|
|
SetThreadPriority(GetCurrentThread(), THREAD_MODE_BACKGROUND_END);
|
|
|
|
}
|
|
|
|
#elif defined(XP_MACOSX)
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_LIKELY(lowIOPrioritySet)) {
|
2012-07-25 07:25:08 -07:00
|
|
|
setiopolicy_np(IOPOL_TYPE_DISK, IOPOL_SCOPE_THREAD, oldPriority);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|