servo/components/media/media_channel/mod.rs
Hayashi Mikihiro 4cc1b68546
Remove lazy static (#33078)
* remove from rand

Mutex<OsRng> can be initialized in compile time.

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* remove from layout_2020

Mutex<()> can be initialize in compile time

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* remove from media

`IS_MULTIPROCESS` doesn't be used.

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* remove lazy_static from dependencies

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

* rewrite suppressed_leaks_for_asan.txt

For all of lazy_static was replaced with LazyLock.

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

---------

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>
2024-08-16 03:57:09 +00:00

113 lines
3 KiB
Rust

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//! Enum wrappers to be able to select different channel implementations at runtime.
mod ipc;
mod mpsc;
use std::fmt;
use serde::{Deserialize, Serialize};
use crate::GLPlayerMsg;
#[derive(Deserialize, Serialize)]
pub enum GLPlayerSender<T: Serialize> {
Ipc(ipc::GLPlayerSender<T>),
Mpsc(mpsc::GLPlayerSender<T>),
}
impl<T> Clone for GLPlayerSender<T>
where
T: Serialize,
{
fn clone(&self) -> Self {
match *self {
GLPlayerSender::Ipc(ref chan) => GLPlayerSender::Ipc(chan.clone()),
GLPlayerSender::Mpsc(ref chan) => GLPlayerSender::Mpsc(chan.clone()),
}
}
}
impl<T: Serialize> fmt::Debug for GLPlayerSender<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "GLPlayerSender(..)")
}
}
impl<T: Serialize> GLPlayerSender<T> {
#[inline]
pub fn send(&self, msg: T) -> GLPlayerSendResult {
match *self {
GLPlayerSender::Ipc(ref sender) => sender.send(msg).map_err(|_| ()),
GLPlayerSender::Mpsc(ref sender) => sender.send(msg).map_err(|_| ()),
}
}
}
pub type GLPlayerSendResult = Result<(), ()>;
pub enum GLPlayerReceiver<T>
where
T: for<'de> Deserialize<'de> + Serialize,
{
Ipc(ipc::GLPlayerReceiver<T>),
Mpsc(mpsc::GLPlayerReceiver<T>),
}
impl<T> GLPlayerReceiver<T>
where
T: for<'de> Deserialize<'de> + Serialize,
{
pub fn recv(&self) -> Result<T, ()> {
match *self {
GLPlayerReceiver::Ipc(ref receiver) => receiver.recv().map_err(|_| ()),
GLPlayerReceiver::Mpsc(ref receiver) => receiver.recv().map_err(|_| ()),
}
}
#[allow(clippy::wrong_self_convention)] // It is an alias to the underlying module
pub fn to_opaque(self) -> ipc_channel::ipc::OpaqueIpcReceiver {
match self {
GLPlayerReceiver::Ipc(receiver) => receiver.to_opaque(),
_ => unreachable!(),
}
}
}
pub fn glplayer_channel<T>() -> Option<(GLPlayerSender<T>, GLPlayerReceiver<T>)>
where
T: for<'de> Deserialize<'de> + Serialize,
{
// Let's use Ipc until we move the Player instance into GPlayerThread
if true {
ipc::glplayer_channel()
.map(|(tx, rx)| (GLPlayerSender::Ipc(tx), GLPlayerReceiver::Ipc(rx)))
.ok()
} else {
mpsc::glplayer_channel()
.map(|(tx, rx)| (GLPlayerSender::Mpsc(tx), GLPlayerReceiver::Mpsc(rx)))
.ok()
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct GLPlayerChan(pub GLPlayerSender<GLPlayerMsg>);
impl GLPlayerChan {
#[inline]
pub fn send(&self, msg: GLPlayerMsg) -> GLPlayerSendResult {
self.0.send(msg)
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct GLPlayerPipeline(pub GLPlayerChan);
impl GLPlayerPipeline {
pub fn channel(&self) -> GLPlayerChan {
self.0.clone()
}
}