Skip to content

Commit 7720a2e

Browse files
committed
Stop exposing/using internal (private) variable within Scheduler
1 parent d59aa72 commit 7720a2e

File tree

9 files changed

+24
-13
lines changed

9 files changed

+24
-13
lines changed

rt/src/Asserts.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { TroupeAggregateRawValue, TroupeRawValue } from './TroupeRawValue.mjs';
1616
// import { LVal } from './Lval';
1717

1818
function _thread() {
19-
return getRuntimeObject().__sched.__currentThread
19+
return getRuntimeObject().__sched.getCurrentThread()
2020
}
2121

2222
function __stringRep (v) {

rt/src/MailboxProcessor.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class MailboxProcessor implements MailboxInterface {
105105

106106

107107
peek(lev: Level, index: number, lowb: Level, highb: Level) {
108-
let theThread = this.sched.__currentThread
108+
let theThread = this.sched.getCurrentThread()
109109
let mb = theThread.mailbox;
110110
debug (`peek index: ${index}`)
111111
debug (`peek interval: [${lowb.stringRep()}, ${highb.stringRep()}]`)
@@ -138,7 +138,7 @@ export class MailboxProcessor implements MailboxInterface {
138138
}
139139

140140
consume(lev: Level, index: number, lowb: Level, highb: Level) {
141-
let theThread = this.sched.__currentThread
141+
let theThread = this.sched.getCurrentThread()
142142
let mb = theThread.mailbox;
143143
debug (`consume index: ${index}`)
144144
debug (`consume interval: [${lowb.stringRep()} to ${highb.stringRep()}]`)

rt/src/Scheduler.mts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,18 @@ export class Scheduler implements SchedulerInterface {
158158
return this.__alive[tid.val.toString()];
159159
}
160160

161+
/** The currently scheduled thread */
162+
getCurrentThread() {
163+
return this.__currentThread;
164+
}
165+
166+
/** Overwrites the current thread; the previously current thread is returned. */
167+
setCurrentThread(t: Thread) {
168+
const prev = this.__currentThread
169+
this.__currentThread = t;
170+
return prev;
171+
}
172+
161173
/*************************************************************************************************\
162174
Thread blocking/unblocking
163175
\*************************************************************************************************/

rt/src/SchedulerInterface.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { LVal } from './Lval.mjs'
33
import { Level } from "./Level.mjs";
44

55
export interface SchedulerInterface {
6-
__currentThread: Thread;
7-
86
resetScheduler(): void;
97

108
scheduleNewThread(fun: () => any, arg: any, pc: Level, block: Level): LVal;
@@ -15,6 +13,8 @@ export interface SchedulerInterface {
1513

1614
isAlive(tid: LVal): boolean;
1715
getThread(tid: LVal): Thread;
16+
getCurrentThread(): Thread;
17+
setCurrentThread(t: Thread): Thread;
1818

1919
stopThreadWithErrorMessage (t: Thread, errMsg: string): void
2020

rt/src/builtins/UserRuntimeZero.mts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,21 +259,20 @@ export class UserRuntimeZero {
259259

260260

261261
libLoadingPseudoThread = new Thread(null, null, null, __unit, levels.BOT, levels.BOT, null, this, null);
262-
savedThread = null ;// this.runtime.__sched.__currentThread;
262+
savedThread = null ;// this.runtime.__sched.getCurrentThread();
263263
setLibloadMode() {
264264
this.mkVal = (x) => new LVal(x, levels.BOT);
265265
this.mkValPos = (x, pos) => new LVal(x, levels.BOT, levels.BOT, pos);
266266
this.Env = LibEnv;
267-
this.savedThread = this.runtime.__sched.__currentThread;
268-
this.runtime.__sched.__currentThread = this.libLoadingPseudoThread;
267+
this.savedThread = this.runtime.__sched.setCurrentThread(this.libLoadingPseudoThread);
269268
}
270269

271270

272271
setNormalMode() {
273272
this.mkVal = this.default_mkVal;
274273
this.mkValPos = this.default_mkValPos
275274
this.Env = RtEnv;
276-
this.runtime.__sched.__currentThread = this.savedThread;
275+
this.runtime.__sched.setCurrentThread(this.savedThread);
277276
}
278277

279278
// tailcall(lff, arg) {

rt/src/builtins/monitor.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function BuiltinMonitors <TBase extends Constructor<UserRuntimeZero>> (Ba
1919

2020
let r = this.runtime.rt_mkuuid();
2121
if (t) {
22-
t.addMonitor(this.runtime.__sched.__currentThread.tid, r);
22+
t.addMonitor(this.runtime.__sched.getCurrentThread().tid, r);
2323
}
2424

2525
return this.runtime.ret(r);

rt/src/builtins/receive.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export function BuiltinReceive<TBase extends Constructor<UserRuntimeZero>>(Base:
133133

134134
_blockThread = mkBase ((arg) => {
135135
assertIsUnit(arg)
136-
this.runtime.__sched.blockThread(this.runtime.__sched.__currentThread);
136+
this.runtime.__sched.blockThread(this.runtime.__sched.getCurrentThread());
137137
return null;
138138
})
139139

rt/src/builtins/self.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { UserRuntimeZero, Constructor, mkBase } from './UserRuntimeZero.mjs'
88
export function BuiltinSelf<TBase extends Constructor<UserRuntimeZero>>(Base: TBase) {
99
return class extends Base {
1010
self = mkBase((arg) => {
11-
return this.runtime.ret(this.runtime.__sched.__currentThread.tid);
11+
return this.runtime.ret(this.runtime.__sched.getCurrentThread().tid);
1212
}, "self");
1313
}
1414
}

rt/src/runtimeMonitored.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const rt_xconsole =
4848
});
4949

5050
/** Returns the current thread */
51-
function $t():Thread { return __sched.__currentThread };
51+
function $t():Thread { return __sched.getCurrentThread() };
5252

5353
// --------------------------------------------------
5454

0 commit comments

Comments
 (0)