修复阻塞阅读eventfd时无法被中断的bug (#1030)

Co-authored-by: sparkzky <sparkhhhhhhhhh@outlook.com>
This commit is contained in:
火花 2024-11-05 16:47:44 +08:00 committed by GitHub
parent c7ad61d495
commit 01b8a76cdc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,6 +5,7 @@ use crate::libs::spinlock::{SpinLock, SpinLockGuard};
use crate::libs::wait_queue::WaitQueue; use crate::libs::wait_queue::WaitQueue;
use crate::net::event_poll::{EPollEventType, EPollItem, EventPoll, KernelIoctlData}; use crate::net::event_poll::{EPollEventType, EPollItem, EventPoll, KernelIoctlData};
use crate::process::ProcessManager; use crate::process::ProcessManager;
use crate::sched::SchedMode;
use crate::syscall::Syscall; use crate::syscall::Syscall;
use alloc::collections::LinkedList; use alloc::collections::LinkedList;
use alloc::string::String; use alloc::string::String;
@ -76,6 +77,11 @@ impl EventFdInode {
Err(SystemError::ENOENT) Err(SystemError::ENOENT)
} }
fn readable(&self) -> bool {
let count = self.eventfd.lock().count;
return count > 0;
}
} }
impl IndexNode for EventFdInode { impl IndexNode for EventFdInode {
@ -104,26 +110,29 @@ impl IndexNode for EventFdInode {
_offset: usize, _offset: usize,
len: usize, len: usize,
buf: &mut [u8], buf: &mut [u8],
data: SpinLockGuard<FilePrivateData>, data_guard: SpinLockGuard<FilePrivateData>,
) -> Result<usize, SystemError> { ) -> Result<usize, SystemError> {
let data = data_guard.clone();
drop(data_guard);
if len < 8 { if len < 8 {
return Err(SystemError::EINVAL); return Err(SystemError::EINVAL);
} }
let mut val = loop { let mut lock_efd = self.eventfd.lock();
let val = self.eventfd.lock().count; while lock_efd.count == 0 {
if val != 0 { if lock_efd.flags.contains(EventFdFlags::EFD_NONBLOCK) {
break val; drop(lock_efd);
}
if self
.eventfd
.lock()
.flags
.contains(EventFdFlags::EFD_NONBLOCK)
{
return Err(SystemError::EAGAIN_OR_EWOULDBLOCK); return Err(SystemError::EAGAIN_OR_EWOULDBLOCK);
} }
self.wait_queue.sleep();
}; drop(lock_efd);
let r = wq_wait_event_interruptible!(self.wait_queue, self.readable(), {});
if r.is_err() {
return Err(SystemError::ERESTARTSYS);
}
lock_efd = self.eventfd.lock();
}
let mut val = lock_efd.count;
let mut eventfd = self.eventfd.lock(); let mut eventfd = self.eventfd.lock();
if eventfd.flags.contains(EventFdFlags::EFD_SEMAPHORE) { if eventfd.flags.contains(EventFdFlags::EFD_SEMAPHORE) {