git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 2fb975398cfb471a241d9576050158a86e8eff04

removed all locks from the schedular

Signed-off-by: wanderer <mjbecze@gmail.com>
wanderer committed on 8/10/2017, 11:45:29 PM
Parent: 4edd1fee9342f57e8ccc90c989eccfbf4aa9a15f

Files changed

portManager.jschanged
scheduler.jschanged
tests/index.jschanged
portManager.jsView
@@ -95,10 +95,10 @@
9595 * @param {string} name
9696 */
9797 delete (name) {
9898 const port = this.ports[name]
99- this.kernel.send(port, new DeleteMessage())
10099 this._delete(name)
100 + return this.kernel.send(port, new DeleteMessage())
101101 }
102102
103103 _delete (name) {
104104 this.hypervisor.addNodeToCheck(this.id)
scheduler.jsView
@@ -103,42 +103,40 @@
103103 }
104104
105105 // checks outstanding waits to see if they can be resolved
106106 _checkWaits () {
107- if (!this._loadingInstances.size) {
108- // if there are no running containers
109- if (!this.instances.size) {
110- // clear any remanding waits
111- this._waits.forEach(wait => wait.resolve())
112- this._waits = []
113- } else {
114- // find the old container and see if to can resolve any of the waits
115- const oldest = this.oldest()
116- for (const index in this._waits) {
117- const wait = this._waits[index]
118- if (wait.ticks <= oldest) {
119- wait.resolve()
120- this._running.add(wait.id)
107 + // if there are no running containers
108 + if (!this.instances.size) {
109 + // clear any remanding waits
110 + this._waits.forEach(wait => wait.resolve())
111 + this._waits = []
112 + } else {
113 + // find the old container and see if to can resolve any of the waits
114 + const oldest = this.oldest()
115 + for (const index in this._waits) {
116 + const wait = this._waits[index]
117 + if (wait.ticks <= oldest) {
118 + wait.resolve()
119 + this._running.add(wait.id)
120 + } else {
121 + this._waits.splice(0, index)
122 + break
123 + }
124 + }
125 + if (!this._running.size) {
126 + // if there are no containers running find the oldest wait and update
127 + // the oldest containers to it ticks
128 + const oldest = this._waits[0].ticks
129 + for (let instance of this.instances) {
130 + instance = instance[1]
131 + if (instance.ticks > oldest) {
132 + break
121133 } else {
122- this._waits.splice(0, index)
123- break
134 + instance.ticks = oldest
135 + this._update(instance)
124136 }
125137 }
126- if (!this._running.size) {
127- // if there are no containers running find the oldest wait and update
128- // the oldest containers to it ticks
129- const oldest = this._waits[0].ticks
130- for (let instance of this.instances) {
131- instance = instance[1]
132- if (instance.ticks > oldest) {
133- break
134- } else {
135- instance.ticks = oldest
136- this._update(instance)
137- }
138- }
139- return this._checkWaits()
140- }
138 + return this._checkWaits()
141139 }
142140 }
143141 }
144142 }
tests/index.jsView
@@ -116,10 +116,13 @@
116116 await this.kernel.createInstance(testVMContainer2.typeId, this.kernel.createMessage({
117117 ports: [portRef2]
118118 }))
119119 this.kernel.incrementTicks(2)
120- this.kernel.send(portRef1, m)
121- return this.kernel.ports.bind('child', portRef1)
120 +
121 + return Promise.all([
122 + this.kernel.send(portRef1, m),
123 + this.kernel.ports.bind('child', portRef1)
124 + ])
122125 }
123126 }
124127
125128 const hypervisor = new Hypervisor(node.dag)
@@ -136,9 +139,9 @@
136139 message = root.createMessage({
137140 data: 'test'
138141 })
139142
140- root.send(portRef1, message)
143 + await root.send(portRef1, message)
141144 const stateRoot = await hypervisor.createStateRoot(Infinity)
142145
143146 t.deepEquals(stateRoot, expectedState, 'expected state')
144147 // await hypervisor.graph.tree(stateRoot, Infinity, true)
@@ -175,9 +178,9 @@
175178 const [portRef1, portRef2] = this.kernel.ports.createChannel()
176179 await this.kernel.createInstance(testVMContainer2.typeId, this.kernel.createMessage({
177180 ports: [portRef2]
178181 }))
179- this.kernel.send(portRef1, m)
182 + await this.kernel.send(portRef1, m)
180183 this.kernel.incrementTicks(1)
181184 return this.kernel.ports.bind('child', portRef1)
182185 }
183186 }
@@ -195,9 +198,9 @@
195198
196199 await root.ports.bind('first', portRef1)
197200 message = root.createMessage()
198201
199- root.send(portRef1, message)
202 + await root.send(portRef1, message)
200203 const stateRoot = await hypervisor.createStateRoot(Infinity)
201204 t.true(hasResolved, 'should resolve before generating the state root')
202205
203206 // await hypervisor.graph.tree(stateRoot, Infinity, true)
@@ -286,11 +289,11 @@
286289
287290 await this.kernel.createInstance(First.typeId, message1)
288291 await this.kernel.createInstance(Second.typeId, message2)
289292
290- this.kernel.send(portRef1, this.kernel.createMessage())
291- this.kernel.send(portRef3, this.kernel.createMessage())
292293 return Promise.all(
294 + this.kernel.send(portRef1, this.kernel.createMessage()),
295 + this.kernel.send(portRef3, this.kernel.createMessage()),
293296 this.kernel.ports.bind('two', portRef3),
294297 this.kernel.ports.bind('one', portRef1)
295298 )
296299 } else if (runs === 1) {
@@ -304,9 +307,9 @@
304307
305308 class First extends BaseContainer {
306309 onMessage (m) {
307310 this.kernel.incrementTicks(2)
308- this.kernel.send(m.fromPort, this.kernel.createMessage({
311 + return this.kernel.send(m.fromPort, this.kernel.createMessage({
309312 data: 'first'
310313 }))
311314 }
312315
@@ -317,9 +320,9 @@
317320
318321 class Second extends BaseContainer {
319322 onMessage (m) {
320323 this.kernel.incrementTicks(3)
321- this.kernel.send(m.fromPort, this.kernel.createMessage({
324 + return this.kernel.send(m.fromPort, this.kernel.createMessage({
322325 data: 'second'
323326 }))
324327 }
325328
@@ -793,10 +796,12 @@
793796 })
794797 await this.kernel.createInstance(First.typeId, message1)
795798 return this.kernel.ports.bind('one', portRef1)
796799 } else {
797- this.kernel.send(one, this.kernel.createMessage())
798- this.kernel.send(one, this.kernel.createMessage())
800 + return Promise.all([
801 + this.kernel.send(one, this.kernel.createMessage()),
802 + this.kernel.send(one, this.kernel.createMessage())
803 + ])
799804 }
800805 }
801806 static get typeId () {
802807 return 299
@@ -827,11 +832,11 @@
827832 ports: [portRef2]
828833 }))
829834
830835 const message = root.createMessage()
831- root.send(portRef1, message)
836 + await root.send(portRef1, message)
832837 await hypervisor.createStateRoot()
833- root.send(portRef1, root.createMessage())
838 + await root.send(portRef1, root.createMessage())
834839 await hypervisor.createStateRoot()
835840 t.equals(runs, 2)
836841 } catch (e) {
837842 console.log(e)
@@ -890,18 +895,18 @@
890895 ports: [portRef2]
891896 })
892897
893898 await this.kernel.createInstance(First.typeId, message1)
894- this.kernel.send(portRef1, this.kernel.createMessage())
899 + await this.kernel.send(portRef1, this.kernel.createMessage())
895900 this.kernel.incrementTicks(6)
896901 return this.kernel.ports.bind('one', portRef1)
897902 }
898903 }
899904
900905 class First extends BaseContainer {
901906 onMessage (m) {
902907 this.kernel.incrementTicks(2)
903- this.kernel.ports.delete('root')
908 + return this.kernel.ports.delete('root')
904909 }
905910 static get typeId () {
906911 return 299
907912 }
@@ -919,9 +924,9 @@
919924 ports: [portRef2]
920925 }))
921926
922927 const message = root.createMessage()
923- root.send(portRef1, message)
928 + await root.send(portRef1, message)
924929
925930 const sr = await hypervisor.createStateRoot()
926931 t.deepEquals(sr, expectedSr, 'should produce the corret state root')
927932 await hypervisor.graph.tree(sr, Infinity, true)
@@ -949,9 +954,9 @@
949954 ports: [portRef2]
950955 }))
951956
952957 const message = root.createMessage()
953- root.send(portRef1, message)
958 + await root.send(portRef1, message)
954959 const sr = await hypervisor.createStateRoot()
955960 t.deepEquals(sr, expectedSr, 'should produce the corret state root')
956961
957962 t.end()
@@ -996,9 +1001,9 @@
9961001 await root.createInstance(Root.typeId, root.createMessage({
9971002 ports: [portRef2]
9981003 }))
9991004
1000- root.send(portRef1, root.createMessage())
1005 + await root.send(portRef1, root.createMessage())
10011006 const sr = await hypervisor.createStateRoot()
10021007
10031008 t.deepEquals(sr, expectedSr, 'should produce the corret state root')
10041009 t.end()
@@ -1014,9 +1019,9 @@
10141019 class Root extends BaseContainer {
10151020 async onMessage (m) {
10161021 if (m.ports.length) {
10171022 const port = this.kernel.ports.get('test1')
1018- this.kernel.send(port, m)
1023 + await this.kernel.send(port, m)
10191024 return this.kernel.ports.unbind('test1')
10201025 } else {
10211026 const [portRef1, portRef2] = this.kernel.ports.createChannel()
10221027 await this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({
@@ -1028,20 +1033,20 @@
10281033 await this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({
10291034 ports: [portRef4]
10301035 }))
10311036 await this.kernel.ports.bind('test2', portRef3)
1032- this.kernel.send(portRef3, this.kernel.createMessage({
1037 + await this.kernel.send(portRef3, this.kernel.createMessage({
10331038 data: 'getChannel'
10341039 }))
10351040 }
10361041 }
10371042 }
10381043
10391044 class Sub extends BaseContainer {
1040- onMessage (message) {
1045 + async onMessage (message) {
10411046 if (message.data === 'getChannel') {
10421047 const ports = this.kernel.ports.createChannel()
1043- this.kernel.send(message.fromPort, this.kernel.createMessage({
1048 + await this.kernel.send(message.fromPort, this.kernel.createMessage({
10441049 data: 'bindPort',
10451050 ports: [ports[1]]
10461051 }))
10471052 return this.kernel.ports.bind('channel', ports[0])
@@ -1065,9 +1070,9 @@
10651070 await root.createInstance(Root.typeId, root.createMessage({
10661071 ports: [portRef2]
10671072 }))
10681073
1069- root.send(portRef1, root.createMessage())
1074 + await root.send(portRef1, root.createMessage())
10701075 const sr = await hypervisor.createStateRoot()
10711076 t.deepEquals(sr, expectedSr, 'should produce the corret state root')
10721077 // await hypervisor.graph.tree(sr, Infinity)
10731078
@@ -1130,21 +1135,19 @@
11301135
11311136 const root = await hypervisor.createInstance(Root.typeId)
11321137
11331138 const [portRef1, portRef2] = root.ports.createChannel()
1134- await root.ports.bind('first', portRef1)
1135- await root.createInstance(Root.typeId, root.createMessage({
1136- ports: [portRef2]
1137- }))
1139 + await Promise.all([
1140 + root.ports.bind('first', portRef1),
1141 + root.createInstance(Root.typeId, root.createMessage({
1142 + ports: [portRef2]
1143 + })),
1144 + root.send(portRef1, root.createMessage())
1145 + ])
11381146
1139- root.send(portRef1, root.createMessage())
1140-
11411147 const sr = await hypervisor.createStateRoot()
11421148 t.deepEquals(sr, expectedSr, 'should produce the corret state root')
11431149
1144- // await hypervisor.graph.tree(sr, Infinity, true)
1145- // console.log(JSON.stringify(sr, null, 2))
1146-
11471150 t.end()
11481151 } catch (e) {
11491152 console.log(e)
11501153 }

Built with git-ssb-web