rename contexts -> threads and spawn -> create

This ensures we're more consistent in naming for these constructs.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2020-07-16 10:17:46 +08:00
parent ba7bb29ce2
commit 1216963d24
4 changed files with 50 additions and 26 deletions

View file

@ -239,7 +239,7 @@ pub fn handle(pid: PID, call: SysCall) -> core::result::Result<xous::Result, xou
.map(|_| Ok(xous::Result::ResumeProcess))
.unwrap_or(Err(xous::Error::ProcessNotFound))
}),
SysCall::SpawnThread(entrypoint, stack_pointer, argument) => {
SysCall::CreateThread(entrypoint, stack_pointer, argument) => {
SystemServices::with_mut(|ss| {
ss.spawn_thread(entrypoint, stack_pointer, argument)
.map(xous::Result::ThreadID)

View file

@ -207,7 +207,7 @@ fn send_borrow_message() {
// let s = String::from_utf8_lossy(&bt);
// println!("SERVER: Got message: {:?} -> \"{}\"", bt, s);
xous::return_memory(envelope.sender, m.buf).unwrap();
// println!("SERVER: Returned memory");
// println!("SERVER: Returned memory");
} else {
panic!("unexpected message type");
}
@ -378,7 +378,8 @@ fn measure_memory_usage() {
// Run the "shutdown" test in its own thread. This ensures that
// any TLS is freed when the thread exits.
let jh = as_process(|| shutdown());
jh.join().expect("couldn't run shutdown test for measuring memory");
jh.join()
.expect("couldn't run shutdown test for measuring memory");
}
fn memory_in_use(start: &Stats) -> usize {
@ -395,16 +396,39 @@ fn measure_memory_usage() {
println!("After test: {:#?} ({} bytes in use)", after_join, miu);
}
// #[test]
// fn multiple_contexts() {
// // Start the kernel in its own thread
// let (main_thread, server_spec) = start_kernel(SERVER_SPEC);
#[test]
fn multiple_contexts() {
// Start the kernel in its own thread
let main_thread = start_kernel(SERVER_SPEC);
// let (server_addr_send, server_addr_recv) = channel();
// xous::create_server(name)
let internal_server = as_process(|| {
let server = xous::create_server(0x53_4534).expect("couldn't create server");
let connection = xous::connect(server).expect("couldn't connect to our own server");
// // Any process ought to be able to shut down the system currently.
// rsyscall(SysCall::Shutdown).expect("unable to shutdown server");
xous::send_message(
connection,
xous::Message::Scalar(xous::ScalarMessage {
id: 1,
arg1: 2,
arg2: 3,
arg3: 4,
arg4: 5,
}),
).expect("couldn't send message");
// main_thread.join().expect("couldn't join kernel process");
// }
let msg = xous::receive_message(server).expect("couldn't receive message");
println!("Received message: {:?}", msg);
// let client_thread = xous::create_thread(move || {
// })
});
internal_server
.join()
.expect("couldn't join internal_server process");
// Any process ought to be able to shut down the system currently.
rsyscall(SysCall::Shutdown).expect("unable to shutdown server");
main_thread.join().expect("couldn't join kernel process");
}

View file

@ -355,7 +355,7 @@ pub enum Result {
Error(Error),
MemoryAddress(MemoryAddress),
MemoryRange(MemoryRange),
ReadyContexts(
ReadyThreads(
usize, /* count */
usize,
/* pid0 */ usize, /* context0 */
@ -386,7 +386,7 @@ impl Result {
Result::Error(e) => [1, e.to_usize(), 0, 0, 0, 0, 0, 0],
Result::MemoryAddress(s) => [2, s.get(), 0, 0, 0, 0, 0, 0],
Result::MemoryRange(r) => [3, r.addr.get(), r.size.get(), 0, 0, 0, 0, 0],
Result::ReadyContexts(count, pid0, ctx0, pid1, ctx1, pid2, ctx2) => {
Result::ReadyThreads(count, pid0, ctx0, pid1, ctx1, pid2, ctx2) => {
[4, *count, *pid0, *ctx0, *pid1, *ctx1, *pid2, *ctx2]
}
Result::ResumeProcess => [5, 0, 0, 0, 0, 0, 0, 0],
@ -426,7 +426,7 @@ impl Result {
Result::MemoryRange(MemoryRange { addr, size })
}
4 => Result::ReadyContexts(src[1], src[2], src[3], src[4], src[5], src[6], src[7]),
4 => Result::ReadyThreads(src[1], src[2], src[3], src[4], src[5], src[6], src[7]),
5 => Result::ResumeProcess,
6 => Result::ServerID((src[1], src[2], src[3], src[4])),
7 => Result::ConnectionID(src[1] as CID),

View file

@ -203,7 +203,7 @@ pub enum SysCall {
SwitchTo(PID, usize /* context ID */),
/// Get a list of contexts that can be run in the given PID.
ReadyContexts(PID),
ReadyThreads(PID),
/// Create a new Server
///
@ -239,7 +239,7 @@ pub enum SysCall {
ReturnMemory(MessageSender, MemoryRange),
/// Spawn a new thread
SpawnThread(
CreateThread(
MemoryAddress, /* entrypoint */
MemoryAddress, /* stack pointer */
Option<MemoryAddress>, /* argument */
@ -268,7 +268,7 @@ enum SysCallNumber {
ClaimInterrupt = 5,
FreeInterrupt = 6,
SwitchTo = 7,
ReadyContexts = 8,
ReadyThreads = 8,
WaitEvent = 9,
IncreaseHeap = 10,
DecreaseHeap = 11,
@ -278,7 +278,7 @@ enum SysCallNumber {
ReceiveMessage = 15,
SendMessage = 16,
Connect = 17,
SpawnThread = 18,
CreateThread = 18,
UnmapMemory = 19,
ReturnMemory = 20,
CreateProcess = 21,
@ -362,8 +362,8 @@ impl SysCall {
0,
0,
],
SysCall::ReadyContexts(a1) => [
SysCallNumber::ReadyContexts as usize,
SysCall::ReadyThreads(a1) => [
SysCallNumber::ReadyThreads as usize,
a1.get() as usize,
0,
0,
@ -478,8 +478,8 @@ impl SysCall {
0,
0,
],
SysCall::SpawnThread(a1, a2, a3) => [
SysCallNumber::SpawnThread as usize,
SysCall::CreateThread(a1, a2, a3) => [
SysCallNumber::CreateThread as usize,
a1.get(),
a2.get(),
a3.map(|x| x.get()).unwrap_or_default(),
@ -548,7 +548,7 @@ impl SysCall {
),
Some(SysCallNumber::FreeInterrupt) => SysCall::FreeInterrupt(a1),
Some(SysCallNumber::SwitchTo) => SysCall::SwitchTo(pid_from_usize(a1)?, a2 as usize),
Some(SysCallNumber::ReadyContexts) => SysCall::ReadyContexts(pid_from_usize(a1)?),
Some(SysCallNumber::ReadyThreads) => SysCall::ReadyThreads(pid_from_usize(a1)?),
Some(SysCallNumber::IncreaseHeap) => SysCall::IncreaseHeap(
a1 as usize,
MemoryFlags::from_bits(a2).ok_or(Error::InvalidSyscall)?,
@ -610,7 +610,7 @@ impl SysCall {
Some(SysCallNumber::ReturnMemory) => {
SysCall::ReturnMemory(a1, MemoryRange::new(a2, a3))
}
Some(SysCallNumber::SpawnThread) => SysCall::SpawnThread(
Some(SysCallNumber::CreateThread) => SysCall::CreateThread(
MemoryAddress::new(a1).ok_or(Error::InvalidSyscall)?,
MemoryAddress::new(a2).ok_or(Error::InvalidSyscall)?,
MemoryAddress::new(a3),