Hi all,
The Tock 2.0 TRD specifies
2 types of Exit syscall: exit-terminate and exit-restart. Both variants take a single argument, a completion code to pass to the kernel. I'd like input on how to structure the Exit API in libtock-rs.
Idea 1: Single function
We can implement Exit as a single function that takes an ExitType argument:
enum ExitType { Terminate = 0, Restart = 1 }
fn exit(exit_type: ExitType, completion_code: u32) -> !;
Idea 2: Separate functions
Because these are considered different types of Exit syscall, the API that most directly represents the TRD uses two methods:
fn exit_terminate(completion_code: u32) -> !;
fn exit_restart(completion_code: u32) -> !;
Comparison
The advantage of having a single function for both Exit calls is that methods that might call Exit can have an ExitType argument:
fn might_exit(exit_type: ExitType) {
let should_exit = /* stuff */;
if should_exit {
TockSyscalls::exit(exit_type, 0);
}
}
whereas with two functions
might_exit() would have to conditionally invoke the correct function. However, I don't expect this to be particularly useful.
The disadvantage of having a single function is it will be awkward to extend if a new Exit call is added. In particular, if an Exit call with a different signature is added, then we either have to overhaul the API (breaking backwards compatibility) or we end up with a weird API:
fn exit(exit_type: ExitType, completion_code: u32) -> !;
fn exit_fallible(code: u32) -> ErrorCode; // New Exit call
Idea 2 should easily extend to support new Exit calls. It is also more consistent with Yield and Memop, which uses separate functions for each invocation type.
Question
Do you have a preference for one design over the other?
Thanks for any help,
Johnathan