Bug 884676 - Part 2: Remove JS_ATOMIC_* in favor of mozilla::Atomic, r=Waldo.

This commit is contained in:
Joshua Cranmer 2013-07-13 20:07:11 -05:00
Родитель 44a60190fc
Коммит 8258da2d0d
14 изменённых файлов: 38 добавлений и 53 удалений

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

@ -38,7 +38,7 @@ NS_IMETHODIMP_(nsrefcnt)
nsNullPrincipal::AddRef()
{
NS_PRECONDITION(int32_t(refcount) >= 0, "illegal refcnt");
nsrefcnt count = PR_ATOMIC_INCREMENT(&refcount);
nsrefcnt count = ++refcount;
NS_LOG_ADDREF(this, count, "nsNullPrincipal", sizeof(*this));
return count;
}
@ -47,7 +47,7 @@ NS_IMETHODIMP_(nsrefcnt)
nsNullPrincipal::Release()
{
NS_PRECONDITION(0 != refcount, "dup release");
nsrefcnt count = PR_ATOMIC_DECREMENT(&refcount);
nsrefcnt count = --refcount;
NS_LOG_RELEASE(this, count, "nsNullPrincipal");
if (count == 0) {
delete this;

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

@ -57,7 +57,7 @@ nsBasePrincipal::AddRef()
{
NS_PRECONDITION(int32_t(refcount) >= 0, "illegal refcnt");
// XXXcaa does this need to be threadsafe? See bug 143559.
nsrefcnt count = PR_ATOMIC_INCREMENT(&refcount);
nsrefcnt count = ++refcount;
NS_LOG_ADDREF(this, count, "nsBasePrincipal", sizeof(*this));
return count;
}
@ -66,7 +66,7 @@ NS_IMETHODIMP_(nsrefcnt)
nsBasePrincipal::Release()
{
NS_PRECONDITION(0 != refcount, "dup release");
nsrefcnt count = PR_ATOMIC_DECREMENT(&refcount);
nsrefcnt count = --refcount;
NS_LOG_RELEASE(this, count, "nsBasePrincipal");
if (count == 0) {
delete this;

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

@ -32,7 +32,7 @@ NS_IMETHODIMP_(nsrefcnt)
nsSystemPrincipal::AddRef()
{
NS_PRECONDITION(int32_t(refcount) >= 0, "illegal refcnt");
nsrefcnt count = PR_ATOMIC_INCREMENT(&refcount);
nsrefcnt count = ++refcount;
NS_LOG_ADDREF(this, count, "nsSystemPrincipal", sizeof(*this));
return count;
}
@ -41,7 +41,7 @@ NS_IMETHODIMP_(nsrefcnt)
nsSystemPrincipal::Release()
{
NS_PRECONDITION(0 != refcount, "dup release");
nsrefcnt count = PR_ATOMIC_DECREMENT(&refcount);
nsrefcnt count = --refcount;
NS_LOG_RELEASE(this, count, "nsSystemPrincipal");
if (count == 0) {
delete this;

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

@ -9,21 +9,19 @@
BEGIN_WORKERS_NAMESPACE
namespace {
JSPrincipals gPrincipal = {
1
#ifdef DEBUG
, kJSPrincipalsDebugToken
#endif
};
} // anonymous namespace
JSPrincipals*
GetWorkerPrincipal()
{
return &gPrincipal;
static Atomic<uint32_t> sInitialized(0);
static JSPrincipals sPrincipal;
if (!sInitialized.exchange(1)) {
sPrincipal.refcount = 1;
#ifdef DEBUG
sPrincipal.debugToken = kJSPrincipalsDebugToken;
#endif
}
return &sPrincipal;
}
END_WORKERS_NAMESPACE

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

@ -4,10 +4,6 @@
#include "jsapi-tests/tests.h"
JSPrincipals system_principals = {
1
};
JSClass global_class = {
"global",
JSCLASS_IS_GLOBAL | JSCLASS_GLOBAL_FLAGS,
@ -41,6 +37,8 @@ CallTrusted(JSContext *cx, unsigned argc, jsval *vp)
BEGIN_TEST(testChromeBuffer)
{
JSPrincipals system_principals;
system_principals.refcount = 1;
JS_SetTrustedPrincipals(rt, &system_principals);
trusted_glob = JS_NewGlobalObject(cx, &global_class, &system_principals);

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

@ -13,11 +13,13 @@ ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
sOriginPrincipalsInErrorReporter = report->originPrincipals;
}
JSPrincipals prin1 = { 1 };
JSPrincipals prin2 = { 1 };
JSPrincipals prin1;
JSPrincipals prin2;
BEGIN_TEST(testOriginPrincipals)
{
prin1.refcount = 1;
prin2.refcount = 2;
/*
* Currently, the only way to set a non-trivial originPrincipal is to use
* JS_EvaluateUCScriptForPrincipalsVersionOrigin. This does not expose the

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

@ -11,6 +11,8 @@
#include "jsscriptinlines.h"
using mozilla::ArrayLength;
static JSScript *
CompileScriptForPrincipalsVersionOrigin(JSContext *cx, JS::HandleObject obj,
JSPrincipals *principals, JSPrincipals *originPrincipals,
@ -75,13 +77,11 @@ FreezeThaw(JSContext *cx, JS::HandleObject funobj)
return funobj2;
}
static JSPrincipals testPrincipals[] = {
{ 1 },
{ 1 },
};
BEGIN_TEST(testXDR_principals)
{
JSPrincipals testPrincipals[2];
for (size_t i = 0; i < ArrayLength(testPrincipals); ++i)
testPrincipals[i].refcount = 1;
JSScript *script;
JSCompartment *compartment = js::GetContextCompartment(cx);
for (int i = TEST_FIRST; i != TEST_END; ++i) {

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

@ -4704,13 +4704,13 @@ JS_CheckAccess(JSContext *cx, JSObject *objArg, jsid idArg, JSAccessMode mode,
JS_PUBLIC_API(void)
JS_HoldPrincipals(JSPrincipals *principals)
{
JS_ATOMIC_INCREMENT(&principals->refcount);
++principals->refcount;
}
JS_PUBLIC_API(void)
JS_DropPrincipals(JSRuntime *rt, JSPrincipals *principals)
{
int rc = JS_ATOMIC_DECREMENT(&principals->refcount);
uint32_t rc = --principals->refcount;
if (rc == 0)
rt->destroyPrincipals(principals);
}

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

@ -9,6 +9,7 @@
#ifndef jsapi_h
#define jsapi_h
#include "mozilla/Atomics.h"
#include "mozilla/FloatingPoint.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/RangedPtr.h"
@ -3728,7 +3729,7 @@ JS_SetReservedSlot(JSObject *obj, uint32_t index, jsval v);
*/
struct JSPrincipals {
/* Don't call "destroy"; use reference counting macros below. */
int refcount;
mozilla::Atomic<uint32_t> refcount;
#ifdef DEBUG
/* A helper to facilitate principals debugging. */

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

@ -992,7 +992,7 @@ js_InvokeOperationCallback(JSContext *cx)
* thread is racing us here we will accumulate another callback request
* which will be serviced at the next opportunity.
*/
JS_ATOMIC_SET(&rt->interrupt, 0);
rt->interrupt = 0;
/* IonMonkey sets its stack limit to UINTPTR_MAX to trigger operaton callbacks. */
rt->resetIonStackLimit();

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

@ -11,17 +11,11 @@
#ifdef JS_THREADSAFE
# include "pratom.h"
# include "prlock.h"
# include "prcvar.h"
# include "prthread.h"
# include "prinit.h"
# define JS_ATOMIC_INCREMENT(p) PR_ATOMIC_INCREMENT((int32_t *)(p))
# define JS_ATOMIC_DECREMENT(p) PR_ATOMIC_DECREMENT((int32_t *)(p))
# define JS_ATOMIC_ADD(p,v) PR_ATOMIC_ADD((int32_t *)(p), (int32_t)(v))
# define JS_ATOMIC_SET(p,v) PR_ATOMIC_SET((int32_t *)(p), (int32_t)(v))
namespace js {
// Defined in jsgc.cpp.
unsigned GetCPUCount();
@ -33,11 +27,6 @@ typedef struct PRThread PRThread;
typedef struct PRCondVar PRCondVar;
typedef struct PRLock PRLock;
# define JS_ATOMIC_INCREMENT(p) (++*(p))
# define JS_ATOMIC_DECREMENT(p) (--*(p))
# define JS_ATOMIC_ADD(p,v) (*(p) += (v))
# define JS_ATOMIC_SET(p,v) (*(p) = (v))
#endif /* JS_THREADSAFE */
#endif /* jslock_h */

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

@ -5160,9 +5160,6 @@ MaybeOverrideOutFileFromEnv(const char* const envVar,
}
}
/* Set the initial counter to 1 so the principal will never be destroyed. */
JSPrincipals shellTrustedPrincipals = { 1 };
JSBool
CheckObjectAccess(JSContext *cx, HandleObject obj, HandleId id, JSAccessMode mode,
MutableHandleValue vp)
@ -5356,6 +5353,9 @@ main(int argc, char **argv, char **envp)
JS::DisableGenerationalGC(rt);
#endif
// Set the initial counter to 1 so the principal will never be destroyed.
JSPrincipals shellTrustedPrincipals;
shellTrustedPrincipals.refcount = 1;
JS_SetTrustedPrincipals(rt, &shellTrustedPrincipals);
JS_SetSecurityCallbacks(rt, &securityCallbacks);

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

@ -88,11 +88,7 @@ JSRuntime::triggerOperationCallback()
*/
mainThread.setIonStackLimit(-1);
/*
* Use JS_ATOMIC_SET in the hope that it ensures the write will become
* immediately visible to other processors polling the flag.
*/
JS_ATOMIC_SET(&interrupt, 1);
interrupt = 1;
#ifdef JS_ION
/* asm.js code uses a separate mechanism to halt running code. */

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

@ -7,6 +7,7 @@
#ifndef vm_Runtime_h
#define vm_Runtime_h
#include "mozilla/Atomics.h"
#include "mozilla/LinkedList.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/PodOperations.h"
@ -648,7 +649,7 @@ struct JSRuntime : public JS::shadow::Runtime,
* If non-zero, we were been asked to call the operation callback as soon
* as possible.
*/
volatile int32_t interrupt;
mozilla::Atomic<int32_t> interrupt;
#ifdef JS_THREADSAFE
private: