This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::mem; | |
| use std::sync::Arc; | |
| use futures::task::{Context, Poll}; | |
| use tokio::sync::{Mutex, OwnedMutexGuard}; | |
| use tower_service::Service; | |
| use tokio_util::sync::ReusableBoxFuture; | |
| pub struct CloneableService<S> { | |
| inner: Arc<Mutex<S>>, | |
| mutex_fut: ReusableBoxFuture<OwnedMutexGuard<S>>, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn transfer(&mut self, value_in: u8) | |
| -> Result<u8, nb::Error<T::Error>> | |
| { | |
| // We always have to do a complete transfer - writing out and reading | |
| // in. If we don't do the read, then the read buffer overflows and | |
| // we can't use it when we need it. | |
| self.spi.send(value_in)?; | |
| Ok(self.spi.read()?) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use tokio::sync::Semaphore; | |
| use std::sync::Arc; | |
| use std::time::Instant; | |
| const LOOPS: usize = 1000000; | |
| async fn twiddle(semaphore1: Arc<Semaphore>, semaphore2: Arc<Semaphore>) { | |
| for _ in 0..LOOPS { | |
| semaphore1.add_permits(1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #[derive(Debug)] | |
| struct MonitoredWriter<W: AsyncWriteExt + Unpin> { | |
| stream: W, | |
| id_string: String, | |
| held_buffer: Vec<u8>, | |
| write_flag: AtomicBool, | |
| } | |
| impl<W: AsyncWriteExt + Unpin> MonitoredWriter<W> { | |
| fn new(stream: W, id_string: String) -> MonitoredWriter<W> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::fmt; | |
| use std::io::{self, IoSlice, IoSliceMut, Read, Write}; | |
| use std::net::{self, Shutdown, SocketAddr}; | |
| #[cfg(any(unix, target_os = "wasi"))] | |
| use std::os::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd}; | |
| // TODO: once <https://github.com/rust-lang/rust/issues/126198> is fixed this | |
| // can use `std::os::fd` and be merged with the above. | |
| #[cfg(target_os = "hermit")] | |
| use std::os::hermit::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd}; | |
| #[cfg(windows)] |
OlderNewer