Skip to content

Commit

Permalink
Remove obsolete Wasm-specific code
Browse files Browse the repository at this point in the history
This is now part of the maybe-rayon crate introduced in PR #2914.
  • Loading branch information
kleisauke authored and barrbrain committed May 20, 2023
1 parent be88146 commit b3e5f87
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 140 deletions.
2 changes: 1 addition & 1 deletion src/api/channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use crate::api::util::*;
use crossbeam::channel::*;

use crate::rate::RCState;
use crate::rayon::ThreadPool;
use crate::util::Pixel;

use rayon::ThreadPool;
use std::sync::Arc;

mod data;
Expand Down
2 changes: 1 addition & 1 deletion src/api/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

use thiserror::Error;

use rayon::{ThreadPool, ThreadPoolBuilder};
use std::sync::Arc;

use crate::api::{ChromaSampling, Context, ContextInner, PixelRange};
use crate::rayon::{ThreadPool, ThreadPoolBuilder};
use crate::util::Pixel;

mod encoder;
Expand Down
2 changes: 1 addition & 1 deletion src/api/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use std::sync::Arc;
pub struct Context<T: Pixel> {
pub(crate) inner: ContextInner<T>,
pub(crate) config: EncoderConfig,
pub(crate) pool: Option<Arc<crate::rayon::ThreadPool>>,
pub(crate) pool: Option<Arc<rayon::ThreadPool>>,
pub(crate) is_flushing: bool,
}

Expand Down
2 changes: 1 addition & 1 deletion src/api/lookahead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use crate::frame::{AsRegion, PlaneOffset};
use crate::me::{estimate_tile_motion, RefMEStats};
use crate::partition::{get_intra_edges, BlockSize};
use crate::predict::{IntraParam, PredictionMode};
use crate::rayon::iter::*;
use crate::tiling::{Area, PlaneRegion, TileRect};
use crate::transform::TxSize;
use crate::Pixel;
use rayon::iter::*;
use rust_hawktracer::*;
use std::sync::Arc;
use v_frame::frame::Frame;
Expand Down
2 changes: 1 addition & 1 deletion src/deblock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ use crate::encoder::FrameInvariants;
use crate::partition::RefType::*;
use crate::predict::PredictionMode::*;
use crate::quantize::*;
use crate::rayon::iter::*;
use crate::tiling::*;
use crate::util::{clamp, ILog, Pixel};
use crate::DeblockState;
use rayon::iter::*;
use rust_hawktracer::*;
use std::cmp;

Expand Down
3 changes: 1 addition & 2 deletions src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use crate::wasm_bindgen::*;
use arg_enum_proc_macro::ArgEnum;
use arrayvec::*;
use bitstream_io::{BigEndian, BitWrite, BitWriter};
use rayon::iter::*;
use rust_hawktracer::*;

use std::collections::VecDeque;
Expand All @@ -49,8 +50,6 @@ use std::mem::MaybeUninit;
use std::sync::Arc;
use std::{fmt, io, mem};

use crate::rayon::iter::*;

#[allow(dead_code)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CDEFSearchMethod {
Expand Down
132 changes: 0 additions & 132 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,138 +143,6 @@ mod wasm_bindgen {
}
}

mod rayon {
cfg_if::cfg_if! {
if #[cfg(all(target_arch="wasm32", not(target_feature = "atomics")))] {
pub struct ThreadPoolBuilder ();
impl ThreadPoolBuilder {
pub fn new() -> ThreadPoolBuilder {
ThreadPoolBuilder()
}
pub fn build(self) -> Result<ThreadPool, ()> {
Ok(ThreadPool())
}
pub fn num_threads(self, _num_threads: usize) -> ThreadPoolBuilder {
ThreadPoolBuilder()
}
}
#[derive(Debug)]
pub struct ThreadPool ();
impl ThreadPool {
pub fn install<OP, R>(&self, op: OP) -> R where
OP: FnOnce() -> R + Send,
R: Send, {
op()
}
}

pub mod iter {
pub trait IntoParallelIterator {
type Iter: Iterator<Item = Self::Item>;
type Item: Send;

fn into_par_iter(self) -> Self::Iter;
}

impl<I: IntoIterator> IntoParallelIterator for I where
I::Item : Send {
type Item = I::Item;
type Iter = I::IntoIter;

fn into_par_iter(self) -> I::IntoIter {
self.into_iter()
}
}

pub trait IntoParallelRefMutIterator<'data> {
type Iter: IntoParallelIterator<Item = Self::Item>;
type Item: Send + 'data;

fn par_iter_mut(&'data mut self) -> Self::Iter;
}

impl<'data, I: 'data + ?Sized> IntoParallelRefMutIterator<'data> for I
where
&'data mut I: IntoParallelIterator,
{
type Iter = <&'data mut I as IntoParallelIterator>::Iter;
type Item = <&'data mut I as IntoParallelIterator>::Item;

fn par_iter_mut(&'data mut self) -> Self::Iter {
self.into_par_iter()
}
}

pub trait ParallelIterator: Iterator {
fn flat_map_iter<U, F>(self, f: F) -> std::iter::FlatMap<Self, U, F>
where
Self: Sized,
U: IntoIterator,
F: FnMut(<Self as Iterator>::Item) -> U,
{
self.flat_map(f)
}
}

impl<I: Iterator> ParallelIterator for I {}
}

pub mod slice {
pub trait ParallelSlice<T: Sync> {
fn par_chunks_exact(
&self, chunk_size: usize,
) -> std::slice::ChunksExact<'_, T>;
}

impl<T: Sync> ParallelSlice<T> for [T] {
#[inline]
fn par_chunks_exact(
&self, chunk_size: usize,
) -> std::slice::ChunksExact<'_, T> {
self.chunks_exact(chunk_size)
}
}
}

pub mod prelude {
pub use super::iter::*;
pub use super::slice::*;
}

pub fn join<A, B, RA, RB>(oper_a: A, oper_b: B) -> (RA, RB)
where
A: FnOnce() -> RA + Send,
B: FnOnce() -> RB + Send,
RA: Send,
RB: Send {
(oper_a(), oper_b())
}

use std::marker::PhantomData;

pub struct Scope<'scope>{
marker: PhantomData<Box<dyn FnOnce(&Scope<'scope>) + Send + Sync + 'scope>>,
}

impl<'scope> Scope<'scope> {
pub fn spawn<BODY>(&self, body: BODY)
where BODY: FnOnce(&Scope<'scope>) + Send + 'scope
{
body(self)
}
}

pub fn scope<'scope, OP, R>(op: OP) -> R
where OP: for<'s> FnOnce(&'s Scope<'scope>) -> R + 'scope + Send, R: Send,
{
op(&Scope { marker: PhantomData})
}
} else {
pub use rayon::*;
}
}
}

#[cfg(any(cargo_c, feature = "capi"))]
pub mod capi;

Expand Down
2 changes: 1 addition & 1 deletion src/scenechange/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl<T: Pixel> SceneChangeDetector<T> {
clone
};

crate::rayon::scope(|s| {
rayon::scope(|s| {
s.spawn(|_| {
let temp_plane =
self.temp_plane.get_or_insert_with(|| frame2.planes[0].clone());
Expand Down

0 comments on commit b3e5f87

Please sign in to comment.