locker: revert to old drain behavior.
This commit is contained in:
parent
8ac673d36e
commit
6d2659a31c
@ -1161,7 +1161,7 @@ Chain.prototype.onDrain = function onDrain() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Chain.prototype.isBusy = function isBusy() {
|
Chain.prototype.isBusy = function isBusy() {
|
||||||
return this.locker.busy;
|
return this.locker.isBusy();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1071,7 +1071,7 @@ Pool.prototype.handleBlock = co(function* handleBlock(block, peer) {
|
|||||||
+ ' ts=%s height=%d highest=%d progress=%s'
|
+ ' ts=%s height=%d highest=%d progress=%s'
|
||||||
+ ' blocks=%d orphans=%d active=%d'
|
+ ' blocks=%d orphans=%d active=%d'
|
||||||
+ ' queue=%d target=%s peers=%d'
|
+ ' queue=%d target=%s peers=%d'
|
||||||
+ ' jobs=%d',
|
+ ' pending=%d jobs=%d',
|
||||||
util.date(block.ts),
|
util.date(block.ts),
|
||||||
this.chain.height,
|
this.chain.height,
|
||||||
this.chain.bestHeight,
|
this.chain.bestHeight,
|
||||||
@ -1082,6 +1082,7 @@ Pool.prototype.handleBlock = co(function* handleBlock(block, peer) {
|
|||||||
peer.queueBlock.size,
|
peer.queueBlock.size,
|
||||||
block.bits,
|
block.bits,
|
||||||
this.peers.size(),
|
this.peers.size(),
|
||||||
|
this.chain.locker.pending,
|
||||||
this.chain.locker.jobs.length);
|
this.chain.locker.jobs.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -29,6 +29,7 @@ function Locker(named) {
|
|||||||
this.destroyed = false;
|
this.destroyed = false;
|
||||||
|
|
||||||
this.map = {};
|
this.map = {};
|
||||||
|
this.pending = 0;
|
||||||
this.current = null;
|
this.current = null;
|
||||||
|
|
||||||
this.unlocker = this.unlock.bind(this);
|
this.unlocker = this.unlock.bind(this);
|
||||||
@ -75,6 +76,19 @@ Locker.prototype.hasPending = function hasPending(name) {
|
|||||||
return this.map[name] > 0;
|
return this.map[name] > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test whether the locker is
|
||||||
|
* busy with a named job.
|
||||||
|
* @returns {Boolean}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Locker.prototype.isBusy = function isBusy() {
|
||||||
|
assert(this.named, 'Must use named jobs.');
|
||||||
|
if (this.current)
|
||||||
|
return true;
|
||||||
|
return this.pending > 0;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lock the parent object and all its methods
|
* Lock the parent object and all its methods
|
||||||
* which use the locker. Begin to queue calls.
|
* which use the locker. Begin to queue calls.
|
||||||
@ -110,6 +124,7 @@ Locker.prototype.lock = function lock(arg1, arg2) {
|
|||||||
if (!this.map[name])
|
if (!this.map[name])
|
||||||
this.map[name] = 0;
|
this.map[name] = 0;
|
||||||
this.map[name]++;
|
this.map[name]++;
|
||||||
|
this.pending++;
|
||||||
}
|
}
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
self.jobs.push(new Job(resolve, reject, name));
|
self.jobs.push(new Job(resolve, reject, name));
|
||||||
@ -136,6 +151,7 @@ Locker.prototype.unlock = function unlock() {
|
|||||||
this.current = null;
|
this.current = null;
|
||||||
|
|
||||||
if (this.jobs.length === 0) {
|
if (this.jobs.length === 0) {
|
||||||
|
assert(this.pending === 0);
|
||||||
this.drain();
|
this.drain();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -148,6 +164,10 @@ Locker.prototype.unlock = function unlock() {
|
|||||||
assert(this.map[job.name] > 0);
|
assert(this.map[job.name] > 0);
|
||||||
if (--this.map[job.name] === 0)
|
if (--this.map[job.name] === 0)
|
||||||
delete this.map[job.name];
|
delete this.map[job.name];
|
||||||
|
this.pending--;
|
||||||
|
} else {
|
||||||
|
if (this.pending === 0)
|
||||||
|
this.drain();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.busy = true;
|
this.busy = true;
|
||||||
@ -164,10 +184,12 @@ Locker.prototype.unlock = function unlock() {
|
|||||||
Locker.prototype.wait = function wait() {
|
Locker.prototype.wait = function wait() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
assert(this.named, 'Must use named jobs.');
|
||||||
|
|
||||||
if (this.destroyed)
|
if (this.destroyed)
|
||||||
return Promise.reject(new Error('Locker is destroyed.'));
|
return Promise.reject(new Error('Locker is destroyed.'));
|
||||||
|
|
||||||
if (!this.busy) {
|
if (!this.isBusy()) {
|
||||||
assert(this.waiting.length === 0);
|
assert(this.waiting.length === 0);
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
@ -206,11 +228,17 @@ Locker.prototype.destroy = function destroy() {
|
|||||||
var err = new Error('Locker was destroyed.');
|
var err = new Error('Locker was destroyed.');
|
||||||
var i, jobs, job;
|
var i, jobs, job;
|
||||||
|
|
||||||
|
assert(!this.destroyed, 'Locker is already destroyed.');
|
||||||
|
|
||||||
this.destroyed = true;
|
this.destroyed = true;
|
||||||
|
|
||||||
jobs = this.jobs.slice();
|
jobs = this.jobs.slice();
|
||||||
|
|
||||||
|
this.busy = false;
|
||||||
this.jobs.length = 0;
|
this.jobs.length = 0;
|
||||||
|
this.map = {};
|
||||||
|
this.pending = 0;
|
||||||
|
this.current = null;
|
||||||
|
|
||||||
for (i = 0; i < jobs.length; i++) {
|
for (i = 0; i < jobs.length; i++) {
|
||||||
job = jobs[i];
|
job = jobs[i];
|
||||||
@ -265,6 +293,15 @@ MappedLock.prototype.has = function has(name) {
|
|||||||
return this.busy[name] === true;
|
return this.busy[name] === true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test whether the locker is busy .
|
||||||
|
* @returns {Boolean}
|
||||||
|
*/
|
||||||
|
|
||||||
|
MappedLock.prototype.isBusy = function isBusy() {
|
||||||
|
return this.busy;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lock the parent object and all its methods
|
* Lock the parent object and all its methods
|
||||||
* which use the locker with a specified key.
|
* which use the locker with a specified key.
|
||||||
@ -346,9 +383,12 @@ MappedLock.prototype.destroy = function destroy() {
|
|||||||
var keys = Object.keys(map);
|
var keys = Object.keys(map);
|
||||||
var i, j, key, jobs, job;
|
var i, j, key, jobs, job;
|
||||||
|
|
||||||
|
assert(!this.destroyed, 'Locker is already destroyed.');
|
||||||
|
|
||||||
this.destroyed = true;
|
this.destroyed = true;
|
||||||
|
|
||||||
this.jobs = {};
|
this.jobs = {};
|
||||||
|
this.busy = {};
|
||||||
|
|
||||||
for (i = 0; i < keys.length; i++) {
|
for (i = 0; i < keys.length; i++) {
|
||||||
key = keys[i];
|
key = keys[i];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user