Skip to content

Commit

Permalink
Merge pull request #36 from hbuxiaofei/Starry-epoll
Browse files Browse the repository at this point in the history
epoll: fix deadlock for fd_table
  • Loading branch information
Azure-stars authored Apr 26, 2024
2 parents c7ba63e + 8706e6d commit c59d10f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ulib/axstarry/src/syscall_fs/ctype/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ impl EpollFile {
let mut ret_events = Vec::new();
loop {
let current_process = current_process();
let fd_table = current_process.fd_manager.fd_table.lock();
for req_event in events.iter() {
let fd_table = current_process.fd_manager.fd_table.lock();
if let Some(file) = &fd_table[req_event.data as usize] {
let mut ret_event_type = EpollEventType::empty();
if file.is_hang_up() {
Expand Down
16 changes: 9 additions & 7 deletions ulib/axstarry/src/syscall_fs/imp/epoll.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The epoll API performs a similar task to poll: monitoring
//! multiple file descriptors to see if I/O is possible on any of
//! them.
//! them.
extern crate alloc;
use crate::{SyscallError, SyscallResult};
use alloc::sync::Arc;
Expand Down Expand Up @@ -96,15 +96,17 @@ pub fn syscall_epoll_wait(args: [usize; 6]) -> SyscallResult {
return Err(SyscallError::EFAULT);
}

let fd_table = process.fd_manager.fd_table.lock();
let epoll_file = if let Some(file) = fd_table[epfd as usize].as_ref() {
if let Some(epoll_file) = file.as_any().downcast_ref::<EpollFile>() {
epoll_file.clone()
let epoll_file = {
let fd_table = process.fd_manager.fd_table.lock();
if let Some(file) = fd_table[epfd as usize].as_ref() {
if let Some(epoll_file) = file.as_any().downcast_ref::<EpollFile>() {
epoll_file.clone()
} else {
return Err(SyscallError::EBADF);
}
} else {
return Err(SyscallError::EBADF);
}
} else {
return Err(SyscallError::EBADF);
};

let timeout = if timeout > 0 {
Expand Down

0 comments on commit c59d10f

Please sign in to comment.