Skip to content

Commit

Permalink
Use std LazyLock
Browse files Browse the repository at this point in the history
  • Loading branch information
MolotovCherry committed Jul 27, 2024
1 parent 477965a commit f5c8d03
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 50 deletions.
1 change: 1 addition & 0 deletions rust/driver-ipc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "driver-ipc"
version = "0.1.0"
edition = "2021"
rust-version = "1.80"

[dependencies]
log = "0.4.22"
Expand Down
1 change: 0 additions & 1 deletion rust/driver-ipc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ mod client;
mod core;
mod driver_client;
pub mod sync;
mod utils;

pub use client::Client;
pub use core::*;
Expand Down
4 changes: 2 additions & 2 deletions rust/driver-ipc/src/sync.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
mod client;
mod driver_client;

use std::sync::LazyLock;

pub use client::{Client, EventsSubscription};
pub use driver_client::DriverClient;

use tokio::runtime::{Builder, Runtime};

use crate::utils::LazyLock;

static RUNTIME: LazyLock<Runtime> = LazyLock::new(|| {
Builder::new_multi_thread()
.worker_threads(1)
Expand Down
21 changes: 0 additions & 21 deletions rust/driver-ipc/src/utils.rs

This file was deleted.

2 changes: 1 addition & 1 deletion rust/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[toolchain]
channel = "nightly-2024-07-05"
channel = "nightly-2024-07-26"
components = ["rustfmt", "clippy"]
targets = []
profile = "minimal"
23 changes: 0 additions & 23 deletions rust/virtual-display-driver/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,3 @@ macro_rules! debug {
}
};
}

// just a dependency-less lazy lock replacement until std stabilizes theirs
pub struct LazyLock<T, F = fn() -> T> {
data: ::std::sync::OnceLock<T>,
f: F,
}

impl<T, F> LazyLock<T, F> {
pub const fn new(f: F) -> LazyLock<T, F> {
Self {
data: ::std::sync::OnceLock::new(),
f,
}
}
}

impl<T> ::std::ops::Deref for LazyLock<T> {
type Target = T;

fn deref(&self) -> &Self::Target {
self.data.get_or_init(self.f)
}
}
4 changes: 2 additions & 2 deletions rust/virtual-display-driver/src/ipc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{
mem::size_of,
ptr::{addr_of_mut, NonNull},
sync::{Mutex, OnceLock},
sync::{LazyLock, Mutex, OnceLock},
thread,
};

Expand All @@ -26,7 +26,7 @@ use windows::Win32::{
System::SystemServices::SECURITY_DESCRIPTOR_REVISION1,
};

use crate::{context::DeviceContext, helpers::LazyLock};
use crate::context::DeviceContext;

pub static ADAPTER: OnceLock<AdapterObject> = OnceLock::new();
pub static MONITOR_MODES: LazyLock<Mutex<Vec<MonitorObject>>> =
Expand Down

0 comments on commit f5c8d03

Please sign in to comment.