Skip to content

Commit

Permalink
use mco replace cogo
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Feb 16, 2022
1 parent 274c76e commit 7bf1778
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 39 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ members = [

[package]
name = "fast_log"
version = "1.4.19"
version = "1.4.20"
description = "Rust async log High-performance asynchronous logging"
readme = "Readme.md"
authors = ["ce <[email protected]>"]
Expand All @@ -19,7 +19,7 @@ default = ["runtime_thread"]
gzip = ["flate2"]

runtime_thread = []
runtime_cogo = ["cogo"]
runtime_mco = ["mco"]

[dependencies]
chrono = { version = "0.4", features = ["serde"] }
Expand All @@ -30,7 +30,7 @@ crossbeam-utils = "0.8"
crossbeam = "0.8"
crossbeam-channel = "0.5"
parking_lot = "0.11"
cogo = {version = "0.1", optional = true }
mco = {version = "0.1", optional = true }
once_cell = "1.9"


Expand Down
2 changes: 1 addition & 1 deletion example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ crossbeam-channel = "0.5"
crossbeam-utils = "0.8"
crossbeam = "0.8"
chrono = { version = "0.4", features = ["serde"] }
cogo = "0.1"
mco = "0.1"

# features=["lz4"] or add features=["zip","lz4"] if you need lz4 packer
fast_log = { path = "../", features = ["lz4","zip","gzip"]}
70 changes: 35 additions & 35 deletions src/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@

use std::time::Duration;

/// if use cogo runtime
#[cfg(feature = "cogo")]
pub type TcpListener = cogo::net::TcpListener;
#[cfg(feature = "cogo")]
pub type TcpStream = cogo::net::TcpStream;
#[cfg(feature = "cogo")]
pub type Receiver<T> = cogo::std::sync::channel::Receiver<T>;
#[cfg(feature = "cogo")]
pub type Sender<T> = cogo::std::sync::channel::Sender<T>;
#[cfg(feature = "cogo")]
pub type JoinHandle<T> = cogo::coroutine::JoinHandle<T>;
#[cfg(feature = "cogo")]
pub type Mutex<T> = cogo::std::sync::Mutex<T>;
#[cfg(feature = "cogo")]
pub type WaitGroup = cogo::std::sync::WaitGroup;
/// if use mco runtime
#[cfg(feature = "mco")]
pub type TcpListener = mco::net::TcpListener;
#[cfg(feature = "mco")]
pub type TcpStream = mco::net::TcpStream;
#[cfg(feature = "mco")]
pub type Receiver<T> = mco::std::sync::channel::Receiver<T>;
#[cfg(feature = "mco")]
pub type Sender<T> = mco::std::sync::channel::Sender<T>;
#[cfg(feature = "mco")]
pub type JoinHandle<T> = mco::coroutine::JoinHandle<T>;
#[cfg(feature = "mco")]
pub type Mutex<T> = mco::std::sync::Mutex<T>;
#[cfg(feature = "mco")]
pub type WaitGroup = mco::std::sync::WaitGroup;

#[cfg(feature = "cogo")]
#[cfg(feature = "mco")]
pub fn chan<T>() -> (Sender<T>, Receiver<T>) {
cogo::chan!()
mco::chan!()
}

#[cfg(feature = "cogo")]
#[cfg(feature = "mco")]
pub fn sleep(d: Duration) {
cogo::coroutine::sleep(d)
mco::coroutine::sleep(d)
}

#[cfg(feature = "cogo")]
#[cfg(feature = "mco")]
pub fn spawn<F>(f: F) -> JoinHandle<()> where F: FnOnce() + std::marker::Send + 'static {
cogo::coroutine::Builder::new().stack_size(0x1000).spawn(f)
mco::coroutine::Builder::new().stack_size(0x1000).spawn(f)
}

#[cfg(feature = "cogo")]
#[cfg(feature = "mco")]
pub fn spawn_stack_size<F>(f: F, stack_size:usize) -> JoinHandle<()> where F: FnOnce() + std::marker::Send + 'static {
cogo::coroutine::Builder::new().stack_size(stack_size).spawn(f)
mco::coroutine::Builder::new().stack_size(stack_size).spawn(f)
}


/// if not cogo
#[cfg(not(feature = "cogo"))]
/// if not mco
#[cfg(not(feature = "mco"))]
pub type TcpListener = std::net::TcpListener;
#[cfg(not(feature = "cogo"))]
#[cfg(not(feature = "mco"))]
pub type TcpStream = std::net::TcpStream;
#[cfg(not(feature = "cogo"))]
#[cfg(not(feature = "mco"))]
pub type Receiver<T> = crossbeam::channel::Receiver<T>;
#[cfg(not(feature = "cogo"))]
#[cfg(not(feature = "mco"))]
pub type Sender<T> = crossbeam::channel::Sender<T>;
#[cfg(not(feature = "cogo"))]
#[cfg(not(feature = "mco"))]
pub type JoinHandle<T> = std::thread::JoinHandle<T>;
#[cfg(not(feature = "cogo"))]
#[cfg(not(feature = "mco"))]
pub type Mutex<T> = std::sync::Mutex<T>;
#[cfg(not(feature = "cogo"))]
#[cfg(not(feature = "mco"))]
pub type WaitGroup = crossbeam_utils::sync::WaitGroup;

#[cfg(not(feature = "cogo"))]
#[cfg(not(feature = "mco"))]
pub fn chan<T>() -> (Sender<T>, Receiver<T>) {
crossbeam::channel::unbounded()
}

#[cfg(not(feature = "cogo"))]
#[cfg(not(feature = "mco"))]
pub fn sleep(d: Duration) {
std::thread::sleep(d)
}

#[cfg(not(feature = "cogo"))]
#[cfg(not(feature = "mco"))]
pub fn spawn<F>(f: F) -> JoinHandle<()> where F: FnOnce() + std::marker::Send + 'static {
std::thread::spawn(f)
}

#[cfg(not(feature = "cogo"))]
#[cfg(not(feature = "mco"))]
pub fn spawn_stack_size<F>(f: F, stack_size:usize) -> JoinHandle<()> where F: FnOnce() + std::marker::Send + 'static {
std::thread::spawn(f)
}

0 comments on commit 7bf1778

Please sign in to comment.