Skip to content

Commit

Permalink
move mpmc,mpsc to channel
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Jan 26, 2022
1 parent 99e3e4c commit 890644f
Show file tree
Hide file tree
Showing 17 changed files with 25 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ members = [

[package]
name = "cogo"
version = "0.1.27"
version = "0.1.28"
edition = "2018"
authors = ["[email protected]","Xudong Huang <[email protected]>"]
license = "MIT/Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion benches/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern crate cogo;
extern crate test;

use test::Bencher;
use cogo::std::sync::mpmc::channel;
use cogo::std::sync::channel::channel;


// improve performance from 39,294 ns/iter to 12,207 ns/iter (my computer)
Expand Down
5 changes: 1 addition & 4 deletions examples/src/channel.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use std::time::Duration;


use cogo::coroutine::sleep;
use cogo::{chan, go};
use cogo::std::sync::mpsc;
use cogo::std::sync::mpsc::{bounded, channel, channel_buf, unbounded};
use cogo::std::sync::channel::{bounded, channel, channel_buf, unbounded};


fn main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::time::Duration;

use cogo::coroutine;
use cogo::net::TcpListener;
use cogo::std::sync::mpsc::channel;
use cogo::std::sync::channel::channel;

// general select example that use cqueue
fn main() {
Expand Down
4 changes: 2 additions & 2 deletions src/std/io/stream_chan.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::mpsc::RecvError;
use crate::std::errors::Error;
use crate::std::io::{Stream, TryStream};
use crate::std::sync::mpsc::{Receiver, Sender, unbounded};
use crate::std::sync::channel::{Receiver, Sender, unbounded};


/// ChanStream,based on mpsc channel.when send Err data stop next
Expand Down Expand Up @@ -53,7 +53,7 @@ impl<T, E> Stream for ChanStream<T, E> {
#[cfg(test)]
mod test {
use crate::std::io::{ChanStream, TryStream};
use crate::std::sync::mpsc::channel;
use crate::std::sync::channel::channel;
use crate::std::errors::Error;
use std::ops::ControlFlow;

Expand Down
10 changes: 5 additions & 5 deletions src/std/sync/mpmc.rs → src/std/sync/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ pub fn bounded<T>(buf: usize) -> (Sender<T>, Receiver<T>) {
#[macro_export]
macro_rules! chan {
() => {
$crate::std::sync::mpsc::bounded(usize::MAX)
$crate::std::sync::channel::bounded(usize::MAX)
};
($num:expr) => {
$crate::std::sync::mpsc::bounded($num)
$crate::std::sync::channel::bounded($num)
};
($t:path,$num:expr) => {
$crate::std::sync::mpsc::bounded::<$t>($num)
$crate::std::sync::channel::bounded::<$t>($num)
};
}

Expand Down Expand Up @@ -1125,9 +1125,9 @@ mod tests {

#[test]
fn stress_mutli_recv() {
use crate::std::sync::mpsc;
use crate::std::sync::channel;
let (tx, rx) = channel();
let (tx1, rx1) = mpsc::channel();
let (tx1, rx1) = channel();
let stress = stress_factor() + 100;

for i in 0..10 {
Expand Down
2 changes: 1 addition & 1 deletion src/std/sync/condvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl Default for Condvar {
mod tests {
#![feature(test)]

use crate::std::sync::mpsc::channel;
use crate::std::sync::channel::channel;
use crate::std::sync::{Condvar, Mutex};
use std::sync::Arc;
use std::sync::mpsc::TryRecvError;
Expand Down
5 changes: 2 additions & 3 deletions src/std/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ pub(crate) mod atomic_dur;
#[cfg(not(unix))]
pub(crate) mod delay_drop;
#[macro_use]
pub mod mpmc;
#[macro_use]
pub mod mpsc;
pub mod channel;

pub use self::atomic_option::AtomicOption;
pub use self::blocking::{Blocker, FastBlocker};
Expand All @@ -28,3 +26,4 @@ pub use self::sync_flag::SyncFlag;
pub use self::wait_group::*;
pub use self::sync_map::*;
pub use self::once::*;
pub use self::channel::*;
8 changes: 0 additions & 8 deletions src/std/sync/mpsc.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/std/sync/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ mod tests {
#![feature(test)]

use super::*;
use crate::std::sync::mpsc::channel;
use crate::std::sync::channel::channel;
use crate::std::sync::Condvar;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
Expand Down
2 changes: 1 addition & 1 deletion src/std/sync/once.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ mod test {
use std::panic::catch_unwind;
use std::sync::Arc;
use crate::{chan, defer};
use crate::std::sync::mpmc::Sender;
use crate::std::sync::channel::Sender;
use crate::std::sync::Once;

pub struct One {
Expand Down
2 changes: 1 addition & 1 deletion src/std/sync/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ impl<'a, T: ?Sized> Drop for RwLockWriteGuard<'a, T> {
mod tests {
#![feature(test)]

use crate::std::sync::mpsc::channel;
use crate::std::sync::channel::channel;
use crate::std::sync::{Condvar, Mutex, RwLock};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Arc, TryLockError};
Expand Down
2 changes: 1 addition & 1 deletion src/std/sync/semphore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ mod tests {
use std::sync::mpsc::TryRecvError;
use std::thread;
use std::time::Duration;
use crate::std::sync::mpsc::channel;
use crate::std::sync::channel::channel;


#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/std/time/tick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::{Arc, LockResult};
use std::sync::mpsc::RecvError;
use std::time::Duration;
use crate::coroutine::sleep;
use crate::std::sync::mpmc::{Receiver, Sender};
use crate::std::sync::channel::{Receiver, Sender};
use crate::std::sync::Mutex;
use crate::std::time::time::Time;
use crate::std::errors::Result;
Expand Down
2 changes: 1 addition & 1 deletion tests/channel.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::time::Duration;
use cogo::coroutine::sleep;
use cogo::go;
use cogo::std::sync::mpmc::channel;
use cogo::std::sync::channel::channel;
use cogo::std::sync::WaitGroup;

#[test]
Expand Down
6 changes: 3 additions & 3 deletions tests/cqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fn cqueue_poll() {
#[test]
fn cqueue_oneshot() {
// oneshot only support open set_work_steal true
use cogo::std::sync::mpsc::channel;
use cogo::std::sync::channel::channel;

let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
Expand Down Expand Up @@ -145,7 +145,7 @@ fn cqueue_oneshot() {

#[test]
fn cqueue_select() {
use cogo::std::sync::mpsc::channel;
use cogo::std::sync::channel::channel;

let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
Expand Down Expand Up @@ -179,7 +179,7 @@ fn cqueue_timeout() {

#[test]
fn cqueue_loop() {
use cogo::std::sync::mpsc::channel;
use cogo::std::sync::channel::channel;

let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
Expand Down
4 changes: 2 additions & 2 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ fn test_sleep() {

#[test]
fn join_macro() {
use cogo::std::sync::mpsc::channel;
use cogo::std::sync::channel::channel;

let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
Expand Down Expand Up @@ -314,7 +314,7 @@ fn join_macro() {

#[test]
fn go_with_macro() {
use cogo::std::sync::mpsc::channel;
use cogo::std::sync::channel::channel;

let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
Expand Down

0 comments on commit 890644f

Please sign in to comment.