mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
implement Drop on Com object
This commit is contained in:
parent
d4e1de7cf9
commit
c972666f41
3 changed files with 57 additions and 17 deletions
|
|
@ -122,10 +122,21 @@ impl Com {
|
||||||
|
|
||||||
impl Drop for Com {
|
impl Drop for Com {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
// tell my handler thread to quit
|
// if we have callbacks, destroy the battstats callback server
|
||||||
xous::send_message(self.conn,
|
if let Some(sid) = self.battstats_sid.take() {
|
||||||
Message::new_scalar(api::Callback::Drop.to_usize().unwrap(), 0, 0, 0, 0)).unwrap();
|
// no need to tell the COM server we're quitting: the next time a callback processes,
|
||||||
// now de-allocate myself
|
// it will automatically remove my entry as it will receive a ServerNotFound error.
|
||||||
self.battstats_sid = None;
|
|
||||||
|
// tell my handler thread to quit
|
||||||
|
let cid = xous::connect(sid).unwrap();
|
||||||
|
xous::send_message(cid,
|
||||||
|
Message::new_blocking_scalar(api::Callback::Drop.to_usize().unwrap(), 0, 0, 0, 0)).unwrap();
|
||||||
|
unsafe{xous::disconnect(cid).unwrap();}
|
||||||
|
xous::destroy_server(sid).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
// now de-allocate myself. It's unsafe because we are responsible to make sure nobody else is using the connection.
|
||||||
|
unsafe{xous::disconnect(self.conn).unwrap();}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -127,21 +127,31 @@ mod implementation {
|
||||||
self.txrx(tx)
|
self.txrx(tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_queue(&mut self) {
|
pub fn process_queue(&mut self) -> Option<xous::CID> {
|
||||||
if !self.workqueue.is_empty() && !self.busy {
|
if !self.workqueue.is_empty() && !self.busy {
|
||||||
self.busy = true;
|
self.busy = true;
|
||||||
let work_descriptor = self.workqueue.swap_remove(0); // not quite FIFO, but Vec does not support FIFO (best we can do with "heapless")
|
let work_descriptor = self.workqueue.swap_remove(0); // not quite FIFO, but Vec does not support FIFO (best we can do with "heapless")
|
||||||
if work_descriptor.work.verb == ComState::STAT.verb {
|
let ret = if work_descriptor.work.verb == ComState::STAT.verb {
|
||||||
let stats = self.get_battstats();
|
let stats = self.get_battstats();
|
||||||
return_battstats(work_descriptor.sender, stats)
|
match return_battstats(work_descriptor.sender, stats) {
|
||||||
.expect("Could not return BattStatsNb value");
|
Err(xous::Error::ServerNotFound) => {
|
||||||
|
// the callback target has quit, so de-allocate it from our list
|
||||||
|
Some(work_descriptor.sender)
|
||||||
|
},
|
||||||
|
Ok(()) => None,
|
||||||
|
_ => panic!("unhandled error in callback process_queue"),
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
error!(
|
error!(
|
||||||
"unimplemented work queue responder 0x{:x}",
|
"unimplemented work queue responder 0x{:x}",
|
||||||
work_descriptor.work.verb
|
work_descriptor.work.verb
|
||||||
);
|
);
|
||||||
}
|
None
|
||||||
|
};
|
||||||
self.busy = false;
|
self.busy = false;
|
||||||
|
ret
|
||||||
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -207,21 +217,31 @@ mod implementation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_queue(&mut self) {
|
pub fn process_queue(&mut self) -> Option<xous::CID> {
|
||||||
if !self.workqueue.is_empty() && !self.busy {
|
if !self.workqueue.is_empty() && !self.busy {
|
||||||
self.busy = true;
|
self.busy = true;
|
||||||
let work_descriptor = self.workqueue.swap_remove(0); // not quite FIFO, but Vec does not support FIFO (best we can do with "heapless")
|
let work_descriptor = self.workqueue.swap_remove(0); // not quite FIFO, but Vec does not support FIFO (best we can do with "heapless")
|
||||||
if work_descriptor.work.verb == ComState::STAT.verb {
|
let ret = if work_descriptor.work.verb == ComState::STAT.verb {
|
||||||
let stats = self.get_battstats();
|
let stats = self.get_battstats();
|
||||||
return_battstats(work_descriptor.sender, stats)
|
match return_battstats(work_descriptor.sender, stats) {
|
||||||
.expect("Could not return BattStatsNb value");
|
Err(xous::Error::ServerNotFound) => {
|
||||||
|
// the callback target has quit, so de-allocate it from our list
|
||||||
|
Some(work_descriptor.sender)
|
||||||
|
},
|
||||||
|
Ok(()) => None,
|
||||||
|
_ => panic!("unhandled error in callback process_queue"),
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
error!(
|
error!(
|
||||||
"unimplemented work queue responder 0x{:x}",
|
"unimplemented work queue responder 0x{:x}",
|
||||||
work_descriptor.work.verb
|
work_descriptor.work.verb
|
||||||
);
|
);
|
||||||
}
|
None
|
||||||
|
};
|
||||||
self.busy = false;
|
self.busy = false;
|
||||||
|
ret
|
||||||
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -341,6 +361,15 @@ fn xmain() -> ! {
|
||||||
None => error!("unknown opcode"),
|
None => error!("unknown opcode"),
|
||||||
}
|
}
|
||||||
|
|
||||||
com.process_queue();
|
if let Some(dropped_cid) = com.process_queue() {
|
||||||
|
for entry in battstats_conns.iter_mut() {
|
||||||
|
if let Some(cid) = *entry {
|
||||||
|
if cid == dropped_cid {
|
||||||
|
*entry = None;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ fn try_main() -> Result<(), DynError> {
|
||||||
//"shellchat",
|
//"shellchat",
|
||||||
//"ime-frontend",
|
//"ime-frontend",
|
||||||
//"ime-plugin-shell",
|
//"ime-plugin-shell",
|
||||||
"graphics-server",
|
//"graphics-server",
|
||||||
"ticktimer-server",
|
"ticktimer-server",
|
||||||
"log-server",
|
"log-server",
|
||||||
"com",
|
"com",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue