2014-06-30 19:39:45 +04: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 15:12:37 +04: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/. */
|
2006-05-10 21:30:15 +04:00
|
|
|
|
|
|
|
#include "nsThreadUtils.h"
|
2012-06-13 07:08:53 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-10-26 17:32:10 +04:00
|
|
|
#include "mozilla/Likely.h"
|
2006-05-10 21:30:15 +04:00
|
|
|
|
|
|
|
#ifdef MOZILLA_INTERNAL_API
|
|
|
|
# include "nsThreadManager.h"
|
|
|
|
#else
|
|
|
|
# include "nsXPCOMCIDInternal.h"
|
|
|
|
# include "nsIThreadManager.h"
|
|
|
|
# include "nsServiceManagerUtils.h"
|
|
|
|
#endif
|
|
|
|
|
2009-11-09 22:30:01 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include <windows.h>
|
2013-10-18 22:14:31 +04:00
|
|
|
#include "mozilla/WindowsVersion.h"
|
|
|
|
using mozilla::IsVistaOrLater;
|
2012-07-25 18:25:08 +04:00
|
|
|
#elif defined(XP_MACOSX)
|
|
|
|
#include <sys/resource.h>
|
2009-11-09 22:30:01 +03:00
|
|
|
#endif
|
|
|
|
|
2012-06-12 21:06:20 +04:00
|
|
|
#include <pratom.h>
|
|
|
|
#include <prthread.h>
|
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
#ifndef XPCOM_GLUE_AVOID_NSPR
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsRunnable, nsIRunnable)
|
2012-12-11 22:13:29 +04:00
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsRunnable::Run()
|
|
|
|
{
|
|
|
|
// Do nothing
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsCancelableRunnable, nsICancelableRunnable,
|
|
|
|
nsIRunnable)
|
2012-12-11 22:13:29 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCancelableRunnable::Run()
|
|
|
|
{
|
|
|
|
// Do nothing
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCancelableRunnable::Cancel()
|
|
|
|
{
|
|
|
|
// Do nothing
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
#endif // XPCOM_GLUE_AVOID_NSPR
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_METHOD
|
2014-06-27 05:35:39 +04:00
|
|
|
NS_NewThread(nsIThread** aResult, nsIRunnable* aEvent, uint32_t aStackSize)
|
2006-05-10 21:30:15 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIThread> thread;
|
|
|
|
#ifdef MOZILLA_INTERNAL_API
|
2014-06-27 05:35:39 +04:00
|
|
|
nsresult rv =
|
|
|
|
nsThreadManager::get()->nsThreadManager::NewThread(0, aStackSize,
|
|
|
|
getter_AddRefs(thread));
|
2006-05-10 21:30:15 +04:00
|
|
|
#else
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIThreadManager> mgr =
|
2014-06-27 05:35:39 +04:00
|
|
|
do_GetService(NS_THREADMANAGER_CONTRACTID, &rv);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2013-11-20 01:27:37 +04:00
|
|
|
return rv;
|
2014-06-27 05:35:39 +04:00
|
|
|
}
|
2006-05-10 21:30:15 +04:00
|
|
|
|
2014-06-27 05:35:39 +04:00
|
|
|
rv = mgr->NewThread(0, aStackSize, getter_AddRefs(thread));
|
2006-05-10 21:30:15 +04:00
|
|
|
#endif
|
2014-06-27 05:35:39 +04:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2013-11-20 01:27:37 +04:00
|
|
|
return rv;
|
2014-06-27 05:35:39 +04:00
|
|
|
}
|
2006-05-10 21:30:15 +04:00
|
|
|
|
2014-06-27 05:35:39 +04:00
|
|
|
if (aEvent) {
|
|
|
|
rv = thread->Dispatch(aEvent, NS_DISPATCH_NORMAL);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2013-11-20 01:27:37 +04:00
|
|
|
return rv;
|
2014-06-27 05:35:39 +04:00
|
|
|
}
|
2006-05-10 21:30:15 +04:00
|
|
|
}
|
|
|
|
|
2014-06-27 05:35:39 +04:00
|
|
|
*aResult = nullptr;
|
|
|
|
thread.swap(*aResult);
|
2006-05-10 21:30:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
2014-06-27 05:35:39 +04:00
|
|
|
NS_GetCurrentThread(nsIThread** aResult)
|
2006-05-10 21:30:15 +04:00
|
|
|
{
|
|
|
|
#ifdef MOZILLA_INTERNAL_API
|
2014-06-27 05:35:39 +04:00
|
|
|
return nsThreadManager::get()->nsThreadManager::GetCurrentThread(aResult);
|
2006-05-10 21:30:15 +04:00
|
|
|
#else
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIThreadManager> mgr =
|
2014-06-27 05:35:39 +04:00
|
|
|
do_GetService(NS_THREADMANAGER_CONTRACTID, &rv);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2013-11-20 01:27:37 +04:00
|
|
|
return rv;
|
2014-06-27 05:35:39 +04:00
|
|
|
}
|
|
|
|
return mgr->GetCurrentThread(aResult);
|
2006-05-10 21:30:15 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
2014-06-27 05:35:39 +04:00
|
|
|
NS_GetMainThread(nsIThread** aResult)
|
2006-05-10 21:30:15 +04:00
|
|
|
{
|
|
|
|
#ifdef MOZILLA_INTERNAL_API
|
2014-06-27 05:35:39 +04:00
|
|
|
return nsThreadManager::get()->nsThreadManager::GetMainThread(aResult);
|
2006-05-10 21:30:15 +04:00
|
|
|
#else
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIThreadManager> mgr =
|
2014-06-27 05:35:39 +04:00
|
|
|
do_GetService(NS_THREADMANAGER_CONTRACTID, &rv);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2013-11-20 01:27:37 +04:00
|
|
|
return rv;
|
2014-06-27 05:35:39 +04:00
|
|
|
}
|
|
|
|
return mgr->GetMainThread(aResult);
|
2006-05-10 21:30:15 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-07-04 14:34:15 +04:00
|
|
|
#ifndef MOZILLA_INTERNAL_API
|
2014-06-27 05:35:39 +04:00
|
|
|
bool
|
|
|
|
NS_IsMainThread()
|
2013-10-17 17:24:30 +04:00
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
nsCOMPtr<nsIThreadManager> mgr =
|
|
|
|
do_GetService(NS_THREADMANAGER_CONTRACTID);
|
2014-06-27 05:35:39 +04:00
|
|
|
if (mgr) {
|
2013-10-17 17:24:30 +04:00
|
|
|
mgr->GetIsMainThread(&result);
|
2014-06-27 05:35:39 +04:00
|
|
|
}
|
2013-10-17 17:24:30 +04:00
|
|
|
return bool(result);
|
|
|
|
}
|
|
|
|
#endif
|
2006-05-10 21:30:15 +04:00
|
|
|
|
2014-07-16 01:29:14 +04: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.
|
2006-05-10 21:30:15 +04:00
|
|
|
NS_METHOD
|
2014-06-27 05:35:39 +04:00
|
|
|
NS_DispatchToCurrentThread(nsIRunnable* aEvent)
|
2006-05-10 21:30:15 +04:00
|
|
|
{
|
2014-07-16 01:29:14 +04:00
|
|
|
nsCOMPtr<nsIRunnable> deathGrip = aEvent;
|
2006-05-10 21:30:15 +04:00
|
|
|
#ifdef MOZILLA_INTERNAL_API
|
2014-06-27 05:35:39 +04:00
|
|
|
nsIThread* thread = NS_GetCurrentThread();
|
|
|
|
if (!thread) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2006-05-10 21:30:15 +04:00
|
|
|
#else
|
|
|
|
nsCOMPtr<nsIThread> thread;
|
|
|
|
nsresult rv = NS_GetCurrentThread(getter_AddRefs(thread));
|
2014-06-27 05:35:39 +04:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2013-11-20 01:27:37 +04:00
|
|
|
return rv;
|
2014-06-27 05:35:39 +04:00
|
|
|
}
|
2006-05-10 21:30:15 +04:00
|
|
|
#endif
|
2014-06-27 05:35:39 +04:00
|
|
|
return thread->Dispatch(aEvent, NS_DISPATCH_NORMAL);
|
2006-05-10 21:30:15 +04:00
|
|
|
}
|
|
|
|
|
2014-07-16 01:29:14 +04: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.
|
2006-05-10 21:30:15 +04:00
|
|
|
NS_METHOD
|
2014-06-27 05:35:39 +04:00
|
|
|
NS_DispatchToMainThread(nsIRunnable* aEvent, uint32_t aDispatchFlags)
|
2006-05-10 21:30:15 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIThread> thread;
|
|
|
|
nsresult rv = NS_GetMainThread(getter_AddRefs(thread));
|
2014-06-27 05:35:39 +04:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2013-11-20 01:27:37 +04:00
|
|
|
return rv;
|
2014-06-27 05:35:39 +04:00
|
|
|
}
|
|
|
|
return thread->Dispatch(aEvent, aDispatchFlags);
|
2006-05-10 21:30:15 +04:00
|
|
|
}
|
|
|
|
|
2007-04-02 19:29:41 +04:00
|
|
|
#ifndef XPCOM_GLUE_AVOID_NSPR
|
2006-05-10 21:30:15 +04:00
|
|
|
NS_METHOD
|
2014-06-27 05:35:39 +04:00
|
|
|
NS_ProcessPendingEvents(nsIThread* aThread, PRIntervalTime aTimeout)
|
2006-05-10 21:30:15 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
#ifdef MOZILLA_INTERNAL_API
|
2014-06-27 05:35:39 +04:00
|
|
|
if (!aThread) {
|
|
|
|
aThread = NS_GetCurrentThread();
|
|
|
|
if (NS_WARN_IF(!aThread)) {
|
2013-11-20 01:27:37 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
2014-06-27 05:35:39 +04:00
|
|
|
}
|
2006-05-10 21:30:15 +04:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
nsCOMPtr<nsIThread> current;
|
2014-06-27 05:35:39 +04:00
|
|
|
if (!aThread) {
|
2006-05-10 21:30:15 +04:00
|
|
|
rv = NS_GetCurrentThread(getter_AddRefs(current));
|
2014-06-27 05:35:39 +04:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2013-11-20 01:27:37 +04:00
|
|
|
return rv;
|
2014-06-27 05:35:39 +04:00
|
|
|
}
|
|
|
|
aThread = current.get();
|
2006-05-10 21:30:15 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
PRIntervalTime start = PR_IntervalNow();
|
|
|
|
for (;;) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool processedEvent;
|
2014-06-27 05:35:39 +04:00
|
|
|
rv = aThread->ProcessNextEvent(false, &processedEvent);
|
|
|
|
if (NS_FAILED(rv) || !processedEvent) {
|
2006-05-10 21:30:15 +04:00
|
|
|
break;
|
2014-06-27 05:35:39 +04:00
|
|
|
}
|
|
|
|
if (PR_IntervalNow() - start > aTimeout) {
|
2006-05-10 21:30:15 +04:00
|
|
|
break;
|
2014-06-27 05:35:39 +04:00
|
|
|
}
|
2006-05-10 21:30:15 +04:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
2007-04-02 19:29:41 +04:00
|
|
|
#endif // XPCOM_GLUE_AVOID_NSPR
|
2006-05-10 21:30:15 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
inline bool
|
2014-06-27 05:35:39 +04:00
|
|
|
hasPendingEvents(nsIThread* aThread)
|
2009-01-04 21:59:17 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool val;
|
2014-06-27 05:35:39 +04:00
|
|
|
return NS_SUCCEEDED(aThread->HasPendingEvents(&val)) && val;
|
2009-01-04 21:59:17 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2014-06-27 05:35:39 +04:00
|
|
|
NS_HasPendingEvents(nsIThread* aThread)
|
2006-05-10 21:30:15 +04:00
|
|
|
{
|
2014-06-27 05:35:39 +04:00
|
|
|
if (!aThread) {
|
2009-01-04 21:59:17 +03:00
|
|
|
#ifndef MOZILLA_INTERNAL_API
|
|
|
|
nsCOMPtr<nsIThread> current;
|
|
|
|
NS_GetCurrentThread(getter_AddRefs(current));
|
|
|
|
return hasPendingEvents(current);
|
|
|
|
#else
|
2014-06-27 05:35:39 +04:00
|
|
|
aThread = NS_GetCurrentThread();
|
|
|
|
if (NS_WARN_IF(!aThread)) {
|
2013-11-20 01:27:37 +04:00
|
|
|
return false;
|
2014-06-27 05:35:39 +04:00
|
|
|
}
|
2006-05-10 21:30:15 +04:00
|
|
|
#endif
|
2009-01-04 21:59:17 +03:00
|
|
|
}
|
2014-06-27 05:35:39 +04:00
|
|
|
return hasPendingEvents(aThread);
|
2006-05-10 21:30:15 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2014-06-27 05:35:39 +04:00
|
|
|
NS_ProcessNextEvent(nsIThread* aThread, bool aMayWait)
|
2006-05-10 21:30:15 +04:00
|
|
|
{
|
|
|
|
#ifdef MOZILLA_INTERNAL_API
|
2014-06-27 05:35:39 +04:00
|
|
|
if (!aThread) {
|
|
|
|
aThread = NS_GetCurrentThread();
|
|
|
|
if (NS_WARN_IF(!aThread)) {
|
2013-11-20 01:27:37 +04:00
|
|
|
return false;
|
2014-06-27 05:35:39 +04:00
|
|
|
}
|
2006-05-10 21:30:15 +04:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
nsCOMPtr<nsIThread> current;
|
2014-06-27 05:35:39 +04:00
|
|
|
if (!aThread) {
|
2006-05-10 21:30:15 +04:00
|
|
|
NS_GetCurrentThread(getter_AddRefs(current));
|
2014-06-27 05:35:39 +04:00
|
|
|
if (NS_WARN_IF(!current)) {
|
2013-11-20 01:27:37 +04:00
|
|
|
return false;
|
2014-06-27 05:35:39 +04:00
|
|
|
}
|
|
|
|
aThread = current.get();
|
2006-05-10 21:30:15 +04:00
|
|
|
}
|
|
|
|
#endif
|
2011-09-29 10:19:26 +04:00
|
|
|
bool val;
|
2014-06-27 05:35:39 +04:00
|
|
|
return NS_SUCCEEDED(aThread->ProcessNextEvent(aMayWait, &val)) && val;
|
2006-05-10 21:30:15 +04:00
|
|
|
}
|
|
|
|
|
2012-06-12 21:06:20 +04:00
|
|
|
#ifndef XPCOM_GLUE_AVOID_NSPR
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2012-06-13 07:08:53 +04:00
|
|
|
class nsNameThreadRunnable MOZ_FINAL : public nsIRunnable
|
2012-06-12 21:06:20 +04:00
|
|
|
{
|
2014-07-01 02:11:53 +04:00
|
|
|
~nsNameThreadRunnable() {}
|
|
|
|
|
2012-06-12 21:06:20 +04:00
|
|
|
public:
|
2014-07-30 04:43:56 +04:00
|
|
|
explicit nsNameThreadRunnable(const nsACString& aName) : mName(aName) {}
|
2012-06-12 21:06:20 +04:00
|
|
|
|
2013-07-19 06:31:26 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2012-06-12 21:06:20 +04:00
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const nsCString mName;
|
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsNameThreadRunnable, nsIRunnable)
|
2012-06-12 21:06:20 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNameThreadRunnable::Run()
|
|
|
|
{
|
|
|
|
PR_SetCurrentThreadName(mName.BeginReading());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
void
|
2014-06-27 05:35:39 +04:00
|
|
|
NS_SetThreadName(nsIThread* aThread, const nsACString& aName)
|
2012-06-12 21:06:20 +04:00
|
|
|
{
|
2014-06-27 05:35:39 +04:00
|
|
|
if (!aThread) {
|
2012-06-12 21:06:20 +04:00
|
|
|
return;
|
2014-06-27 05:35:39 +04:00
|
|
|
}
|
2012-06-12 21:06:20 +04:00
|
|
|
|
2014-06-27 05:35:39 +04:00
|
|
|
aThread->Dispatch(new nsNameThreadRunnable(aName),
|
|
|
|
nsIEventTarget::DISPATCH_NORMAL);
|
2012-06-12 21:06:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#else // !XPCOM_GLUE_AVOID_NSPR
|
|
|
|
|
|
|
|
void
|
2014-06-27 05:35:39 +04:00
|
|
|
NS_SetThreadName(nsIThread* aThread, const nsACString& aName)
|
2012-06-12 21:06:20 +04:00
|
|
|
{
|
|
|
|
// No NSPR, no love.
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
#ifdef MOZILLA_INTERNAL_API
|
2014-06-27 05:35:39 +04:00
|
|
|
nsIThread*
|
|
|
|
NS_GetCurrentThread()
|
|
|
|
{
|
2006-05-10 21:30:15 +04:00
|
|
|
return nsThreadManager::get()->GetCurrentThread();
|
|
|
|
}
|
|
|
|
#endif
|
2012-06-12 21:06:20 +04:00
|
|
|
|
|
|
|
// nsThreadPoolNaming
|
|
|
|
void
|
2014-06-27 05:35:39 +04:00
|
|
|
nsThreadPoolNaming::SetThreadPoolName(const nsACString& aPoolName,
|
|
|
|
nsIThread* aThread)
|
2012-06-12 21:06:20 +04:00
|
|
|
{
|
|
|
|
nsCString name(aPoolName);
|
2014-05-22 07:48:50 +04:00
|
|
|
name.AppendLiteral(" #");
|
2012-06-12 21:06:20 +04:00
|
|
|
name.AppendInt(++mCounter, 10); // The counter is declared as volatile
|
|
|
|
|
|
|
|
if (aThread) {
|
|
|
|
// Set on the target thread
|
|
|
|
NS_SetThreadName(aThread, name);
|
2014-06-27 05:35:39 +04:00
|
|
|
} else {
|
2012-06-12 21:06:20 +04:00
|
|
|
// Set on the current thread
|
2014-07-04 14:33:56 +04:00
|
|
|
#ifndef XPCOM_GLUE_AVOID_NSPR
|
2012-06-12 21:06:20 +04:00
|
|
|
PR_SetCurrentThreadName(name.BeginReading());
|
2014-07-04 14:33:56 +04:00
|
|
|
#endif
|
2012-06-12 21:06:20 +04:00
|
|
|
}
|
|
|
|
}
|
2012-07-25 18:25:08 +04: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 17:32:10 +04:00
|
|
|
if (MOZ_LIKELY(lowIOPrioritySet)) {
|
2012-07-25 18:25:08 +04:00
|
|
|
// On Windows the old thread priority is automatically restored
|
|
|
|
SetThreadPriority(GetCurrentThread(), THREAD_MODE_BACKGROUND_END);
|
|
|
|
}
|
|
|
|
#elif defined(XP_MACOSX)
|
2012-10-26 17:32:10 +04:00
|
|
|
if (MOZ_LIKELY(lowIOPrioritySet)) {
|
2012-07-25 18:25:08 +04:00
|
|
|
setiopolicy_np(IOPOL_TYPE_DISK, IOPOL_SCOPE_THREAD, oldPriority);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|