git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit f25a4c630940b064038e561bbafd852d929317c8

implemented main loop

wanderer committed on 7/6/2017, 2:24:04 AM
Parent: 016c6df49758e5db4d0f3caaf955ad714e137afc

Files changed

kernel.jschanged
kernel.jsView
@@ -34,37 +34,37 @@
3434 * @param {object} message
3535 */
3636 queue (portName, message) {
3737 this.ports.queue(portName, message)
38- if (this.containerState !== 'running') {
39- this.containerState = 'running'
40- return this._runNextMessage()
41- }
38+ return this._startMessageLoop()
4239 }
4340
44- initialize (message) {
45- this.containerState = 'running'
46- return this.run(message, 'initialize')
41+ async initialize (message) {
42+ await this.run(message, 'initialize')
43+ return this._startMessageLoop()
4744 }
4845
4946 // waits for the next message
50- async _runNextMessage () {
51- // check if the ports are saturated, if so we don't have to wait on the
52- // scheduler
53- const message = await this.ports.getNextMessage()
47+ async _startMessageLoop () {
48+ // this ensure we only every have one loop running at a time
49+ if (this.containerState !== 'running') {
50+ this.containerState = 'running'
5451
55- if (message) {
56- message.fromPort.messages.shift()
57- // if the message we recived had more ticks then we currently have the
58- // update it
59- if (message._fromTicks > this.ticks) {
60- this.ticks = message._fromTicks
61- this.hypervisor.scheduler.update(this)
52+ while (1) {
53+ let message = await this.ports.getNextMessage()
54+ if (!message) break
55+
56+ message.fromPort.messages.shift()
57+ // if the message we recived had more ticks then we currently have the
58+ // update it
59+ if (message._fromTicks > this.ticks) {
60+ this.ticks = message._fromTicks
61+ this.hypervisor.scheduler.update(this)
62+ }
63+ // run the next message
64+ await this.run(message)
6265 }
63- // run the next message
64- return this.run(message)
65- } else {
66- // if no more messages then shut down
66+ // no more messages; shut down
6767 this.hypervisor.scheduler.done(this.id)
6868 }
6969 }
7070
@@ -99,13 +99,11 @@
9999 if (responsePort) {
100100 this.send(responsePort, new Message({
101101 data: result
102102 }))
103- this.ports._unboundPorts.add(responsePort)
104103 }
105104
106105 this.ports.clearUnboundedPorts()
107- return this._runNextMessage()
108106 }
109107
110108 getResponsePort (message) {
111109 if (message.responsePort) {

Built with git-ssb-web