trying to get the exclusive lock code right
This commit is contained in:
parent
46f314ea35
commit
31ac428276
|
@ -139,13 +139,11 @@
|
||||||
function(releaseLock) {
|
function(releaseLock) {
|
||||||
succ = succ || function () {};
|
succ = succ || function () {};
|
||||||
fail = fail || function () {};
|
fail = fail || function () {};
|
||||||
|
|
||||||
releaseLock();
|
|
||||||
|
|
||||||
if (!(baselib.arity.isArityMatching(v.racketArity, args.length - 2))) {
|
if (!(baselib.arity.isArityMatching(v.racketArity, args.length - 2))) {
|
||||||
var msg = baselib.format.format(
|
var msg = baselib.format.format(
|
||||||
"arity mismatch: ~s expected ~s argument(s) but received ~s",
|
"arity mismatch: ~s expected ~s argument(s) but received ~s",
|
||||||
[v.displayName, v.racketArity, args.length - 2]);
|
[v.displayName, v.racketArity, args.length - 2]);
|
||||||
|
releaseLock();
|
||||||
return fail(new baselib.exceptions.RacketError(
|
return fail(new baselib.exceptions.RacketError(
|
||||||
msg,
|
msg,
|
||||||
baselib.exceptions.makeExnFailContractArity(msg,
|
baselib.exceptions.makeExnFailContractArity(msg,
|
||||||
|
@ -197,8 +195,8 @@
|
||||||
MACHINE.a = oldArgcount;
|
MACHINE.a = oldArgcount;
|
||||||
MACHINE.p = oldProc;
|
MACHINE.p = oldProc;
|
||||||
fail(e);
|
fail(e);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
releaseLock();
|
||||||
MACHINE.trampoline(v.label);
|
MACHINE.trampoline(v.label);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -234,17 +232,17 @@
|
||||||
for (i = 0; i < arguments.length; i++) {
|
for (i = 0; i < arguments.length; i++) {
|
||||||
args.push(arguments[i]);
|
args.push(arguments[i]);
|
||||||
}
|
}
|
||||||
MACHINE.exclusiveLock.acquire(
|
MACHINE.exclusiveLock.acquire(
|
||||||
"internal call during pause",
|
"internal call during pause",
|
||||||
function(releaseLock) {
|
function(releaseLock) {
|
||||||
releaseLock();
|
|
||||||
var i;
|
var i;
|
||||||
var oldArgcount, oldVal, oldProc, oldErrorHandler;
|
var oldArgcount, oldVal, oldProc, oldErrorHandler;
|
||||||
if (! baselib.arity.isArityMatching(proc.racketArity, args.length - 4)) {
|
if (! baselib.arity.isArityMatching(proc.racketArity, args.length - 4)) {
|
||||||
var msg = baselib.format.format("arity mismatch: ~s expected ~s arguments, but received ~s",
|
var msg = baselib.format.format("arity mismatch: ~s expected ~s arguments, but received ~s",
|
||||||
[proc.displayName, proc.racketArity, args.length - 4]);
|
[proc.displayName, proc.racketArity, args.length - 4]);
|
||||||
return fail(baselib.exceptions.makeExnFailContractArity(msg,
|
releaseLock();
|
||||||
MACHINE.captureContinuationMarks()));
|
fail(baselib.exceptions.makeExnFailContractArity(msg,
|
||||||
|
MACHINE.captureContinuationMarks()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isClosure(proc)) {
|
if (isClosure(proc)) {
|
||||||
|
@ -292,10 +290,11 @@
|
||||||
MACHINE.p = oldProc;
|
MACHINE.p = oldProc;
|
||||||
fail(e);
|
fail(e);
|
||||||
};
|
};
|
||||||
|
releaseLock();
|
||||||
MACHINE.trampoline(proc.label);
|
MACHINE.trampoline(proc.label);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
releaseLock();
|
||||||
fail(baselib.exceptions.makeExnFail(
|
fail(baselib.exceptions.makeExnFail(
|
||||||
baselib.format.format(
|
baselib.format.format(
|
||||||
"Not a procedure: ~e",
|
"Not a procedure: ~e",
|
||||||
|
|
|
@ -202,24 +202,25 @@
|
||||||
that,
|
that,
|
||||||
// releaseLock
|
// releaseLock
|
||||||
function() {
|
function() {
|
||||||
setTimeout(
|
var waiter;
|
||||||
function() {
|
if (alreadyReleased) {
|
||||||
var waiter;
|
throw new Error(
|
||||||
if (alreadyReleased) {
|
"Internal error: trying to release the lock, but already released");
|
||||||
throw new Error(
|
}
|
||||||
"Internal error: trying to release the lock, but already released");
|
if (that.locked === false) {
|
||||||
}
|
throw new Error(
|
||||||
if (that.locked === false) {
|
"Internal error: trying to unlock the lock, but already unlocked");
|
||||||
throw new Error(
|
}
|
||||||
"Internal error: trying to unlock the lock, but already unlocked");
|
that.locked = false;
|
||||||
}
|
alreadyReleased = true;
|
||||||
that.locked = false;
|
if (that.waiters.length > 0) {
|
||||||
alreadyReleased = true;
|
waiter = that.waiters.shift();
|
||||||
if (that.waiters.length > 0) {
|
setTimeout(
|
||||||
waiter = that.waiters.shift();
|
function() {
|
||||||
that.acquire(waiter.id, waiter.onAcquire);
|
that.acquire(waiter.id, waiter.onAcquire);
|
||||||
}
|
},
|
||||||
}, 0);
|
0);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.waiters.push({ id: id,
|
this.waiters.push({ id: id,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user