Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  mod.rs

  Sprache: Rust
 

cfg_rt! {
    pub(cratemod current_thread;
    pub(crateuse current_thread::CurrentThread;

    mod defer;
    use defer::Defer;

    pub(cratemod inject;
    pub(crateuse inject::Inject;
}

cfg_rt_multi_thread! {
    mod block_in_place;
    pub(crateuse block_in_place::block_in_place;

    mod lock;
    use lock::Lock;

    pub(cratemod multi_thread;
    pub(crateuse multi_thread::MultiThread;

    cfg_unstable! {
        pub(cratemod multi_thread_alt;
        pub(crateuse multi_thread_alt::MultiThread as MultiThreadAlt;
    }
}

use crate::runtime::driver;

#[derive(Debug, Clone)]
pub(crateenum Handle {
    #[cfg(feature = "rt")]
    CurrentThread(Arc<current_thread::Handle>),

    #[cfg(feature = "rt-multi-thread")]
    MultiThread(Arc<multi_thread::Handle>),

    #[cfg(all(tokio_unstable, feature = "rt-multi-thread"))]
    MultiThreadAlt(Arc<multi_thread_alt::Handle>),

    // TODO: This is to avoid triggering "dead code" warnings many other places
    // in the codebase. Remove this during a later cleanup
    #[cfg(not(feature = "rt"))]
    #[allow(dead_code)]
    Disabled,
}

#[cfg(feature = "rt")]
pub(superenum Context {
    CurrentThread(current_thread::Context),

    #[cfg(feature = "rt-multi-thread")]
    MultiThread(multi_thread::Context),

    #[cfg(all(tokio_unstable, feature = "rt-multi-thread"))]
    MultiThreadAlt(multi_thread_alt::Context),
}

impl Handle {
    #[cfg_attr(not(feature = "full"), allow(dead_code))]
    pub(cratefn driver(&self) -> &driver::Handle {
        match *self {
            #[cfg(feature = "rt")]
            Handle::CurrentThread(ref h) => &h.driver,

            #[cfg(feature = "rt-multi-thread")]
            Handle::MultiThread(ref h) => &h.driver,

            #[cfg(all(tokio_unstable, feature = "rt-multi-thread"))]
            Handle::MultiThreadAlt(ref h) => &h.driver,

            #[cfg(not(feature = "rt"))]
            Handle::Disabled => unreachable!(),
        }
    }
}

cfg_rt! {
    use crate::future::Future;
    use crate::loom::sync::Arc;
    use crate::runtime::{blocking, task::Id};
    use crate::runtime::context;
    use crate::task::JoinHandle;
    use crate::util::RngSeedGenerator;
    use std::task::Waker;

    macro_rules! match_flavor {
        ($self:expr, $ty:ident($h:ident) => $e:expr) => {
            match $self {
                $ty::CurrentThread($h) => $e,

                #[cfg(feature = "rt-multi-thread")]
                $ty::MultiThread($h) => $e,

                #[cfg(all(tokio_unstable, feature = "rt-multi-thread"))]
                $ty::MultiThreadAlt($h) => $e,
            }
        }
    }

    impl Handle {
        #[track_caller]
        pub(cratefn current() -> Handle {
            match context::with_current(Clone::clone) {
                Ok(handle) => handle,
                Err(e) => panic!("{}", e),
            }
        }

        pub(cratefn blocking_spawner(&self) -> &blocking::Spawner {
            match_flavor!(self, Handle(h) => &h.blocking_spawner)
        }

        pub(cratefn spawn<F>(&self, future: F, id: Id) -> JoinHandle<F::Output>
        where
            F: Future + Send + 'static,
            F::Output: Send + 'static,
        {
            match self {
                Handle::CurrentThread(h) => current_thread::Handle::spawn(h, future, id),

                #[cfg(feature = "rt-multi-thread")]
                Handle::MultiThread(h) => multi_thread::Handle::spawn(h, future, id),

                #[cfg(all(tokio_unstable, feature = "rt-multi-thread"))]
                Handle::MultiThreadAlt(h) => multi_thread_alt::Handle::spawn(h, future, id),
            }
        }

        pub(cratefn shutdown(&self) {
            match *self {
                Handle::CurrentThread(_) => {},

                #[cfg(feature = "rt-multi-thread")]
                Handle::MultiThread(ref h) => h.shutdown(),

                #[cfg(all(tokio_unstable, feature = "rt-multi-thread"))]
                Handle::MultiThreadAlt(ref h) => h.shutdown(),
            }
        }

        pub(cratefn seed_generator(&self) -> &RngSeedGenerator {
            match_flavor!(self, Handle(h) => &h.seed_generator)
        }

        pub(cratefn as_current_thread(&self) -> &Arc<current_thread::Handle> {
            match self {
                Handle::CurrentThread(handle) => handle,
                #[cfg(feature = "rt-multi-thread")]
                _ => panic!("not a CurrentThread handle"),
            }
        }

        cfg_rt_multi_thread! {
            cfg_unstable! {
                pub(cratefn expect_multi_thread_alt(&self) -> &Arc<multi_thread_alt::Handle> {
                    match self {
                        Handle::MultiThreadAlt(handle) => handle,
                        _ => panic!("not a `MultiThreadAlt` handle"),
                    }
                }
            }
        }
    }

    impl Handle {
        pub(cratefn num_workers(&self) -> usize {
            match self {
                Handle::CurrentThread(_) => 1,
                #[cfg(feature = "rt-multi-thread")]
                Handle::MultiThread(handle) => handle.num_workers(),
                #[cfg(all(tokio_unstable, feature = "rt-multi-thread"))]
                Handle::MultiThreadAlt(handle) => handle.num_workers(),
            }
        }

        pub(cratefn num_alive_tasks(&self) -> usize {
            match_flavor!(self, Handle(handle) => handle.num_alive_tasks())
        }
    }

    cfg_unstable_metrics! {
        use crate::runtime::{SchedulerMetrics, WorkerMetrics};

        impl Handle {
            cfg_64bit_metrics! {
                pub(cratefn spawned_tasks_count(&self) -> u64 {
                    match_flavor!(self, Handle(handle) => handle.spawned_tasks_count())
                }
            }

            pub(cratefn num_blocking_threads(&self) -> usize {
                match_flavor!(self, Handle(handle) => handle.num_blocking_threads())
            }

            pub(cratefn num_idle_blocking_threads(&self) -> usize {
                match_flavor!(self, Handle(handle) => handle.num_idle_blocking_threads())
            }

            pub(cratefn scheduler_metrics(&self) -> &SchedulerMetrics {
                match_flavor!(self, Handle(handle) => handle.scheduler_metrics())
            }

            pub(cratefn worker_metrics(&self, worker: usize) -> &WorkerMetrics {
                match_flavor!(self, Handle(handle) => handle.worker_metrics(worker))
            }

            pub(cratefn injection_queue_depth(&self) -> usize {
                match_flavor!(self, Handle(handle) => handle.injection_queue_depth())
            }

            pub(cratefn worker_local_queue_depth(&self, worker: usize) -> usize {
                match_flavor!(self, Handle(handle) => handle.worker_local_queue_depth(worker))
            }

            pub(cratefn blocking_queue_depth(&self) -> usize {
                match_flavor!(self, Handle(handle) => handle.blocking_queue_depth())
            }
        }
    }

    impl Context {
        #[track_caller]
        pub(cratefn expect_current_thread(&self) -> ¤t_thread::Context {
            match self {
                Context::CurrentThread(context) => context,
                #[cfg(feature = "rt-multi-thread")]
                _ => panic!("expected `CurrentThread::Context`")
            }
        }

        pub(cratefn defer(&self, waker: &Waker) {
            match_flavor!(self, Context(context) => context.defer(waker));
        }

        cfg_rt_multi_thread! {
            #[track_caller]
            pub(cratefn expect_multi_thread(&self) -> &multi_thread::Context {
                match self {
                    Context::MultiThread(context) => context,
                    _ => panic!("expected `MultiThread::Context`")
                }
            }

            cfg_unstable! {
                #[track_caller]
                pub(cratefn expect_multi_thread_alt(&self) -> &multi_thread_alt::Context {
                    match self {
                        Context::MultiThreadAlt(context) => context,
                        _ => panic!("expected `MultiThreadAlt::Context`")
                    }
                }
            }
        }
    }
}

cfg_not_rt! {
    #[cfg(any(
        feature = "net",
        all(unix, feature = "process"),
        all(unix, feature = "signal"),
        feature = "time",
    ))]
    impl Handle {
        #[track_caller]
        pub(cratefn current() -> Handle {
            panic!("{}"crate::util::error::CONTEXT_MISSING_ERROR)
        }
    }
}

Messung V0.5 in Prozent
C=80 H=97 G=88

¤ Dauer der Verarbeitung: 0.10 Sekunden  (vorverarbeitet am  2026-06-23) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik