Commit f53952e52386255d9558c848de3deb7c976779cd
remove fastproityqueue
wanderer committed on 5/10/2017, 7:59:50 AMParent: 318e88b7d16e694a7a34015a3c1a6b831c91c49e
Files changed
kernel.js | changed |
package.json | changed |
kernel.js | ||
---|---|---|
@@ -25,16 +25,12 @@ | ||
25 | 25 | }) |
26 | 26 | |
27 | 27 | this.vm = new opts.VM(this) |
28 | 28 | this._waitingMap = new Map() |
29 | - this._waitingQueue = new PriorityQueue((a, b) => { | |
30 | - return a.threshold < b.threshold | |
31 | - }) | |
32 | 29 | |
33 | 30 | this.on('result', this._runNextMessage) |
34 | 31 | this.on('idle', () => { |
35 | - while (!this._waitingQueue.isEmpty()) { | |
36 | - const waiter = this._waitingQueue.poll() | |
32 | + for (const [, waiter] of this._waitingMap) { | |
37 | 33 | waiter.resolve(this.ticks) |
38 | 34 | } |
39 | 35 | }) |
40 | 36 | } |
@@ -99,28 +95,24 @@ | ||
99 | 95 | return this.ticks |
100 | 96 | } else if (this.vmState === 'idle') { |
101 | 97 | return this.ports.wait(threshold, fromPort) |
102 | 98 | } else { |
103 | - const promise = new Promise((resolve, reject) => { | |
104 | - this._waitingQueue.add({ | |
99 | + return new Promise((resolve, reject) => { | |
100 | + this._waitingMap.set(fromPort, { | |
105 | 101 | threshold: threshold, |
106 | 102 | resolve: resolve, |
107 | 103 | from: fromPort |
108 | 104 | }) |
109 | 105 | }) |
110 | - this._waitingMap.set(fromPort, promise) | |
111 | - return promise | |
112 | 106 | } |
113 | 107 | } |
114 | 108 | |
115 | 109 | incrementTicks (count) { |
116 | 110 | this.ticks += count |
117 | - while (!this._waitingQueue.isEmpty()) { | |
118 | - const waiter = this._waitingQueue.peek() | |
119 | - if (waiter.threshold > this.ticks) { | |
120 | - break | |
121 | - } else { | |
122 | - this._waitingQueue.poll().resolve(this.ticks) | |
111 | + for (const [fromPort, waiter] in this._waitingMap) { | |
112 | + if (waiter.threshold < this.ticks) { | |
113 | + this._waitingMap.delete(fromPort) | |
114 | + waiter.resolve(this.ticks) | |
123 | 115 | } |
124 | 116 | } |
125 | 117 | } |
126 | 118 | |
@@ -158,6 +150,12 @@ | ||
158 | 150 | |
159 | 151 | const receiverEntryPort = portRef === this.entryPort ? this.parentPort : portRef |
160 | 152 | const vm = await this.hypervisor.getInstance(receiverEntryPort) |
161 | 153 | vm.queue(message) |
154 | + | |
155 | + const waiter = this._waitingMap.get(portRef) | |
156 | + if (waiter) { | |
157 | + waiter.resolve(this.ticks) | |
158 | + this._waitingMap.delete(portRef) | |
159 | + } | |
162 | 160 | } |
163 | 161 | } |
Built with git-ssb-web