From e2a6233c1272254b307c112c29f4cf7f0140b289 Mon Sep 17 00:00:00 2001 From: Jeremy Soller <jeremy@system76.com> Date: Wed, 13 Mar 2019 13:57:07 -0600 Subject: [PATCH] New fevent functionality to prevent missing events --- src/event.rs | 25 ++++++++++--------------- src/scheme/debug.rs | 2 +- src/scheme/irq.rs | 2 +- src/scheme/itimer.rs | 2 +- src/scheme/pipe.rs | 2 +- src/scheme/time.rs | 2 +- src/scheme/user.rs | 2 +- 7 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/event.rs b/src/event.rs index dbe908f4..2e6cf9ae 100644 --- a/src/event.rs +++ b/src/event.rs @@ -52,7 +52,10 @@ impl EventQueue { event.flags ); - send_flags(RegKey { scheme, number })?; + let flags = sync(RegKey { scheme, number })?; + if flags > 0 { + trigger(scheme, number, flags); + } } Ok(events.len()) @@ -133,7 +136,7 @@ pub fn register(reg_key: RegKey, queue_key: QueueKey, flags: usize) { } } -pub fn send_flags(reg_key: RegKey) -> Result<()> { +pub fn sync(reg_key: RegKey) -> Result<usize> { let mut flags = 0; { @@ -146,21 +149,13 @@ pub fn send_flags(reg_key: RegKey) -> Result<()> { } } - let event_id = { - let scheme = { - let schemes = scheme::schemes(); - let scheme = schemes.get(reg_key.scheme).ok_or(Error::new(EBADF))?; - Arc::clone(&scheme) - }; - - scheme.fevent(reg_key.number, flags)? + let scheme = { + let schemes = scheme::schemes(); + let scheme = schemes.get(reg_key.scheme).ok_or(Error::new(EBADF))?; + Arc::clone(&scheme) }; - if event_id != reg_key.number { - println!("scheme {} returned event id {} instead of {}", reg_key.scheme.into(), event_id, reg_key.number); - } - - Ok(()) + scheme.fevent(reg_key.number, flags) } pub fn unregister_file(scheme: SchemeId, number: usize) { diff --git a/src/scheme/debug.rs b/src/scheme/debug.rs index 35de9cc6..be93f99a 100644 --- a/src/scheme/debug.rs +++ b/src/scheme/debug.rs @@ -108,7 +108,7 @@ impl Scheme for DebugScheme { *handles.get(&id).ok_or(Error::new(EBADF))? }; - Ok(id) + Ok(0) } fn fpath(&self, id: usize, buf: &mut [u8]) -> Result<usize> { diff --git a/src/scheme/irq.rs b/src/scheme/irq.rs index 3c61091a..bb359e18 100644 --- a/src/scheme/irq.rs +++ b/src/scheme/irq.rs @@ -88,7 +88,7 @@ impl Scheme for IrqScheme { } fn fevent(&self, file: usize, _flags: usize) -> Result<usize> { - Ok(file) + Ok(0) } fn fpath(&self, id: usize, buf: &mut [u8]) -> Result<usize> { diff --git a/src/scheme/itimer.rs b/src/scheme/itimer.rs index 2eaae089..53c48fd5 100644 --- a/src/scheme/itimer.rs +++ b/src/scheme/itimer.rs @@ -81,7 +81,7 @@ impl Scheme for ITimerScheme { fn fevent(&self, id: usize, _flags: usize) -> Result<usize> { let handles = self.handles.read(); - handles.get(&id).ok_or(Error::new(EBADF)).and(Ok(id)) + handles.get(&id).ok_or(Error::new(EBADF)).and(Ok(0)) } fn fpath(&self, id: usize, buf: &mut [u8]) -> Result<usize> { diff --git a/src/scheme/pipe.rs b/src/scheme/pipe.rs index 80451d01..8bb6ae76 100644 --- a/src/scheme/pipe.rs +++ b/src/scheme/pipe.rs @@ -166,7 +166,7 @@ impl PipeRead { } fn fevent(&self, _flags: usize) -> Result<usize> { - Ok(self.event_id) + Ok(0) } fn read(&self, buf: &mut [u8]) -> Result<usize> { diff --git a/src/scheme/time.rs b/src/scheme/time.rs index 7ec3a185..bf5f73d9 100644 --- a/src/scheme/time.rs +++ b/src/scheme/time.rs @@ -92,7 +92,7 @@ impl Scheme for TimeScheme { fn fevent(&self, id: usize, _flags: usize) -> Result<usize> { let handles = self.handles.read(); - handles.get(&id).ok_or(Error::new(EBADF)).and(Ok(id)) + handles.get(&id).ok_or(Error::new(EBADF)).and(Ok(0)) } fn fpath(&self, id: usize, buf: &mut [u8]) -> Result<usize> { diff --git a/src/scheme/user.rs b/src/scheme/user.rs index 94785cdc..65a0dd50 100644 --- a/src/scheme/user.rs +++ b/src/scheme/user.rs @@ -207,7 +207,7 @@ impl UserInner { } pub fn fevent(&self, _flags: usize) -> Result<usize> { - Ok(self.handle_id) + Ok(0) } pub fn fsync(&self) -> Result<usize> { -- GitLab