Skip to content

Commit 121a90f

Browse files
committed
Fix whitespace and missing semicolons in Scheduler
1 parent 7208ba4 commit 121a90f

File tree

1 file changed

+44
-42
lines changed

1 file changed

+44
-42
lines changed

rt/src/Scheduler.mts

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,20 @@ export class Scheduler implements SchedulerInterface {
7474
initScheduler(node, stopWhenAllThreadsAreDone, stopRuntime) {
7575
this.__node = node;
7676
this.__stopWhenAllThreadsAreDone = stopWhenAllThreadsAreDone;
77-
this.__stopRuntime = stopRuntime
77+
this.__stopRuntime = stopRuntime;
7878
}
7979

8080
/** Kill all current threads (without notifying any monitors), staying ready for spawning new
8181
* threads. */
8282
resetScheduler() {
8383
// console.log (`The current length of __funloop is ${this.__funloop.length}`)
8484
// console.log (`The number of active threads is ${Object.keys(this.__alive).length}`)
85-
for (let x in this.__alive) {
85+
for (let x in this.__alive) {
8686
if (this.__currentThread.tid.val.toString() == x) {
8787
// console.log (x, "ACTIVE")
8888
} else {
8989
// console.log (x, "KILLING");
90-
delete this.__alive[x]
90+
delete this.__alive[x];
9191
}
9292
}
9393
this.__blocked = [];
@@ -102,7 +102,7 @@ export class Scheduler implements SchedulerInterface {
102102

103103
/** Add a thread `t` to the active function loop. */
104104
scheduleThread(t: Thread) {
105-
this.__funloop.push(t)
105+
this.__funloop.push(t);
106106
}
107107

108108
/** Create a new thread `t` for the given function to be evaluated and schedule it. */
@@ -130,14 +130,14 @@ export class Scheduler implements SchedulerInterface {
130130

131131

132132
this.__alive[newPid.val.toString()] = t;
133-
this.scheduleThread (t)
133+
this.scheduleThread(t);
134134
return newPid;
135135
}
136136

137137
/** Schedule the given function as the very next thing to be run. */
138138
schedule(thefun, args, nm) {
139-
this.__currentThread.runNext (thefun, args, nm);
140-
this.scheduleThread(this.__currentThread)
139+
this.__currentThread.runNext(thefun, args, nm);
140+
this.scheduleThread(this.__currentThread);
141141
}
142142

143143
/*************************************************************************************************\
@@ -160,7 +160,7 @@ export class Scheduler implements SchedulerInterface {
160160

161161
/** Block thread object `t`. */
162162
blockThread(t: Thread) {
163-
this.__blocked.push(t)
163+
this.__blocked.push(t);
164164
}
165165

166166
/** Unblock the thread with the given identifier, `pid`. */
@@ -180,35 +180,37 @@ export class Scheduler implements SchedulerInterface {
180180

181181
/** Notify monitors about thread termination. */
182182
notifyMonitors (status = TerminationStatus.OK, errstr = null) {
183-
let mkVal = this.__currentThread.mkVal
184-
let ids = Object.keys (this.__currentThread.monitors);
185-
for ( let i = 0; i < ids.length; i ++ ) {
186-
let id = ids[i];
187-
let toPid = this.__currentThread.monitors[id].pid;
188-
let refUUID = this.__currentThread.monitors[id].uuid;
189-
let thisPid = this.__currentThread.tid;
190-
let statusVal = this.__currentThread.mkVal ( status ) ;
191-
let reason = TerminationStatus.OK == status ? statusVal :
192-
mkTuple ( [statusVal, mkVal (errstr)] );
193-
let message = mkVal (mkTuple ([ mkVal("DONE"), refUUID, thisPid, reason]))
194-
this.rtObj.sendMessageNoChecks ( toPid, message , false) // false flag means no need to return in the process
195-
}
183+
let mkVal = this.__currentThread.mkVal;
184+
let ids = Object.keys(this.__currentThread.monitors);
185+
for (let i = 0; i < ids.length; i++) {
186+
let id = ids[i];
187+
let toPid = this.__currentThread.monitors[id].pid;
188+
let refUUID = this.__currentThread.monitors[id].uuid;
189+
let thisPid = this.__currentThread.tid;
190+
let statusVal = this.__currentThread.mkVal( status );
191+
let reason = TerminationStatus.OK == status
192+
? statusVal
193+
: mkTuple ([statusVal, mkVal (errstr)]);
194+
let message = mkVal (mkTuple([ mkVal("DONE"), refUUID, thisPid, reason]));
195+
// false flag means no need to return in the process
196+
this.rtObj.sendMessageNoChecks( toPid, message, false);
197+
}
196198
}
197199

198200
/** Epilogue for `main` thread: notify monitors, print and persist the final value */
199201
haltMain (persist=null) {
200202
this.__currentThread.raiseCurrentThreadPCToBlockingLev()
201-
let retVal = new LVal (this.__currentThread.r0_val,
203+
let retVal = new LVal (this.__currentThread.r0_val,
202204
lub(this.__currentThread.bl, this.__currentThread.r0_lev),
203205
lub(this.__currentThread.bl, this.__currentThread.r0_tlev))
204206

205-
this.notifyMonitors ();
207+
this.notifyMonitors();
206208

207209
delete this.__alive[this.__currentThread.tid.val.toString()];
208210
console.log(">>> Main thread finished with value:", retVal.stringRep());
209211
if (persist) {
210-
this.rtObj.persist (retVal, persist )
211-
console.log ("Saved the result value in file", persist)
212+
this.rtObj.persist(retVal, persist )
213+
console.log("Saved the result value in file", persist)
212214
}
213215
return null;
214216
}
@@ -217,12 +219,12 @@ export class Scheduler implements SchedulerInterface {
217219
haltOther () {
218220
this.notifyMonitors();
219221
// console.log (this.__currentThread.processDebuggingName, this.__currentThread.tid.val.toString(), "done")
220-
delete this.__alive [this.__currentThread.tid.val.toString()];
222+
delete this.__alive[this.__currentThread.tid.val.toString()];
221223
}
222224

223225
/** Kill thread `t` with the error message `s` sent to its monitors. */
224226
stopThreadWithErrorMessage (t: Thread, s: string) {
225-
this.notifyMonitors(TerminationStatus.ERR, s) ;
227+
this.notifyMonitors(TerminationStatus.ERR, s);
226228
delete this.__alive [t.tid.val.toString()];
227229
}
228230

@@ -247,15 +249,15 @@ export class Scheduler implements SchedulerInterface {
247249
loop() {
248250
const $$LOOPBOUND = 500000;
249251
let _FUNLOOP = this.__funloop
250-
let _curThread: Thread;
251-
let dest;
252+
let _curThread: Thread;
253+
let dest;
252254
try {
253-
for (let $$loopiter = 0; $$loopiter < $$LOOPBOUND && _FUNLOOP.length > 0; $$loopiter ++ ) {
255+
for (let $$loopiter = 0; $$loopiter < $$LOOPBOUND && _FUNLOOP.length > 0; $$loopiter++) {
254256
_curThread = _FUNLOOP.shift();
255257
this.__currentThread = _curThread;
256-
dest = _curThread.next
258+
dest = _curThread.next;
257259
let ttl = 1000; // magic constant; 2021-04-29
258-
while (dest && ttl -- ) {
260+
while (dest && ttl--) {
259261
// 2021-04-24; AA; TODO: profile the addition of this conditional in this tight loop
260262
// if (showStack) {
261263
// this.__currentThread.showStack()
@@ -266,24 +268,24 @@ export class Scheduler implements SchedulerInterface {
266268
// if (dest.debugname ) {
267269
// console.log (" -- ", dest.debugname)
268270
// }
269-
dest = dest ()
271+
dest = dest();
270272
}
271273

272274
if (dest) {
273-
_curThread.handlerState.checkGuard()
275+
_curThread.handlerState.checkGuard();
274276

275-
_curThread.next = dest ;
276-
_FUNLOOP.push (_curThread);
277+
_curThread.next = dest;
278+
_FUNLOOP.push(_curThread);
277279
}
278-
}
280+
}
279281
} catch (e) {
280282
if (e instanceof TroupeError) {
281283
e.handleError(this);
282284
} else {
283-
console.log ("--- Schedule module caught an internal exception ---")
284-
console.log ("--- The following output may help identify a bug in the runtime ---")
285-
console.log ("Destination function\n" , dest)
286-
this.__currentThread.showStack()
285+
console.log("--- Schedule module caught an internal exception ---");
286+
console.log("--- The following output may help identify a bug in the runtime ---");
287+
console.log("Destination function\n", dest);
288+
this.__currentThread.showStack();
287289
throw e;
288290
}
289291
}
@@ -293,7 +295,7 @@ export class Scheduler implements SchedulerInterface {
293295
this.resumeLoopAsync();
294296
}
295297

296-
if (this.__stopWhenAllThreadsAreDone && Object.keys(this.__alive).length == 0 ) {
298+
if (this.__stopWhenAllThreadsAreDone && Object.keys(this.__alive).length == 0) {
297299
this.__stopRuntime();
298300
}
299301
}

0 commit comments

Comments
 (0)