mirror of
https://github.com/Cuprate/cuprate.git
synced 2025-01-11 05:15:24 +00:00
add statics.rs
This commit is contained in:
parent
726a9f244b
commit
35065b7866
2 changed files with 48 additions and 1 deletions
|
@ -17,9 +17,13 @@ mod blockchain;
|
||||||
mod config;
|
mod config;
|
||||||
mod p2p;
|
mod p2p;
|
||||||
mod rpc;
|
mod rpc;
|
||||||
|
mod statics;
|
||||||
mod txpool;
|
mod txpool;
|
||||||
mod version;
|
mod version;
|
||||||
|
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
todo!()
|
// Initialize global static `LazyLock` data.
|
||||||
|
statics::init_lazylock_statics();
|
||||||
}
|
}
|
||||||
|
|
43
binaries/cuprated/src/statics.rs
Normal file
43
binaries/cuprated/src/statics.rs
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
//! Global `static`s used throughout `cuprated`.
|
||||||
|
|
||||||
|
use std::{
|
||||||
|
sync::{atomic::AtomicU64, LazyLock},
|
||||||
|
time::{SystemTime, UNIX_EPOCH},
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Define all the `static`s in the file/module.
|
||||||
|
///
|
||||||
|
/// This wraps all `static` inside a `LazyLock` and creates a
|
||||||
|
/// [`init_lazylock_statics`] function that must/should be
|
||||||
|
/// used by `main()` early on.
|
||||||
|
macro_rules! define_lazylock_statics {
|
||||||
|
($(
|
||||||
|
$( #[$attr:meta] )*
|
||||||
|
$name:ident: $t:ty = $init_fn:expr;
|
||||||
|
)*) => {
|
||||||
|
/// Initialize global static `LazyLock` data.
|
||||||
|
pub fn init_lazylock_statics() {
|
||||||
|
$(
|
||||||
|
LazyLock::force(&$name);
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
|
||||||
|
$(
|
||||||
|
$(#[$attr])*
|
||||||
|
pub static $name: LazyLock<$t> = LazyLock::new(|| $init_fn);
|
||||||
|
)*
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
define_lazylock_statics! {
|
||||||
|
/// The start time of `cuprated`.
|
||||||
|
///
|
||||||
|
/// This must/should be set early on in `main()`.
|
||||||
|
START_INSTANT: SystemTime = SystemTime::now();
|
||||||
|
|
||||||
|
/// Start time of `cuprated` as a UNIX timestamp.
|
||||||
|
START_INSTANT_UNIX: u64 = START_INSTANT
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.expect("Failed to set `cuprated` startup time.")
|
||||||
|
.as_secs();
|
||||||
|
}
|
Loading…
Reference in a new issue