diff --git a/aya/src/maps/perf/async_perf_event_array.rs b/aya/src/maps/perf/async_perf_event_array.rs index cc52e2dc..678060b0 100644 --- a/aya/src/maps/perf/async_perf_event_array.rs +++ b/aya/src/maps/perf/async_perf_event_array.rs @@ -1,8 +1,5 @@ use bytes::BytesMut; -use std::{ - borrow::Borrow, - os::fd::{AsRawFd as _, RawFd}, -}; +use std::borrow::Borrow; // See https://doc.rust-lang.org/cargo/reference/features.html#mutually-exclusive-features. // @@ -103,16 +100,11 @@ impl> AsyncPerfEventArray { ) -> Result, PerfBufferError> { let Self { perf_map } = self; let buf = perf_map.open(index, page_count)?; - let fd = buf.as_raw_fd(); - Ok(AsyncPerfEventArrayBuffer { - buf, - - #[cfg(feature = "async_tokio")] - async_tokio_fd: AsyncFd::new(fd)?, - - #[cfg(all(not(feature = "async_tokio"), feature = "async_std"))] - async_std_fd: Async::new(fd)?, - }) + #[cfg(feature = "async_tokio")] + let buf = AsyncFd::new(buf)?; + #[cfg(all(not(feature = "async_tokio"), feature = "async_std"))] + let buf = Async::new(buf)?; + Ok(AsyncPerfEventArrayBuffer { buf }) } } @@ -131,14 +123,15 @@ impl> AsyncPerfEventArray { /// /// See the [`AsyncPerfEventArray` documentation](AsyncPerfEventArray) for an overview of how to /// use perf buffers. -pub struct AsyncPerfEventArrayBuffer { +pub struct AsyncPerfEventArrayBuffer> { + #[cfg(not(any(feature = "async_tokio", feature = "async_std")))] buf: PerfEventArrayBuffer, #[cfg(feature = "async_tokio")] - async_tokio_fd: AsyncFd, + buf: AsyncFd>, #[cfg(all(not(feature = "async_tokio"), feature = "async_std"))] - async_std_fd: Async, + buf: Async>, } impl> AsyncPerfEventArrayBuffer { @@ -155,21 +148,20 @@ impl> AsyncPerfEventArrayBuffer { &mut self, buffers: &mut [BytesMut], ) -> Result { - let Self { - buf, - #[cfg(feature = "async_tokio")] - async_tokio_fd, - #[cfg(all(not(feature = "async_tokio"), feature = "async_std"))] - async_std_fd, - } = self; + let Self { buf } = self; loop { #[cfg(feature = "async_tokio")] - let mut guard = async_tokio_fd.readable_mut().await?; + let mut guard = buf.readable_mut().await?; + #[cfg(feature = "async_tokio")] + let buf = guard.get_inner_mut(); #[cfg(all(not(feature = "async_tokio"), feature = "async_std"))] - if !buf.readable() { - async_std_fd.readable().await?; - } + let buf = { + if !buf.get_ref().readable() { + buf.readable().await?; + } + buf.get_mut() + }; let events = buf.read_events(buffers)?; const EMPTY: Events = Events { read: 0, lost: 0 }; diff --git a/aya/src/maps/perf/perf_event_array.rs b/aya/src/maps/perf/perf_event_array.rs index 075998c6..00a5457e 100644 --- a/aya/src/maps/perf/perf_event_array.rs +++ b/aya/src/maps/perf/perf_event_array.rs @@ -180,7 +180,6 @@ impl> PerfEventArray { ) -> Result, PerfBufferError> { // FIXME: keep track of open buffers - // this cannot fail as new() checks that the fd is open let map_data: &MapData = self.map.deref().borrow(); let map_fd = map_data.fd; let buf = PerfBuffer::open(index, self.page_size, page_count.unwrap_or(2))?; diff --git a/xtask/public-api/aya.txt b/xtask/public-api/aya.txt index 47d9433c..81a8be26 100644 --- a/xtask/public-api/aya.txt +++ b/xtask/public-api/aya.txt @@ -404,7 +404,7 @@ impl core::borrow::BorrowMut for aya::maps::perf::AsyncPerfEventArray w pub fn aya::maps::perf::AsyncPerfEventArray::borrow_mut(&mut self) -> &mut T impl core::convert::From for aya::maps::perf::AsyncPerfEventArray pub fn aya::maps::perf::AsyncPerfEventArray::from(t: T) -> T -pub struct aya::maps::perf::AsyncPerfEventArrayBuffer +pub struct aya::maps::perf::AsyncPerfEventArrayBuffer> impl> aya::maps::perf::AsyncPerfEventArrayBuffer pub async fn aya::maps::perf::AsyncPerfEventArrayBuffer::read_events(&mut self, buffers: &mut [bytes::bytes_mut::BytesMut]) -> core::result::Result impl core::marker::Send for aya::maps::perf::AsyncPerfEventArrayBuffer where T: core::marker::Send + core::marker::Sync