mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-09 15:26:47 +00:00
uevent should be format Enum of smoltcp socket should be optimized. need to add interface for routing subsys actix is still not abled to run. clean some casual added code to other places
65 lines
1.6 KiB
Rust
65 lines
1.6 KiB
Rust
use alloc::{
|
|
collections::LinkedList,
|
|
sync::{Arc, Weak},
|
|
vec::Vec,
|
|
};
|
|
use system_error::SystemError;
|
|
|
|
use crate::{
|
|
libs::{spinlock::SpinLock, wait_queue::EventWaitQueue},
|
|
net::event_poll::{EPollEventType, EPollItem, EventPoll},
|
|
process::ProcessManager,
|
|
sched::{schedule, SchedMode},
|
|
};
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct EPollItems {
|
|
items: Arc<SpinLock<LinkedList<Arc<EPollItem>>>>,
|
|
}
|
|
|
|
impl Default for EPollItems {
|
|
fn default() -> Self {
|
|
Self {
|
|
items: Arc::new(SpinLock::new(LinkedList::new())),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl EPollItems {
|
|
pub fn add(&self, item: Arc<EPollItem>) {
|
|
self.items.lock_irqsave().push_back(item);
|
|
}
|
|
|
|
pub fn remove(&self, item: &Weak<SpinLock<EventPoll>>) -> Result<(), SystemError> {
|
|
let to_remove = self
|
|
.items
|
|
.lock_irqsave()
|
|
.extract_if(|x| x.epoll().ptr_eq(item))
|
|
.collect::<Vec<_>>();
|
|
|
|
let result = if !to_remove.is_empty() {
|
|
Ok(())
|
|
} else {
|
|
Err(SystemError::ENOENT)
|
|
};
|
|
|
|
drop(to_remove);
|
|
return result;
|
|
}
|
|
|
|
pub fn clear(&self) -> Result<(), SystemError> {
|
|
let mut guard = self.items.lock_irqsave();
|
|
let mut result = Ok(());
|
|
guard.iter().for_each(|item| {
|
|
if let Some(epoll) = item.epoll().upgrade() {
|
|
let _ =
|
|
EventPoll::ep_remove(&mut epoll.lock_irqsave(), item.fd(), None).map_err(|e| {
|
|
result = Err(e);
|
|
});
|
|
}
|
|
});
|
|
guard.clear();
|
|
return result;
|
|
}
|
|
}
|