mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-21 09:14:34 +00:00
kernel: server: allow taking multiple messages from queue
Previously, we would only look at the top item on the server queue. If it was not a known message, we would return an error. This patch changes this behavior to look through the entire queue for something we can take, and then clean it up as we go along. This allow for having outstanding requests in the queue an forms the backbone of the sleep server. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
ccc7264b79
commit
9ab5b4880f
1 changed files with 268 additions and 209 deletions
|
|
@ -387,17 +387,26 @@ impl Server {
|
|||
}
|
||||
}
|
||||
*current_val = QueuedMessage::Empty;
|
||||
if idx == self.queue_tail {
|
||||
self.queue_tail += 1;
|
||||
if self.queue_tail >= self.queue.len() {
|
||||
self.queue_tail = 0;
|
||||
}
|
||||
// Advance the pointer in case we have a long string of Empty messages.
|
||||
while self.queue_tail != self.queue_head && self.queue[self.queue_tail] == QueuedMessage::Empty {
|
||||
self.queue_tail += 1;
|
||||
if self.queue_tail >= self.queue.len() {
|
||||
self.queue_tail = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Destructure the PID and context ID from the `pid_tid` field
|
||||
klog!(
|
||||
"taking waiting message and returning to pid: {} tid: {}",
|
||||
pid,
|
||||
tid
|
||||
);
|
||||
// klog!(
|
||||
// "taking waiting message and returning to pid: {} tid: {}",
|
||||
// pid,
|
||||
// tid
|
||||
// );
|
||||
|
||||
if !is_memory {
|
||||
return Ok(WaitingMessage::ScalarMessage(
|
||||
|
|
@ -442,17 +451,47 @@ impl Server {
|
|||
/// * **None**: There are no waiting messages
|
||||
/// ***Some(MessageEnvelope): This message is queued.
|
||||
pub fn take_next_message(&mut self, sidx: usize) -> Option<xous_kernel::MessageEnvelope> {
|
||||
// println!(
|
||||
// klog!(
|
||||
// "queue_head: ((({}))) queue_tail: ((({}))): {:?} CID: ((({})))",
|
||||
// self.queue_head, self.queue_tail, self.queue[self.queue_tail], sidx
|
||||
// self.queue_head,
|
||||
// self.queue_tail,
|
||||
// self.queue[self.queue_tail],
|
||||
// sidx
|
||||
// );
|
||||
use core::convert::TryInto;
|
||||
let mut sender = SenderID::new(sidx, self.queue_tail, None);
|
||||
let (result, response) = match self.queue[self.queue_tail] {
|
||||
QueuedMessage::Empty => return None,
|
||||
QueuedMessage::WaitingReturnMemory(_, _, _, _, _) => return None,
|
||||
QueuedMessage::WaitingForget(_, _, _, _, _) => return None,
|
||||
QueuedMessage::WaitingReturnScalar(_, _, _) => return None,
|
||||
let mut queue_idx = self.queue_tail;
|
||||
while queue_idx != self.queue_head {
|
||||
let mut sender = SenderID::new(sidx, queue_idx, None);
|
||||
// klog!("Message @ server.queue[{}]: {:?}", queue_idx, self.queue[queue_idx]);
|
||||
let (result, response) = match self.queue[queue_idx] {
|
||||
QueuedMessage::Empty => {
|
||||
queue_idx += 1;
|
||||
if queue_idx >= self.queue.len() {
|
||||
queue_idx = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
QueuedMessage::WaitingReturnMemory(_, _, _, _, _) => {
|
||||
queue_idx += 1;
|
||||
if queue_idx >= self.queue.len() {
|
||||
queue_idx = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
QueuedMessage::WaitingForget(_, _, _, _, _) => {
|
||||
queue_idx += 1;
|
||||
if queue_idx >= self.queue.len() {
|
||||
queue_idx = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
QueuedMessage::WaitingReturnScalar(_, _, _) => {
|
||||
queue_idx += 1;
|
||||
if queue_idx >= self.queue.len() {
|
||||
queue_idx = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
QueuedMessage::MemoryMessageROLend(
|
||||
pid,
|
||||
tid,
|
||||
|
|
@ -564,13 +603,15 @@ impl Server {
|
|||
(
|
||||
xous_kernel::MessageEnvelope {
|
||||
sender: sender.into(),
|
||||
body: xous_kernel::Message::BlockingScalar(xous_kernel::ScalarMessage {
|
||||
body: xous_kernel::Message::BlockingScalar(
|
||||
xous_kernel::ScalarMessage {
|
||||
id,
|
||||
arg1,
|
||||
arg2,
|
||||
arg3,
|
||||
arg4,
|
||||
}),
|
||||
},
|
||||
),
|
||||
},
|
||||
QueuedMessage::WaitingReturnScalar(pid, tid, client_addr),
|
||||
)
|
||||
|
|
@ -595,11 +636,13 @@ impl Server {
|
|||
valid: MemorySize::new(valid),
|
||||
}),
|
||||
};
|
||||
self.queue[self.queue_tail] = QueuedMessage::Empty;
|
||||
self.queue[queue_idx] = QueuedMessage::Empty;
|
||||
if queue_idx == self.queue_tail {
|
||||
self.queue_tail += 1;
|
||||
if self.queue_tail >= self.queue.len() {
|
||||
self.queue_tail = 0;
|
||||
}
|
||||
}
|
||||
return Some(msg);
|
||||
}
|
||||
|
||||
|
|
@ -616,11 +659,13 @@ impl Server {
|
|||
arg4,
|
||||
}),
|
||||
};
|
||||
self.queue[self.queue_tail] = QueuedMessage::Empty;
|
||||
self.queue[queue_idx] = QueuedMessage::Empty;
|
||||
if queue_idx == self.queue_tail {
|
||||
self.queue_tail += 1;
|
||||
if self.queue_tail >= self.queue.len() {
|
||||
self.queue_tail = 0;
|
||||
}
|
||||
}
|
||||
return Some(msg);
|
||||
}
|
||||
QueuedMessage::BlockingScalarTerminated(
|
||||
|
|
@ -644,17 +689,21 @@ impl Server {
|
|||
arg4,
|
||||
}),
|
||||
};
|
||||
self.queue[self.queue_tail] = QueuedMessage::Empty;
|
||||
self.queue[queue_idx] = QueuedMessage::Empty;
|
||||
if queue_idx == self.queue_tail {
|
||||
self.queue_tail += 1;
|
||||
if self.queue_tail >= self.queue.len() {
|
||||
self.queue_tail = 0;
|
||||
}
|
||||
}
|
||||
return Some(msg);
|
||||
}
|
||||
};
|
||||
|
||||
self.queue[self.queue_tail] = response;
|
||||
Some(result)
|
||||
self.queue[queue_idx] = response;
|
||||
return Some(result);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Add the given message to this server's queue.
|
||||
|
|
@ -669,7 +718,12 @@ impl Server {
|
|||
message: xous_kernel::Message,
|
||||
original_address: Option<MemoryAddress>,
|
||||
) -> core::result::Result<usize, xous_kernel::Error> {
|
||||
// println!("Queueing message: {:?} for pid: {} tid: {}", message, pid.get(), context);
|
||||
// klog!(
|
||||
// "Queueing message: {:?} for pid: {} tid: {}",
|
||||
// message,
|
||||
// pid.get(),
|
||||
// context
|
||||
// );
|
||||
if self.queue[self.queue_head] != QueuedMessage::Empty {
|
||||
return Err(xous_kernel::Error::ServerQueueFull);
|
||||
}
|
||||
|
|
@ -732,6 +786,11 @@ impl Server {
|
|||
if self.queue_head >= self.queue.len() {
|
||||
self.queue_head = 0;
|
||||
}
|
||||
// klog!(
|
||||
// "queue head: {} queue_tail: {}",
|
||||
// self.queue_head,
|
||||
// self.queue_tail
|
||||
// );
|
||||
Ok(idx)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue