git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 99abd38a5b872b13ce3d020a5947a5325c6c13f4

remove unneeded waits

wanderer committed on 5/8/2017, 6:49:53 PM
Parent: e0d0380c051f78c76923c1d39111ee94896e3a8d

Files changed

kernel.jschanged
portManager.jschanged
kernel.jsView
@@ -11,8 +11,9 @@
1111 this.hypervisor = opts.hypervisor
1212
1313 this.vmState = 'idle'
1414 this.ticks = 0
15+
1516 // create the port manager
1617 this.ports = new PortManager({
1718 kernel: this,
1819 hypervisor: opts.hypervisor,
@@ -24,8 +25,9 @@
2425 this.vm = new opts.VM(this)
2526 this._waitingQueue = new PriorityQueue((a, b) => {
2627 return a.threshold > b.threshold
2728 })
29+
2830 this.on('result', this._runNextMessage)
2931 this.on('idle', () => {
3032 while (!this._waitingQueue.isEmpty()) {
3133 const waiter = this._waitingQueue.poll()
@@ -37,10 +39,10 @@
3739 start () {
3840 return this.ports.start()
3941 }
4042
41- async queue (message) {
42- await this.ports.queue(message)
43+ queue (message) {
44+ this.ports.queue(message)
4345 if (this.vmState !== 'running') {
4446 this._updateVmState('running')
4547 this._runNextMessage()
4648 }
@@ -109,9 +111,9 @@
109111 }
110112
111113 // returns a promise that resolves once the kernel hits the threshould tick
112114 // count
113- async wait (threshold, fromPort) {
115+ wait (threshold, fromPort) {
114116 if (threshold <= this.ticks) {
115117 return this.ticks
116118 } else if (this.vmState === 'idle') {
117119 return this.ports.wait(threshold, fromPort)
@@ -156,9 +158,9 @@
156158 }
157159 }
158160
159161 // create the port instance
160- await this.ports.set(name, portRef)
162+ this.ports.set(name, portRef)
161163 // incerment the nonce
162164 nonce = new BN(nonce)
163165 nonce.iaddn(1)
164166 this.state['/'].nonce = nonce.toArray()
portManager.jsView
@@ -31,41 +31,35 @@
3131
3232 async start () {
3333 // map ports to thier id's
3434 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 => {
3636 const port = this.ports[name]
3737 this._mapPort(name, port)
3838 })
3939
40- // create the parent port
41- await Promise.all(promises)
4240 // skip the root, since it doesn't have a parent
4341 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))
4643 }
4744 }
4845
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)
5349 }
5450
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)
5853 }
5954
6055 set (name, port) {
6156 this.ports[name] = port
6257 return this._mapPort(name, port)
6358 }
6459
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)
6862 }
6963
7064 getRef (key) {
7165 if (key === ENTRY) {
@@ -75,19 +69,17 @@
7569 }
7670 }
7771
7872 // waits till all ports have reached a threshold tick count
79- async wait (threshold, fromPort) {
73+ wait (threshold, fromPort) {
8074 // 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]) => {
8376 return port.ticks < threshold && fromPort !== portRef
8477 })
8578
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]) => {
8880 // 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)
9082 })
9183 return Promise.all(promises)
9284 }
9385

Built with git-ssb-web