kernel: more renaming context -> thread

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2020-07-21 10:01:57 +08:00
parent 16d88d8cb5
commit e1bf9965c3
3 changed files with 23 additions and 23 deletions

View file

@ -147,7 +147,7 @@ pub struct Server {
/// The `context mask` is a bitfield of contexts that are able to handle /// The `context mask` is a bitfield of contexts that are able to handle
/// this message. If there are no available contexts, then messages will /// this message. If there are no available contexts, then messages will
/// need to be queued. /// need to be queued.
ready_contexts: usize, ready_threads: usize,
} }
/// Convert a PID and CTX pair into a `usize` sender /// Convert a PID and CTX pair into a `usize` sender
@ -191,7 +191,7 @@ impl Server {
queue_head: 0, queue_head: 0,
queue_tail: 0, queue_tail: 0,
queue, queue,
ready_contexts: 0, ready_threads: 0,
}); });
Ok(()) Ok(())
} }
@ -605,8 +605,8 @@ impl Server {
/// Return a context ID that is available and blocking. If no such context /// Return a context ID that is available and blocking. If no such context
/// ID exists, or if this server isn't actually ready to receive packets, /// ID exists, or if this server isn't actually ready to receive packets,
/// return None. /// return None.
pub fn take_available_context(&mut self) -> Option<TID> { pub fn take_available_thread(&mut self) -> Option<TID> {
if self.ready_contexts == 0 { if self.ready_threads == 0 {
return None; return None;
} }
let mut test_ctx_mask = 1; let mut test_ctx_mask = 1;
@ -615,8 +615,8 @@ impl Server {
loop { loop {
// If the context mask matches this context number, remove it // If the context mask matches this context number, remove it
// and return the index. // and return the index.
if self.ready_contexts & test_ctx_mask == test_ctx_mask { if self.ready_threads & test_ctx_mask == test_ctx_mask {
self.ready_contexts &= !test_ctx_mask; self.ready_threads &= !test_ctx_mask;
return Some(ctx_number); return Some(ctx_number);
} }
// Advance to the next slot. // Advance to the next slot.
@ -635,19 +635,19 @@ impl Server {
/// # Panics /// # Panics
/// ///
/// If the context cannot be returned because it is already blocking. /// If the context cannot be returned because it is already blocking.
pub fn return_available_context(&mut self, ctx_number: TID) { pub fn return_available_thread(&mut self, tid: TID) {
if self.ready_contexts & 1 << ctx_number != 0 { if self.ready_threads & 1 << tid != 0 {
panic!( panic!(
"tried to return context {}, but it was already blocking", "tried to return context {}, but it was already blocking",
ctx_number tid
); );
} }
self.ready_contexts |= 1 << ctx_number; self.ready_threads |= 1 << tid;
} }
/// Add the given context to the list of ready and waiting contexts. /// Add the given context to the list of ready and waiting contexts.
pub fn park_context(&mut self, context: TID) { pub fn park_thread(&mut self, tid: TID) {
// println!("KERNEL({}): Parking context: {}", self.pid, context); // println!("KERNEL({}): Parking context: {}", self.pid, context);
self.ready_contexts |= 1 << context; self.ready_threads |= 1 << tid;
} }
} }

View file

@ -706,7 +706,7 @@ impl SystemServices {
/// Resume the given process, picking up exactly where it left off. If the /// Resume the given process, picking up exactly where it left off. If the
/// process is in the Setup state, set it up and then resume. /// process is in the Setup state, set it up and then resume.
pub fn activate_process_context( pub fn activate_process_thread(
&mut self, &mut self,
new_pid: PID, new_pid: PID,
mut new_context: TID, mut new_context: TID,

View file

@ -102,7 +102,7 @@ fn send_message(pid: PID, thread: TID, cid: CID, message: Message) -> SysCallRes
if let Some(ctx_number) = ss if let Some(ctx_number) = ss
.server_from_sidx(sidx) .server_from_sidx(sidx)
.expect("server couldn't be located") .expect("server couldn't be located")
.take_available_context() .take_available_thread()
{ {
// println!( // println!(
// "There are contexts available to handle this message. Marking PID {} as Ready", // "There are contexts available to handle this message. Marking PID {} as Ready",
@ -115,7 +115,7 @@ fn send_message(pid: PID, thread: TID, cid: CID, message: Message) -> SysCallRes
.or_else(|e| { .or_else(|e| {
ss.server_from_sidx(sidx) ss.server_from_sidx(sidx)
.expect("server couldn't be located") .expect("server couldn't be located")
.return_available_context(thread); .return_available_thread(thread);
Err(e) Err(e)
})?, })?,
}; };
@ -126,13 +126,13 @@ fn send_message(pid: PID, thread: TID, cid: CID, message: Message) -> SysCallRes
ss.ready_context(server_pid, ctx_number).or_else(|e| { ss.ready_context(server_pid, ctx_number).or_else(|e| {
ss.server_from_sidx(sidx) ss.server_from_sidx(sidx)
.expect("server couldn't be located") .expect("server couldn't be located")
.return_available_context(thread); .return_available_thread(thread);
Err(e) Err(e)
})?; })?;
if blocking && cfg!(baremetal) { if blocking && cfg!(baremetal) {
// println!("Activating Server context and switching away from Client"); // println!("Activating Server context and switching away from Client");
ss.activate_process_context(server_pid, ctx_number, !blocking, blocking) ss.activate_process_thread(server_pid, ctx_number, !blocking, blocking)
.map(|_| Ok(xous::Result::Message(envelope))) .map(|_| Ok(xous::Result::Message(envelope)))
.unwrap_or(Err(xous::Error::ProcessNotFound)) .unwrap_or(Err(xous::Error::ProcessNotFound))
} else if blocking && !cfg!(baremetal) { } else if blocking && !cfg!(baremetal) {
@ -169,7 +169,7 @@ fn send_message(pid: PID, thread: TID, cid: CID, message: Message) -> SysCallRes
let process = ss.get_process(pid).expect("Can't get current process"); let process = ss.get_process(pid).expect("Can't get current process");
let ppid = process.ppid; let ppid = process.ppid;
unsafe { SWITCHTO_CALLER = None }; unsafe { SWITCHTO_CALLER = None };
ss.activate_process_context(ppid, 0, !blocking, blocking) ss.activate_process_thread(ppid, 0, !blocking, blocking)
.map(|_| Ok(xous::Result::ResumeProcess)) .map(|_| Ok(xous::Result::ResumeProcess))
.unwrap_or(Err(xous::Error::ProcessNotFound)) .unwrap_or(Err(xous::Error::ProcessNotFound))
} }
@ -209,13 +209,13 @@ fn receive_message(pid: PID, tid: TID, sid: SID) -> SysCallResult {
// "KERNEL({}): did not have any waiting messages -- parking context {}", // "KERNEL({}): did not have any waiting messages -- parking context {}",
// pid, tid // pid, tid
// ); // );
server.park_context(tid); server.park_thread(tid);
// For baremetal targets, switch away from this process. // For baremetal targets, switch away from this process.
if cfg!(baremetal) { if cfg!(baremetal) {
unsafe { SWITCHTO_CALLER = None }; unsafe { SWITCHTO_CALLER = None };
let ppid = ss.get_process(pid).expect("Can't get current process").ppid; let ppid = ss.get_process(pid).expect("Can't get current process").ppid;
ss.activate_process_context(ppid, 0, false, true) ss.activate_process_thread(ppid, 0, false, true)
.map(|_| Ok(xous::Result::ResumeProcess)) .map(|_| Ok(xous::Result::ResumeProcess))
.unwrap_or(Err(xous::Error::ProcessNotFound)) .unwrap_or(Err(xous::Error::ProcessNotFound))
} }
@ -366,7 +366,7 @@ pub fn handle(
); );
SWITCHTO_CALLER = Some((pid, tid)); SWITCHTO_CALLER = Some((pid, tid));
} }
ss.activate_process_context(new_pid, new_context, true, false) ss.activate_process_thread(new_pid, new_context, true, false)
.map(|_ctx| { .map(|_ctx| {
// println!("switchto ({}, {})", pid, _ctx); // println!("switchto ({}, {})", pid, _ctx);
xous::Result::ResumeProcess xous::Result::ResumeProcess
@ -388,7 +388,7 @@ pub fn handle(
.expect("yielded when no parent context was present") .expect("yielded when no parent context was present")
}; };
SystemServices::with_mut(|ss| { SystemServices::with_mut(|ss| {
ss.activate_process_context(parent_pid, parent_ctx, true, true) ss.activate_process_thread(parent_pid, parent_ctx, true, true)
.map(|_| Ok(xous::Result::ResumeProcess)) .map(|_| Ok(xous::Result::ResumeProcess))
.unwrap_or(Err(xous::Error::ProcessNotFound)) .unwrap_or(Err(xous::Error::ProcessNotFound))
}) })
@ -410,7 +410,7 @@ pub fn handle(
let process = ss.get_process(pid).expect("Can't get current process"); let process = ss.get_process(pid).expect("Can't get current process");
let ppid = process.ppid; let ppid = process.ppid;
unsafe { SWITCHTO_CALLER = None }; unsafe { SWITCHTO_CALLER = None };
ss.activate_process_context(ppid, 0, false, true) ss.activate_process_thread(ppid, 0, false, true)
.map(|_| Ok(xous::Result::ResumeProcess)) .map(|_| Ok(xous::Result::ResumeProcess))
.unwrap_or(Err(xous::Error::ProcessNotFound)) .unwrap_or(Err(xous::Error::ProcessNotFound))
}), }),