mirror of
https://gitlab.com/marcandre.lureau/qemu-display.git
synced 2024-12-22 13:45:18 +00:00
rdp: make DisplayQueue cloneable
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
parent
6801ea795c
commit
6c9acc27d1
@ -1,10 +1,13 @@
|
||||
#![allow(dead_code)]
|
||||
// I wish I could reuse tokio::mpsc instead of creating a new queue from scratch
|
||||
use ironrdp::server::{BitmapUpdate, DisplayUpdate, PixelOrder};
|
||||
use ironrdp::{
|
||||
core::assert_impl,
|
||||
server::{BitmapUpdate, DisplayUpdate, PixelOrder},
|
||||
};
|
||||
use std::{
|
||||
collections::VecDeque,
|
||||
sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
atomic::{AtomicBool, AtomicUsize, Ordering},
|
||||
Arc,
|
||||
},
|
||||
};
|
||||
@ -24,16 +27,29 @@ pub(crate) struct DisplayQueue {
|
||||
notify_producer: Notify,
|
||||
notify_consumer: Notify,
|
||||
is_closed: AtomicBool,
|
||||
senders: AtomicUsize,
|
||||
}
|
||||
|
||||
pub(crate) struct Sender {
|
||||
channel: Arc<DisplayQueue>,
|
||||
}
|
||||
|
||||
impl Clone for Sender {
|
||||
fn clone(&self) -> Self {
|
||||
self.channel.senders.fetch_add(1, Ordering::SeqCst);
|
||||
Self {
|
||||
channel: Arc::clone(&self.channel),
|
||||
}
|
||||
}
|
||||
}
|
||||
assert_impl!(Sender: Send);
|
||||
|
||||
impl Drop for Sender {
|
||||
fn drop(&mut self) {
|
||||
if self.channel.senders.fetch_sub(1, Ordering::SeqCst) == 1 {
|
||||
self.channel.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct Receiver {
|
||||
@ -53,6 +69,7 @@ impl DisplayQueue {
|
||||
notify_producer: Notify::new(),
|
||||
notify_consumer: Notify::new(),
|
||||
is_closed: AtomicBool::new(false),
|
||||
senders: AtomicUsize::new(1),
|
||||
});
|
||||
(
|
||||
Sender {
|
||||
|
Loading…
Reference in New Issue
Block a user