зеркало из https://github.com/mozilla/gecko-dev.git
Bug 772314 - Replace NSPR's interval timer with PRMJ_Now; r=luke
PR_IntervalTime offers no extra functionality above PRMJ_Now for our uses.
This commit is contained in:
Родитель
c8f0c7a400
Коммит
78f1843bbe
|
@ -3199,20 +3199,3 @@ js_DateGetMsecSinceEpoch(JSContext *cx, JSObject *obj)
|
|||
return obj->isDate() ? obj->getDateUTCTime().toNumber() : 0;
|
||||
}
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
#include "prinrval.h"
|
||||
|
||||
JS_FRIEND_API(uint32_t)
|
||||
js_IntervalNow()
|
||||
{
|
||||
return uint32_t(PR_IntervalToMilliseconds(PR_IntervalNow()));
|
||||
}
|
||||
|
||||
#else /* !JS_THREADSAFE */
|
||||
|
||||
JS_FRIEND_API(uint32_t)
|
||||
js_IntervalNow()
|
||||
{
|
||||
return uint32_t(PRMJ_Now() / PRMJ_USEC_PER_MSEC);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -83,11 +83,6 @@ js_DateGetMinutes(JSContext *cx, JSObject* obj);
|
|||
extern JS_FRIEND_API(int)
|
||||
js_DateGetSeconds(JSContext *cx, JSObject* obj);
|
||||
|
||||
typedef uint32_t JSIntervalTime;
|
||||
|
||||
extern JS_FRIEND_API(JSIntervalTime)
|
||||
js_IntervalNow();
|
||||
|
||||
/* Date constructor native. Exposed only so the JIT can know its address. */
|
||||
JSBool
|
||||
js_Date(JSContext *cx, unsigned argc, js::Value *vp);
|
||||
|
|
|
@ -141,7 +141,7 @@ static PRLock *gWatchdogLock = NULL;
|
|||
static PRCondVar *gWatchdogWakeup = NULL;
|
||||
static PRThread *gWatchdogThread = NULL;
|
||||
static bool gWatchdogHasTimeout = false;
|
||||
static PRIntervalTime gWatchdogTimeout = 0;
|
||||
static int64_t gWatchdogTimeout = 0;
|
||||
|
||||
static PRCondVar *gSleepWakeup = NULL;
|
||||
|
||||
|
@ -302,7 +302,7 @@ GetLine(FILE *file, const char * prompt)
|
|||
* on timing.
|
||||
*/
|
||||
struct JSShellContextData {
|
||||
volatile JSIntervalTime startTime;
|
||||
volatile int64_t startTime;
|
||||
};
|
||||
|
||||
static JSShellContextData *
|
||||
|
@ -316,7 +316,7 @@ NewContextData()
|
|||
calloc(sizeof(JSShellContextData), 1);
|
||||
if (!data)
|
||||
return NULL;
|
||||
data->startTime = js_IntervalNow();
|
||||
data->startTime = PRMJ_Now();
|
||||
return data;
|
||||
}
|
||||
|
||||
|
@ -2790,12 +2790,11 @@ Resolver(JSContext *cx, unsigned argc, jsval *vp)
|
|||
|
||||
/*
|
||||
* Check that t1 comes strictly before t2. The function correctly deals with
|
||||
* PRIntervalTime wrap-around between t2 and t1 assuming that t2 and t1 stays
|
||||
* within INT32_MAX from each other. We use MAX_TIMEOUT_INTERVAL to enforce
|
||||
* this restriction.
|
||||
* wrap-around between t2 and t1 assuming that t2 and t1 stays within INT32_MAX
|
||||
* from each other. We use MAX_TIMEOUT_INTERVAL to enforce this restriction.
|
||||
*/
|
||||
static bool
|
||||
IsBefore(PRIntervalTime t1, PRIntervalTime t2)
|
||||
IsBefore(int64_t t1, int64_t t2)
|
||||
{
|
||||
return int32_t(t1 - t2) < 0;
|
||||
}
|
||||
|
@ -2803,7 +2802,7 @@ IsBefore(PRIntervalTime t1, PRIntervalTime t2)
|
|||
static JSBool
|
||||
Sleep_fn(JSContext *cx, unsigned argc, jsval *vp)
|
||||
{
|
||||
PRIntervalTime t_ticks;
|
||||
int64_t t_ticks;
|
||||
|
||||
if (argc == 0) {
|
||||
t_ticks = 0;
|
||||
|
@ -2820,19 +2819,19 @@ Sleep_fn(JSContext *cx, unsigned argc, jsval *vp)
|
|||
}
|
||||
t_ticks = (t_secs <= 0.0)
|
||||
? 0
|
||||
: PRIntervalTime(PR_TicksPerSecond() * t_secs);
|
||||
: int64_t(PRMJ_USEC_PER_SEC * t_secs);
|
||||
}
|
||||
if (t_ticks == 0) {
|
||||
JS_YieldRequest(cx);
|
||||
} else {
|
||||
JSAutoSuspendRequest suspended(cx);
|
||||
PR_Lock(gWatchdogLock);
|
||||
PRIntervalTime to_wakeup = PR_IntervalNow() + t_ticks;
|
||||
int64_t to_wakeup = PRMJ_Now() + t_ticks;
|
||||
for (;;) {
|
||||
PR_WaitCondVar(gSleepWakeup, t_ticks);
|
||||
if (gCanceled)
|
||||
break;
|
||||
PRIntervalTime now = PR_IntervalNow();
|
||||
int64_t now = PRMJ_Now();
|
||||
if (!IsBefore(now, to_wakeup))
|
||||
break;
|
||||
t_ticks = to_wakeup - now;
|
||||
|
@ -2892,7 +2891,7 @@ WatchdogMain(void *arg)
|
|||
|
||||
PR_Lock(gWatchdogLock);
|
||||
while (gWatchdogThread) {
|
||||
PRIntervalTime now = PR_IntervalNow();
|
||||
int64_t now = PRMJ_Now();
|
||||
if (gWatchdogHasTimeout && !IsBefore(now, gWatchdogTimeout)) {
|
||||
/*
|
||||
* The timeout has just expired. Trigger the operation callback
|
||||
|
@ -2906,9 +2905,9 @@ WatchdogMain(void *arg)
|
|||
/* Wake up any threads doing sleep. */
|
||||
PR_NotifyAllCondVar(gSleepWakeup);
|
||||
} else {
|
||||
PRIntervalTime sleepDuration = gWatchdogHasTimeout
|
||||
? gWatchdogTimeout - now
|
||||
: PR_INTERVAL_NO_TIMEOUT;
|
||||
int64_t sleepDuration = gWatchdogHasTimeout
|
||||
? gWatchdogTimeout - now
|
||||
: PR_INTERVAL_NO_TIMEOUT;
|
||||
DebugOnly<PRStatus> status =
|
||||
PR_WaitCondVar(gWatchdogWakeup, sleepDuration);
|
||||
JS_ASSERT(status == PR_SUCCESS);
|
||||
|
@ -2927,8 +2926,8 @@ ScheduleWatchdog(JSRuntime *rt, double t)
|
|||
return true;
|
||||
}
|
||||
|
||||
PRIntervalTime interval = PRIntervalTime(ceil(t * PR_TicksPerSecond()));
|
||||
PRIntervalTime timeout = PR_IntervalNow() + interval;
|
||||
int64_t interval = int64_t(ceil(t * PRMJ_USEC_PER_SEC));
|
||||
int64_t timeout = PRMJ_Now() + interval;
|
||||
PR_Lock(gWatchdogLock);
|
||||
if (!gWatchdogThread) {
|
||||
JS_ASSERT(!gWatchdogHasTimeout);
|
||||
|
@ -3081,7 +3080,7 @@ Elapsed(JSContext *cx, unsigned argc, jsval *vp)
|
|||
double d = 0.0;
|
||||
JSShellContextData *data = GetContextData(cx);
|
||||
if (data)
|
||||
d = js_IntervalNow() - data->startTime;
|
||||
d = PRMJ_Now() - data->startTime;
|
||||
return JS_NewNumberValue(cx, d, vp);
|
||||
}
|
||||
JS_ReportError(cx, "Wrong number of arguments");
|
||||
|
|
Загрузка…
Ссылка в новой задаче