bug 905410 - remove most remaining usage of nspr atomics outside of xpcom/ r=ehsan

This commit is contained in:
Trevor Saunders 2013-08-12 05:51:49 -04:00
Родитель 63f6d15be9
Коммит acfc9e9cd6
18 изменённых файлов: 63 добавлений и 64 удалений

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

@ -24,7 +24,6 @@
#include "nsContentUtils.h"
#include "nsEventDispatcher.h"
#include "nsThreadUtils.h"
#include "pratom.h"
#include "IDBEvents.h"
#include "IDBFactory.h"
@ -46,8 +45,8 @@ namespace {
mozilla::StaticRefPtr<IndexedDatabaseManager> gInstance;
int32_t gInitialized = 0;
int32_t gClosed = 0;
mozilla::Atomic<int32_t> gInitialized(0);
mozilla::Atomic<int32_t> gClosed(0);
class AsyncDeleteFileRunnable MOZ_FINAL : public nsIRunnable
{
@ -141,7 +140,7 @@ IndexedDatabaseManager::~IndexedDatabaseManager()
}
bool IndexedDatabaseManager::sIsMainProcess = false;
int32_t IndexedDatabaseManager::sLowDiskSpaceMode = 0;
mozilla::Atomic<int32_t> IndexedDatabaseManager::sLowDiskSpaceMode(0);
// static
IndexedDatabaseManager*
@ -180,7 +179,7 @@ IndexedDatabaseManager::GetOrCreate()
nsresult rv = instance->Init();
NS_ENSURE_SUCCESS(rv, nullptr);
if (PR_ATOMIC_SET(&gInitialized, 1)) {
if (gInitialized.exchange(1)) {
NS_ERROR("Initialized more than once?!");
}
@ -244,7 +243,7 @@ IndexedDatabaseManager::Destroy()
{
// Setting the closed flag prevents the service from being recreated.
// Don't set it though if there's no real instance created.
if (!!gInitialized && PR_ATOMIC_SET(&gClosed, 1)) {
if (!!gInitialized && gClosed.exchange(1)) {
NS_ERROR("Shutdown more than once?!");
}
@ -589,10 +588,10 @@ IndexedDatabaseManager::Observe(nsISupports* aSubject, const char* aTopic,
const nsDependentString data(aData);
if (data.EqualsLiteral(LOW_DISK_SPACE_DATA_FULL)) {
PR_ATOMIC_SET(&sLowDiskSpaceMode, 1);
sLowDiskSpaceMode = 1;
}
else if (data.EqualsLiteral(LOW_DISK_SPACE_DATA_FREE)) {
PR_ATOMIC_SET(&sLowDiskSpaceMode, 0);
sLowDiskSpaceMode = 0;
}
else {
NS_NOTREACHED("Unknown data value!");

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

@ -12,6 +12,7 @@
#include "nsIIndexedDatabaseManager.h"
#include "nsIObserver.h"
#include "mozilla/Atomics.h"
#include "mozilla/Mutex.h"
#include "nsClassHashtable.h"
#include "nsHashKeys.h"
@ -146,7 +147,7 @@ private:
mozilla::Mutex mFileMutex;
static bool sIsMainProcess;
static int32_t sLowDiskSpaceMode;
static mozilla::Atomic<int32_t> sLowDiskSpaceMode;
};
END_INDEXEDDB_NAMESPACE

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

@ -23,6 +23,7 @@
#include <algorithm>
#include "GeckoProfiler.h"
#include "mozilla/Atomics.h"
#include "mozilla/dom/file/FileService.h"
#include "mozilla/dom/indexedDB/Client.h"
#include "mozilla/LazyIdleThread.h"
@ -36,7 +37,6 @@
#include "nsScriptSecurityManager.h"
#include "nsThreadUtils.h"
#include "nsXULAppAPI.h"
#include "pratom.h"
#include "xpcpublic.h"
#include "AcquireListener.h"
@ -260,7 +260,7 @@ END_QUOTA_NAMESPACE
namespace {
QuotaManager* gInstance = nullptr;
int32_t gShutdown = 0;
mozilla::Atomic<uint32_t> gShutdown(0);
int32_t gStorageQuotaMB = DEFAULT_QUOTA_MB;
@ -1200,7 +1200,7 @@ QuotaManager::Observe(nsISupports* aSubject,
if (!strcmp(aTopic, PROFILE_BEFORE_CHANGE_OBSERVER_ID)) {
// Setting this flag prevents the service from being recreated and prevents
// further storagess from being created.
if (PR_ATOMIC_SET(&gShutdown, 1)) {
if (gShutdown.exchange(1)) {
NS_ERROR("Shutdown more than once?!");
}
@ -2171,7 +2171,7 @@ AsyncUsageRunnable::Run()
NS_IMETHODIMP
AsyncUsageRunnable::Cancel()
{
if (PR_ATOMIC_SET(&mCanceled, 1)) {
if (mCanceled.exchange(1)) {
NS_WARNING("Canceled more than once?!");
return NS_ERROR_UNEXPECTED;
}

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

@ -9,6 +9,7 @@
#include "mozilla/dom/quota/QuotaCommon.h"
#include "mozilla/Atomics.h"
#include "Utilities.h"
BEGIN_QUOTA_NAMESPACE
@ -69,7 +70,7 @@ public:
}
protected:
int32_t mCanceled;
mozilla::Atomic<int32_t> mCanceled;
private:
uint64_t mDatabaseUsage;

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

@ -39,7 +39,7 @@ using mozilla::gfx::SourceSurface;
namespace mozilla {
namespace layers {
int32_t Image::sSerialCounter = 0;
Atomic<int32_t> Image::sSerialCounter(0);
already_AddRefed<Image>
ImageFactory::CreateImage(const ImageFormat *aFormats,

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

@ -6,6 +6,7 @@
#ifndef GFX_IMAGECONTAINER_H
#define GFX_IMAGECONTAINER_H
#include "mozilla/Atomics.h"
#include "mozilla/Mutex.h"
#include "mozilla/ReentrantMonitor.h"
#include "gfxASurface.h" // for gfxImageFormat
@ -13,7 +14,6 @@
#include "mozilla/TimeStamp.h"
#include "ImageTypes.h"
#include "nsTArray.h"
#include "pratom.h"
#ifdef XP_WIN
struct ID3D10Texture2D;
@ -103,7 +103,7 @@ public:
protected:
Image(void* aImplData, ImageFormat aFormat) :
mImplData(aImplData),
mSerial(PR_ATOMIC_INCREMENT(&sSerialCounter)),
mSerial(++sSerialCounter),
mFormat(aFormat),
mSent(false)
{}
@ -113,7 +113,7 @@ protected:
void* mImplData;
int32_t mSerial;
ImageFormat mFormat;
static int32_t sSerialCounter;
static mozilla::Atomic<int32_t> sSerialCounter;
bool mSent;
};

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

@ -8,7 +8,6 @@
#include "RasterImage.h"
#include "DiscardTracker.h"
#include "mozilla/Preferences.h"
#include "pratom.h"
namespace mozilla {
namespace image {
@ -19,7 +18,7 @@ static const char* sDiscardTimeoutPref = "image.mem.min_discard_timeout_ms";
/* static */ nsCOMPtr<nsITimer> DiscardTracker::sTimer;
/* static */ bool DiscardTracker::sInitialized = false;
/* static */ bool DiscardTracker::sTimerOn = false;
/* static */ int32_t DiscardTracker::sDiscardRunnablePending = 0;
/* static */ Atomic<int32_t> DiscardTracker::sDiscardRunnablePending(0);
/* static */ int64_t DiscardTracker::sCurrentDecodedImageBytes = 0;
/* static */ uint32_t DiscardTracker::sMinDiscardTimeoutMs = 10000;
/* static */ uint32_t DiscardTracker::sMaxDecodedImageKB = 42 * 1024;
@ -32,7 +31,7 @@ static const char* sDiscardTimeoutPref = "image.mem.min_discard_timeout_ms";
NS_IMETHODIMP
DiscardTracker::DiscardRunnable::Run()
{
PR_ATOMIC_SET(&sDiscardRunnablePending, 0);
sDiscardRunnablePending = 0;
DiscardTracker::DiscardNow();
return NS_OK;
@ -294,7 +293,7 @@ DiscardTracker::MaybeDiscardSoon()
if (sCurrentDecodedImageBytes > sMaxDecodedImageKB * 1024 &&
!sDiscardableImages.isEmpty()) {
// Check if the value of sDiscardRunnablePending used to be false
if (!PR_ATOMIC_SET(&sDiscardRunnablePending, 1)) {
if (!sDiscardRunnablePending.exchange(1)) {
nsRefPtr<DiscardRunnable> runnable = new DiscardRunnable();
NS_DispatchToMainThread(runnable);
}

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

@ -6,6 +6,7 @@
#ifndef mozilla_imagelib_DiscardTracker_h_
#define mozilla_imagelib_DiscardTracker_h_
#include "mozilla/Atomics.h"
#include "mozilla/LinkedList.h"
#include "mozilla/TimeStamp.h"
#include "prlock.h"
@ -111,7 +112,7 @@ class DiscardTracker
static nsCOMPtr<nsITimer> sTimer;
static bool sInitialized;
static bool sTimerOn;
static int32_t sDiscardRunnablePending;
static mozilla::Atomic<int32_t> sDiscardRunnablePending;
static int64_t sCurrentDecodedImageBytes;
static uint32_t sMinDiscardTimeoutMs;
static uint32_t sMaxDecodedImageKB;

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

@ -13,9 +13,6 @@
#include "nsCRT.h"
#include "nsComponentManagerUtils.h"
#include "nsCharsetAlias.h"
#include "pratom.h"
static int32_t gInstanceCount = 0;
/* Implementation file */
NS_IMPL_ISUPPORTS1(nsScriptableUnicodeConverter, nsIScriptableUnicodeConverter)
@ -23,12 +20,10 @@ NS_IMPL_ISUPPORTS1(nsScriptableUnicodeConverter, nsIScriptableUnicodeConverter)
nsScriptableUnicodeConverter::nsScriptableUnicodeConverter()
: mIsInternal(false)
{
PR_ATOMIC_INCREMENT(&gInstanceCount);
}
nsScriptableUnicodeConverter::~nsScriptableUnicodeConverter()
{
PR_ATOMIC_DECREMENT(&gInstanceCount);
}
nsresult

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

@ -6,6 +6,7 @@
#include <algorithm>
#include "mozilla/Atomics.h"
#include "base/compiler_specific.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
@ -32,7 +33,6 @@
#endif
#include "MessagePump.h"
#include "pratom.h"
using base::Time;
using base::TimeDelta;
@ -87,11 +87,11 @@ MessageLoop* MessageLoop::current() {
return lazy_tls_ptr.Pointer()->Get();
}
int32_t message_loop_id_seq = 0;
static mozilla::Atomic<int32_t> message_loop_id_seq(0);
MessageLoop::MessageLoop(Type type)
: type_(type),
id_(PR_ATOMIC_INCREMENT(&message_loop_id_seq)),
id_(++message_loop_id_seq),
nestable_tasks_allowed_(true),
exception_restoration_(false),
state_(NULL),

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

@ -14,7 +14,6 @@
#include "nsIServiceManager.h"
#include "nsCOMPtr.h"
#include "nsIURI.h"
#include "pratom.h"
#include "prlog.h"
#include "nsCRT.h"
#include "netCore.h"
@ -23,6 +22,7 @@
#include "nsString.h"
#include "nsTArray.h"
#include "nsIHttpChannelInternal.h"
#include "mozilla/Atomics.h"
#include "mozilla/Telemetry.h"
#include "nsAutoPtr.h"
#include "mozilla/net/PSpdyPush3.h"
@ -1056,7 +1056,7 @@ public:
nsLoadGroupConnectionInfo();
private:
int32_t mBlockingTransactionCount; // signed for PR_ATOMIC_*
Atomic<uint32_t> mBlockingTransactionCount;
nsAutoPtr<mozilla::net::SpdyPushCache3> mSpdyCache3;
};
@ -1071,14 +1071,14 @@ NS_IMETHODIMP
nsLoadGroupConnectionInfo::GetBlockingTransactionCount(uint32_t *aBlockingTransactionCount)
{
NS_ENSURE_ARG_POINTER(aBlockingTransactionCount);
*aBlockingTransactionCount = static_cast<uint32_t>(mBlockingTransactionCount);
*aBlockingTransactionCount = mBlockingTransactionCount;
return NS_OK;
}
NS_IMETHODIMP
nsLoadGroupConnectionInfo::AddBlockingTransaction()
{
PR_ATOMIC_INCREMENT(&mBlockingTransactionCount);
mBlockingTransactionCount++;
return NS_OK;
}
@ -1086,8 +1086,8 @@ NS_IMETHODIMP
nsLoadGroupConnectionInfo::RemoveBlockingTransaction(uint32_t *_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
*_retval =
static_cast<uint32_t>(PR_ATOMIC_DECREMENT(&mBlockingTransactionCount));
mBlockingTransactionCount--;
*_retval = mBlockingTransactionCount;
return NS_OK;
}

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

@ -35,12 +35,12 @@
#include "nsAlgorithm.h"
#include "nsProxyRelease.h"
#include "nsNetUtil.h"
#include "mozilla/Atomics.h"
#include "mozilla/Attributes.h"
#include "TimeStamp.h"
#include "mozilla/Telemetry.h"
#include "plbase64.h"
#include "pratom.h"
#include "prmem.h"
#include "prnetdb.h"
#include "prbit.h"
@ -424,12 +424,12 @@ public:
void IncrementSessionCount()
{
PR_ATOMIC_INCREMENT(&mSessionCount);
mSessionCount++;
}
void DecrementSessionCount()
{
PR_ATOMIC_DECREMENT(&mSessionCount);
mSessionCount--;
}
int32_t SessionCount()
@ -468,7 +468,7 @@ private:
// SessionCount might be decremented from the main or the socket
// thread, so manage it with atomic counters
int32_t mSessionCount;
Atomic<int32_t> mSessionCount;
// Queue for websockets that have not completed connecting yet.
// The first nsOpenConn with a given address will be either be

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

@ -100,17 +100,17 @@ static PLDHashTableOps gMapOps = {
#ifdef DEBUG
class nsAutoAtomic {
public:
nsAutoAtomic(int32_t &i)
nsAutoAtomic(Atomic<int32_t> &i)
:mI(i) {
PR_ATOMIC_INCREMENT(&mI);
mI++;
}
~nsAutoAtomic() {
PR_ATOMIC_DECREMENT(&mI);
mI--;
}
protected:
int32_t &mI;
Atomic<int32_t> &mI;
private:
nsAutoAtomic(); // not accessible

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

@ -6,6 +6,9 @@
#ifndef nsSecureBrowserUIImpl_h_
#define nsSecureBrowserUIImpl_h_
#ifdef DEBUG
#include "mozilla/Atomics.h"
#endif
#include "mozilla/ReentrantMonitor.h"
#include "nsCOMPtr.h"
#include "nsString.h"
@ -93,7 +96,7 @@ protected:
bool mOnLocationChangeSeen;
#ifdef DEBUG
/* related to mReentrantMonitor */
int32_t mOnStateLocationChangeReentranceDetection;
mozilla::Atomic<int32_t> mOnStateLocationChangeReentranceDetection;
#endif
static already_AddRefed<nsISupports> ExtractSecurityInfo(nsIRequest* aRequest);

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

@ -18,15 +18,17 @@
#include "PublicSSL.h"
#include "ssl.h"
#include "nsNetCID.h"
#include "mozilla/Atomics.h"
#include "mozilla/unused.h"
using mozilla::psm::SyncRunnableBase;
using mozilla::Atomic;
using mozilla::unused;
namespace {
static int32_t sCertOverrideSvcExists = 0;
static int32_t sCertDBExists = 0;
static Atomic<int32_t> sCertOverrideSvcExists(0);
static Atomic<int32_t> sCertDBExists(0);
class MainThreadClearer : public SyncRunnableBase
{
@ -38,9 +40,9 @@ public:
// is in progress. We want to avoid this, since they do not handle the situation well,
// hence the flags to avoid instantiating the services if they don't already exist.
bool certOverrideSvcExists = (bool)PR_ATOMIC_SET(&sCertOverrideSvcExists, 0);
bool certOverrideSvcExists = (bool)sCertOverrideSvcExists.exchange(0);
if (certOverrideSvcExists) {
unused << PR_ATOMIC_SET(&sCertOverrideSvcExists, 1);
sCertOverrideSvcExists = 1;
nsCOMPtr<nsICertOverrideService> icos = do_GetService(NS_CERTOVERRIDE_CONTRACTID);
if (icos) {
icos->ClearValidityOverride(
@ -49,9 +51,9 @@ public:
}
}
bool certDBExists = (bool)PR_ATOMIC_SET(&sCertDBExists, 0);
bool certDBExists = (bool)sCertDBExists.exchange(0);
if (certDBExists) {
unused << PR_ATOMIC_SET(&sCertDBExists, 1);
sCertDBExists = 1;
nsCOMPtr<nsIX509CertDB> certdb = do_GetService(NS_X509CERTDB_CONTRACTID);
if (certdb) {
nsCOMPtr<nsIRecentBadCerts> badCerts;
@ -204,13 +206,13 @@ SharedSSLState::GlobalCleanup()
/*static*/ void
SharedSSLState::NoteCertOverrideServiceInstantiated()
{
unused << PR_ATOMIC_SET(&sCertOverrideSvcExists, 1);
sCertOverrideSvcExists = 1;
}
/*static*/ void
SharedSSLState::NoteCertDBServiceInstantiated()
{
unused << PR_ATOMIC_SET(&sCertDBExists, 1);
sCertDBExists = 1;
}
void

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

@ -30,11 +30,11 @@
#include "nsThreadUtils.h"
#include "nsXPCOMStrings.h"
#include "nsProxyRelease.h"
#include "mozilla/Atomics.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/Mutex.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/Telemetry.h"
#include "pratom.h"
#include "prlog.h"
#include "prprf.h"
#include "prnetdb.h"
@ -84,7 +84,7 @@ nsIThread* nsUrlClassifierDBService::gDbBackgroundThread = nullptr;
// thread.
static bool gShuttingDownThread = false;
static int32_t gFreshnessGuarantee = CONFIRM_AGE_DEFAULT_SEC;
static mozilla::Atomic<int32_t> gFreshnessGuarantee(CONFIRM_AGE_DEFAULT_SEC);
static void
SplitTables(const nsACString& str, nsTArray<nsCString>& tables)
@ -1143,7 +1143,7 @@ nsUrlClassifierDBService::Init()
prefs->AddObserver(GETHASH_TABLES_PREF, this, false);
rv = prefs->GetIntPref(CONFIRM_AGE_PREF, &tmpint);
PR_ATOMIC_SET(&gFreshnessGuarantee, NS_SUCCEEDED(rv) ? tmpint : CONFIRM_AGE_DEFAULT_SEC);
gFreshnessGuarantee = NS_SUCCEEDED(rv) ? tmpint : CONFIRM_AGE_DEFAULT_SEC;
prefs->AddObserver(CONFIRM_AGE_PREF, this, false);
}
@ -1460,7 +1460,7 @@ nsUrlClassifierDBService::Observe(nsISupports *aSubject, const char *aTopic,
} else if (NS_LITERAL_STRING(CONFIRM_AGE_PREF).Equals(aData)) {
int32_t tmpint;
rv = prefs->GetIntPref(CONFIRM_AGE_PREF, &tmpint);
PR_ATOMIC_SET(&gFreshnessGuarantee, NS_SUCCEEDED(rv) ? tmpint : CONFIRM_AGE_DEFAULT_SEC);
gFreshnessGuarantee = NS_SUCCEEDED(rv) ? tmpint : CONFIRM_AGE_DEFAULT_SEC;
}
} else if (!strcmp(aTopic, "profile-before-change") ||
!strcmp(aTopic, "xpcom-shutdown-threads")) {

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

@ -9,7 +9,6 @@
#include "nsThreadUtils.h"
#include "nsIObserverService.h"
#include "nsServiceManagerUtils.h"
#include "pratom.h"
#include "mozilla/Services.h"
// When processing the next thread event, the appshell may process native
@ -62,8 +61,7 @@ nsBaseAppShell::Init()
void
nsBaseAppShell::NativeEventCallback()
{
int32_t hasPending = PR_ATOMIC_SET(&mNativeEventPending, 0);
if (hasPending == 0)
if (!mNativeEventPending.exchange(0))
return;
// If DoProcessNextNativeEvent is on the stack, then we assume that we can
@ -227,8 +225,7 @@ nsBaseAppShell::OnDispatchedEvent(nsIThreadInternal *thr)
if (mBlockNativeEvent)
return NS_OK;
int32_t lastVal = PR_ATOMIC_SET(&mNativeEventPending, 1);
if (lastVal == 1)
if (mNativeEventPending.exchange(1))
return NS_OK;
// Returns on the main thread in NativeEventCallback above

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

@ -6,6 +6,7 @@
#ifndef nsBaseAppShell_h__
#define nsBaseAppShell_h__
#include "mozilla/Atomics.h"
#include "nsIAppShell.h"
#include "nsIThreadInternal.h"
#include "nsIObserver.h"
@ -119,7 +120,7 @@ private:
*/
bool *mBlockedWait;
int32_t mFavorPerf;
int32_t mNativeEventPending;
mozilla::Atomic<uint32_t> mNativeEventPending;
PRIntervalTime mStarvationDelay;
PRIntervalTime mSwitchTime;
PRIntervalTime mLastNativeEventTime;