git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 4cca53d29be42c593457a41e7d0d5df90fe7a1aa

fixed schedular

wanderer committed on 6/20/2017, 6:50:19 PM
Parent: 6b20ce6345f5cf4e554a3d7b67876db977eb8070

Files changed

portManager.jschanged
scheduler.jschanged
tests/index.jschanged
portManager.jsView
@@ -84,9 +84,9 @@
8484 return port
8585 }
8686
8787 delete (name) {
88-
88+ delete this.ports[name]
8989 }
9090
9191 _deleteDestPort (port) {
9292 this.exInterface.send(port, 'delete')
scheduler.jsView
@@ -44,9 +44,9 @@
4444 this._checkWaits()
4545 }
4646
4747 wait (ticks, id) {
48- if (!this.locks.size && (ticks <= this.smallest() || !this.isRunning())) {
48+ if (!this.locks.size && ticks <= this.smallest()) {
4949 return
5050 } else {
5151 return new Promise((resolve, reject) => {
5252 binarySearchInsert(this._waits, comparator, {
@@ -58,10 +58,9 @@
5858 }
5959 }
6060
6161 smallest () {
62- const smallest = [...this.instances][0]
63- return smallest ? smallest[1].ticks : 0
62+ return [...this.instances][0][1].ticks
6463 }
6564
6665 _checkWaits () {
6766 if (!this.locks.size) {
tests/index.jsView
@@ -108,46 +108,8 @@
108108 port = root.ports.get('first')
109109 root.send(port, message)
110110 })
111111
112- tape.skip('ping pong', async t => {
113- class Ping extends BaseContainer {
114- async run (m) {
115- let port = this.exInterface.ports.get('child')
116- if (!port) {
117- port = this.exInterface.ports.create('pong')
118- this.exInterface.ports.bind(port, 'child')
119- }
120-
121- if (this.exInterface.ticks < 100) {
122- this.exInterface.incrementTicks(1)
123- return this.exInterface.send(port, this.exInterface.createMessage())
124- }
125- }
126- }
127-
128- class Pong extends BaseContainer {
129- run (m) {
130- const port = m.fromPort
131- this.exInterface.incrementTicks(2)
132- return this.exInterface.send(port, this.exInterface.createMessage())
133- }
134- }
135-
136- const hypervisor = new Hypervisor(node.dag)
137-
138- hypervisor.registerContainer('ping', Ping)
139- hypervisor.registerContainer('pong', Pong)
140- const root = await hypervisor.createInstance('pong')
141- const port = root.ports.create('ping')
142- root.ports.bind(port, 'child')
143-
144- await root.send(port, root.createMessage())
145- await hypervisor.createStateRoot(root, Infinity)
146-
147- t.end()
148- })
149-
150112 tape('traps', async t => {
151113 t.plan(1)
152114 class Root extends BaseContainer {
153115 async run (m) {
@@ -374,11 +336,8 @@
374336 class First extends BaseContainer {
375337 run (m) {
376338 this.exInterface.incrementTicks(2)
377339 return this.exInterface.send(m.fromPort, this.exInterface.createMessage({
378- resources: {
379- priority: 100
380- },
381340 data: 'first'
382341 }))
383342 }
384343 }
@@ -437,5 +396,35 @@
437396 await root.ports.unbind('test')
438397 const message = root.createMessage({ports: [port]})
439398 t.equals(message.ports[0], port, 'should create a message if the port is unbound')
440399 })
400+
401+ tape.only('port deletion', async t => {
402+ t.plan(2)
403+
404+ class Root extends BaseContainer {
405+ run (m) {
406+ const one = this.exInterface.ports.create('first')
407+ this.exInterface.ports.bind('one', one)
408+ this.exInterface.send(one, this.exInterface.createMessage())
409+ this.exInterface.incrementTicks(6)
410+ }
411+ }
412+
413+ class First extends BaseContainer {
414+ run (m) {
415+ this.exInterface.incrementTicks(2)
416+ this.exInterface.ports.delete('root')
417+ }
418+ }
419+
420+ const hypervisor = new Hypervisor(node.dag)
421+
422+ hypervisor.registerContainer('root', Root)
423+ hypervisor.registerContainer('first', First)
424+
425+ const root = await hypervisor.createInstance('root')
426+ const port = root.ports.create('root')
427+ root.ports.bind('first', port)
428+ root.send(port, root.createMessage())
429+ })
441430 })

Built with git-ssb-web