git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit ca90e13f859d9f1babea0d5f690290cf73a06138

fixed names in inbox.js

Signed-off-by: wanderer <mjbecze@gmail.com>
wanderer committed on 11/19/2017, 1:34:55 AM
Parent: 26c361018ce2740027699d601b339a3001fea89b

Files changed

actor.jschanged
inbox.jschanged
index.jschanged
scheduler.jschanged
tests/index.jschanged
actor.jsView
@@ -55,9 +55,8 @@
5555 // waits for the next message
5656 async _startMessageLoop () {
5757 // this ensure we only every have one loop running at a time
5858 if (this.containerState !== 'running') {
59- this.hypervisor.scheduler.update(this)
6059 this.containerState = 'running'
6160 while (1) {
6261 const message = await this.inbox.getNextMessage()
6362 if (!message) break
@@ -98,8 +97,9 @@
9897 let result
9998 try {
10099 result = await this.container[method](message)
101100 } catch (e) {
101+ console.log(e)
102102 result = {
103103 exception: true,
104104 exceptionError: e
105105 }
inbox.jsView
@@ -41,12 +41,12 @@
4141 throw new Error('already getting next message')
4242 }
4343
4444 this._waitingTags = new Set(tags)
45- this._queue.forEach(message => this._queueWaitingTags(message))
45+ this._queue.forEach(message => this._queueMessage(message))
4646
4747 const message = await this.getNextMessage(timeout)
48- // console.log('***', message)
48+ this._waitingTagsQueue.forEach(message => this._queueMessage(message))
4949
5050 delete this._waitingTags
5151 return message
5252 }
@@ -67,9 +67,8 @@
6767 while (true) {
6868 if (message && message._fromTicks < timeout) {
6969 timeout = message._fromTicks
7070 }
71- // console.log(timeout, oldestTime)
7271
7372 if (oldestTime >= timeout) {
7473 break
7574 }
@@ -109,20 +108,13 @@
109108 }
110109 }
111110
112111 _queueMessage (message) {
113- if (this._waitingTags) {
114- this._queueWaitingTags(message)
115- }
116- binarySearchInsert(this._queue, messageArbiter, message)
117- }
118-
119- _queueWaitingTags (message) {
120- if (this._waitingTags.has(message.tag)) {
121- this._waitingAddresses.delete(message.tag)
112+ if (this._waitingTags && this._waitingTags.has(message.tag)) {
113+ this._waitingTags.delete(message.tag)
122114 binarySearchInsert(this._waitingTagsQueue, messageArbiter, message)
123- // keep the taged waiting quueue pruned
124- this._waitingTagsQueue = [this._waitingTagsQueue[0]]
115+ } else {
116+ binarySearchInsert(this._queue, messageArbiter, message)
125117 }
126118 }
127119 }
128120
index.jsView
@@ -18,9 +18,9 @@
1818 async send (cap, message) {
1919 cap = await Promise.resolve(cap)
2020 const id = cap.destId
2121 const instance = await this.getInstance(id)
22- return instance.queue(message)
22+ instance.queue(message)
2323 }
2424
2525 // loads an instance of a container from the state
2626 async _loadInstance (id) {
scheduler.jsView
@@ -103,40 +103,42 @@
103103
104104 // checks outstanding waits to see if they can be resolved
105105 _checkWaits () {
106106 // if there are no running containers
107- if (!this.instances.size) {
108- // clear any remanding waits
109- this._waits.forEach(wait => wait.resolve())
110- this._waits = []
111- } else {
112- // find the old container and see if to can resolve any of the waits
113- while (this._waits[0]) {
114- const wait = this._waits[0]
115- const least = this.leastNumberOfTicks(wait.id)
116- if (wait.ticks <= least) {
117- this._waits.shift()
118- wait.resolve()
119- this._running.add(wait.id)
120- } else {
121- break
107+ if (!this._loadingInstances.size) {
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+ while (this._waits[0]) {
115+ const wait = this._waits[0]
116+ const least = this.leastNumberOfTicks(wait.id)
117+ if (wait.ticks <= least) {
118+ this._waits.shift()
119+ wait.resolve()
120+ this._running.add(wait.id)
121+ } else {
122+ break
123+ }
122124 }
123- }
124125
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
133- } else {
134- instance.ticks = oldest
135- this._update(instance)
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+ }
136138 }
139+ return this._checkWaits()
137140 }
138- return this._checkWaits()
139141 }
140142 }
141143 }
142144 }
tests/index.jsView
@@ -478,13 +478,12 @@
478478 t.deepEquals(stateRoot, expectedState, 'expected root!')
479479 t.equals(hypervisor.scheduler.leastNumberOfTicks(), 0)
480480 })
481481
482-tape.skip('basic tagged caps', async t => {
483- t.plan(4)
484- let message
482+tape('basic tagged caps', async t => {
483+ t.plan(5)
485484 const expectedState = {
486- '/': Buffer.from('fc935489953ed357f06171dd23439d83190b3a1b', 'hex')
485+ '/': Buffer.from('ef403643f292108fe9edc1700d80a7bf2402e7a0', 'hex')
487486 }
488487
489488 const tree = new RadixTree({
490489 db: db
@@ -495,18 +494,16 @@
495494 t.true(m, 'should recive first message')
496495 const rCap = this.kernel.mintCap(1)
497496 const message = new Message()
498497 message.responseCap = rCap
499- console.log('here')
500- this.kernel.send(m.caps[0], message)
498+ await this.kernel.send(m.caps[0], message)
501499 const rMessage = await this.kernel.inbox.waitOnTag([1], 44)
502500 t.true(rMessage, 'should recive a response message')
503501 }
504502 }
505503
506504 class testVMContainerB extends BaseContainer {
507505 onMessage (m) {
508- console.log('&&&&&&&&&&&&&&&&&&&&&&&&&&')
509506 t.true(m, 'should recive a message')
510507 }
511508
512509 static get typeId () {

Built with git-ssb-web