I agree, the parameter list for this procedure is on the edge, but still just acceptable. But defining a record type for just some config parameters is worth a thought, especially as I already factored out one parameter, assuming a default value (ptype := Essential), and providing an additional config procedure for changing it if required, which is only needed in a minority of cases.
Here's a comparison of the approaches:
Code: Select all
TYPE
ProcessID* = ARRAY 4 OF CHAR;
Ticks* = INTEGER;
Process* = POINTER TO ProcessDesc;
ProcessDesc* = RECORD
cor: Coroutines.Coroutine;
schedulerState: INTEGER;
next, nextR: Process;
period, ticker, delay: Ticks;
ptype: INTEGER;
resetCount: INTEGER;
id: ProcessID
END;
ProcessConfig* = RECORD
startAfter*, period*: Ticks;
ptype*: INTEGER;
id*: ProcessID
END;
PROCEDURE Init*(p: Process; proc: Coroutines.PROC; stack: ARRAY OF BYTE; startAfter, period: Ticks; pid: ARRAY OF CHAR);
BEGIN
ASSERT(LEN(pid) <= 4, Error.PreCond);
NEW(p.cor); Coroutines.Init(p.cor, proc, stack, pid);
p.period := period;
p.ticker := startAfter;
p.id := pid;
p.ptype := Essential;
p.schedulerState := Off;
p.resetCount := 0
END Init;
PROCEDURE Init2*(p: Process; proc: Coroutines.PROC; stack: ARRAY OF BYTE; cfg: ProcessConfig);
BEGIN
NEW(p.cor); Coroutines.Init(p.cor, proc, stack, cfg.id);
p.period := cfg.period;
p.ticker := cfg.startAfter;
p.ptype := cfg.ptype;
p.id := cfg.id;
p.schedulerState := Off;
p.resetCount := 0
END Init2;
Regarding the type of ProcessID: I have considered using integers, but right now, the ID is only used in diagnostic messages and logs, and identifying a process by a mnemonic is easier than a number. I even pass the ID to the corresponding Coroutine for dev purposes for now, which I will drop later. Each process of the application program is implemented in a separate module, and "naming" the process is done there, ie not "centrally". Keeping the char-typed IDs apart in this scheme is easier than using integers, such as "hb" for the heartbeat process, "dp" for the display process, and so on. The role and use of the process ID might evolve, though, at which point I'll need to reconsider. Which is why having "pid: ProcessID" would have been preferrable over "pid: ARRAY OF CHAR". Your suggestion of using a config-record would in fact also account for that aspect.