summaryrefslogtreecommitdiffstats
path: root/tokio/src/runtime/blocking.rs
blob: 8408e78b7ee8e1aa6f025c87025266464a0047db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//! Abstracts out the APIs necessary to `Runtime` for integrating the blocking
//! pool. When the `blocking` feature flag is **not** enabled. These APIs are
//! shells. This isolates the complexity of dealing with conditional
//! compilation.

cfg_blocking_impl! {
    pub(crate) use crate::blocking::BlockingPool;
    pub(crate) use crate::blocking::Spawner;

    use crate::runtime::Builder;

    pub(crate) fn create_blocking_pool(builder: &Builder) -> BlockingPool {
        BlockingPool::new(builder.thread_name.clone(), builder.thread_stack_size)
    }
}

cfg_not_blocking_impl! {
    use crate::runtime::Builder;

    #[derive(Debug, Clone)]
    pub(crate) struct BlockingPool {}

    pub(crate) use BlockingPool as Spawner;

    pub(crate) fn create_blocking_pool(_builder: &Builder) -> BlockingPool {
        BlockingPool {}
    }

    impl BlockingPool {
        pub(crate) fn spawner(&self) -> &BlockingPool {
            self
        }

        pub(crate) fn enter<F, R>(&self, f: F) -> R
        where
            F: FnOnce() -> R,
        {
            f()
        }
    }
}