open_coroutine_hooks/
lib.rs

1#![deny(
2    // The following are allowed by default lints according to
3    // https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html
4    anonymous_parameters,
5    bare_trait_objects,
6    // box_pointers, // use box pointer to allocate on heap
7    // elided_lifetimes_in_paths, // allow anonymous lifetime
8    missing_copy_implementations,
9    missing_debug_implementations,
10    // missing_docs, // TODO: add documents
11    // single_use_lifetimes, // TODO: fix lifetime names only used once
12    // trivial_casts,
13    trivial_numeric_casts,
14    // unreachable_pub, allow clippy::redundant_pub_crate lint instead
15    // unsafe_code,
16    unstable_features,
17    unused_extern_crates,
18    unused_import_braces,
19    unused_qualifications,
20    unused_results,
21    variant_size_differences,
22
23    warnings, // treat all wanings as errors
24
25    clippy::all,
26    // clippy::restriction,
27    clippy::pedantic,
28    // clippy::nursery, // It's still under development
29    clippy::cargo,
30)]
31#![allow(
32    // Some explicitly allowed Clippy lints, must have clear reason to allow
33    clippy::blanket_clippy_restriction_lints, // allow clippy::restriction
34    clippy::implicit_return, // actually omitting the return keyword is idiomatic Rust code
35    clippy::module_name_repetitions, // repeation of module name in a struct name is not big deal
36    clippy::multiple_crate_versions, // multi-version dependency crates is not able to fix
37    clippy::missing_errors_doc, // TODO: add error docs
38    clippy::missing_panics_doc, // TODO: add panic docs
39    clippy::panic_in_result_fn,
40    clippy::shadow_same, // Not too much bad
41    clippy::shadow_reuse, // Not too much bad
42    clippy::exhaustive_enums,
43    clippy::exhaustive_structs,
44    clippy::indexing_slicing,
45    clippy::separated_literal_suffix, // conflicts with clippy::unseparated_literal_suffix
46    clippy::single_char_lifetime_names, // TODO: change lifetime names
47)]
48
49use open_coroutine_core::net::config::Config;
50use open_coroutine_core::net::event_loop::EventLoops;
51
52#[no_mangle]
53pub extern "C" fn init_config(config: Config) {
54    //一方面保证hook的函数能够被重定向到(防止压根不调用coroutine_crate的情况)
55    //另一方面初始化EventLoop配置
56    _ = Config::get_instance()
57        .set_event_loop_size(config.get_event_loop_size())
58        .set_stack_size(config.get_stack_size())
59        .set_min_size(config.get_min_size())
60        .set_max_size(config.get_max_size())
61        .set_keep_alive_time(config.get_keep_alive_time());
62    open_coroutine_core::warn!("open-coroutine inited with {config:#?}");
63}
64
65#[no_mangle]
66pub extern "C" fn shutdowns() {
67    EventLoops::stop();
68}
69
70pub mod coroutine;
71
72pub mod task;
73
74#[allow(dead_code, clippy::not_unsafe_ptr_arg_deref, clippy::similar_names)]
75#[cfg(unix)]
76pub mod unix;
77
78#[allow(dead_code, clippy::not_unsafe_ptr_arg_deref, clippy::similar_names)]
79#[cfg(windows)]
80mod windows;