Commit 99abd38a5b872b13ce3d020a5947a5325c6c13f4
remove unneeded waits
wanderer committed on 5/8/2017, 6:49:53 PMParent: e0d0380c051f78c76923c1d39111ee94896e3a8d
Files changed
kernel.js | changed |
portManager.js | changed |
kernel.js | ||
---|---|---|
@@ -11,8 +11,9 @@ | ||
11 | 11 | this.hypervisor = opts.hypervisor |
12 | 12 | |
13 | 13 | this.vmState = 'idle' |
14 | 14 | this.ticks = 0 |
15 | + | |
15 | 16 | // create the port manager |
16 | 17 | this.ports = new PortManager({ |
17 | 18 | kernel: this, |
18 | 19 | hypervisor: opts.hypervisor, |
@@ -24,8 +25,9 @@ | ||
24 | 25 | this.vm = new opts.VM(this) |
25 | 26 | this._waitingQueue = new PriorityQueue((a, b) => { |
26 | 27 | return a.threshold > b.threshold |
27 | 28 | }) |
29 | + | |
28 | 30 | this.on('result', this._runNextMessage) |
29 | 31 | this.on('idle', () => { |
30 | 32 | while (!this._waitingQueue.isEmpty()) { |
31 | 33 | const waiter = this._waitingQueue.poll() |
@@ -37,10 +39,10 @@ | ||
37 | 39 | start () { |
38 | 40 | return this.ports.start() |
39 | 41 | } |
40 | 42 | |
41 | - async queue (message) { | |
42 | - await this.ports.queue(message) | |
43 | + queue (message) { | |
44 | + this.ports.queue(message) | |
43 | 45 | if (this.vmState !== 'running') { |
44 | 46 | this._updateVmState('running') |
45 | 47 | this._runNextMessage() |
46 | 48 | } |
@@ -109,9 +111,9 @@ | ||
109 | 111 | } |
110 | 112 | |
111 | 113 | // returns a promise that resolves once the kernel hits the threshould tick |
112 | 114 | // count |
113 | - async wait (threshold, fromPort) { | |
115 | + wait (threshold, fromPort) { | |
114 | 116 | if (threshold <= this.ticks) { |
115 | 117 | return this.ticks |
116 | 118 | } else if (this.vmState === 'idle') { |
117 | 119 | return this.ports.wait(threshold, fromPort) |
@@ -156,9 +158,9 @@ | ||
156 | 158 | } |
157 | 159 | } |
158 | 160 | |
159 | 161 | // create the port instance |
160 | - await this.ports.set(name, portRef) | |
162 | + this.ports.set(name, portRef) | |
161 | 163 | // incerment the nonce |
162 | 164 | nonce = new BN(nonce) |
163 | 165 | nonce.iaddn(1) |
164 | 166 | this.state['/'].nonce = nonce.toArray() |
portManager.js | ||
---|---|---|
@@ -31,41 +31,35 @@ | ||
31 | 31 | |
32 | 32 | async start () { |
33 | 33 | // map ports to thier id's |
34 | 34 | this.ports = await this.hypervisor.graph.get(this.state, 'ports') |
35 | - const promises = Object.keys(this.ports).map(name => { | |
35 | + Object.keys(this.ports).map(name => { | |
36 | 36 | const port = this.ports[name] |
37 | 37 | this._mapPort(name, port) |
38 | 38 | }) |
39 | 39 | |
40 | - // create the parent port | |
41 | - await Promise.all(promises) | |
42 | 40 | // skip the root, since it doesn't have a parent |
43 | 41 | if (this.parentPort !== undefined) { |
44 | - const id = await this.hypervisor.generateID(this.parentPort) | |
45 | - this._portMap.set(id, new Port(ENTRY)) | |
42 | + this._portMap.set(this.parentPort, new Port(ENTRY)) | |
46 | 43 | } |
47 | 44 | } |
48 | 45 | |
49 | - async _mapPort (name, port) { | |
50 | - const id = await this.hypervisor.generateID(port) | |
51 | - port = new Port(name) | |
52 | - this._portMap.set(id, port) | |
46 | + _mapPort (name, portRef) { | |
47 | + const port = new Port(name) | |
48 | + this._portMap.set(portRef, port) | |
53 | 49 | } |
54 | 50 | |
55 | - async queue (message) { | |
56 | - const id = await this.hypervisor.generateID(message.fromPort) | |
57 | - this._portMap.get(id).queue(message) | |
51 | + queue (message) { | |
52 | + this._portMap.get(message.fromPort).queue(message) | |
58 | 53 | } |
59 | 54 | |
60 | 55 | set (name, port) { |
61 | 56 | this.ports[name] = port |
62 | 57 | return this._mapPort(name, port) |
63 | 58 | } |
64 | 59 | |
65 | - async get (port) { | |
66 | - const id = await this.hypervisor.generateID(port) | |
67 | - return this._portMap.get(id) | |
60 | + get (port) { | |
61 | + return this._portMap.get(port) | |
68 | 62 | } |
69 | 63 | |
70 | 64 | getRef (key) { |
71 | 65 | if (key === ENTRY) { |
@@ -75,19 +69,17 @@ | ||
75 | 69 | } |
76 | 70 | } |
77 | 71 | |
78 | 72 | // waits till all ports have reached a threshold tick count |
79 | - async wait (threshold, fromPort) { | |
73 | + wait (threshold, fromPort) { | |
80 | 74 | // find the ports that have a smaller tick count then the threshold tick count |
81 | - const unkownPorts = [...this._portMap].filter(([id, port]) => { | |
82 | - const portRef = this.getRef(port.name) | |
75 | + const unkownPorts = [...this._portMap].filter(([portRef, port]) => { | |
83 | 76 | return port.ticks < threshold && fromPort !== portRef |
84 | 77 | }) |
85 | 78 | |
86 | - const promises = unkownPorts.map(async ([id, port]) => { | |
87 | - const portObj = port.name === ENTRY ? this.parentPort : this.ports[port.name] | |
79 | + const promises = unkownPorts.map(async ([portRef, port]) => { | |
88 | 80 | // update the port's tick count |
89 | - port.ticks = await this.hypervisor.wait(portObj, threshold, this.entryPort) | |
81 | + port.ticks = await this.hypervisor.wait(portRef, threshold, this.entryPort) | |
90 | 82 | }) |
91 | 83 | return Promise.all(promises) |
92 | 84 | } |
93 | 85 |
Built with git-ssb-web