trying to get the exclusive lock code right

This commit is contained in:
Danny Yoo 2011-12-04 20:40:44 -05:00
parent 46f314ea35
commit 31ac428276
2 changed files with 28 additions and 28 deletions

View File

@ -138,14 +138,12 @@
"js-as-closure",
function(releaseLock) {
succ = succ || function () {};
fail = fail || function () {};
releaseLock();
fail = fail || function () {};
if (!(baselib.arity.isArityMatching(v.racketArity, args.length - 2))) {
var msg = baselib.format.format(
"arity mismatch: ~s expected ~s argument(s) but received ~s",
[v.displayName, v.racketArity, args.length - 2]);
releaseLock();
return fail(new baselib.exceptions.RacketError(
msg,
baselib.exceptions.makeExnFailContractArity(msg,
@ -197,8 +195,8 @@
MACHINE.a = oldArgcount;
MACHINE.p = oldProc;
fail(e);
};
};
releaseLock();
MACHINE.trampoline(v.label);
});
};
@ -234,17 +232,17 @@
for (i = 0; i < arguments.length; i++) {
args.push(arguments[i]);
}
MACHINE.exclusiveLock.acquire(
MACHINE.exclusiveLock.acquire(
"internal call during pause",
function(releaseLock) {
releaseLock();
var i;
var oldArgcount, oldVal, oldProc, oldErrorHandler;
if (! baselib.arity.isArityMatching(proc.racketArity, args.length - 4)) {
var msg = baselib.format.format("arity mismatch: ~s expected ~s arguments, but received ~s",
[proc.displayName, proc.racketArity, args.length - 4]);
return fail(baselib.exceptions.makeExnFailContractArity(msg,
MACHINE.captureContinuationMarks()));
releaseLock();
fail(baselib.exceptions.makeExnFailContractArity(msg,
MACHINE.captureContinuationMarks()));
}
if (isClosure(proc)) {
@ -292,10 +290,11 @@
MACHINE.p = oldProc;
fail(e);
};
releaseLock();
MACHINE.trampoline(proc.label);
} else {
releaseLock();
fail(baselib.exceptions.makeExnFail(
baselib.format.format(
"Not a procedure: ~e",

View File

@ -202,24 +202,25 @@
that,
// releaseLock
function() {
setTimeout(
function() {
var waiter;
if (alreadyReleased) {
throw new Error(
"Internal error: trying to release the lock, but already released");
}
if (that.locked === false) {
throw new Error(
"Internal error: trying to unlock the lock, but already unlocked");
}
that.locked = false;
alreadyReleased = true;
if (that.waiters.length > 0) {
waiter = that.waiters.shift();
var waiter;
if (alreadyReleased) {
throw new Error(
"Internal error: trying to release the lock, but already released");
}
if (that.locked === false) {
throw new Error(
"Internal error: trying to unlock the lock, but already unlocked");
}
that.locked = false;
alreadyReleased = true;
if (that.waiters.length > 0) {
waiter = that.waiters.shift();
setTimeout(
function() {
that.acquire(waiter.id, waiter.onAcquire);
}
}, 0);
},
0);
}
});
} else {
this.waiters.push({ id: id,