Skip to content

Commit

Permalink
Use parking_lot::const_recursive_mutex instead of lazy_static
Browse files Browse the repository at this point in the history
  • Loading branch information
thomcc committed Dec 6, 2020
1 parent 54ab45b commit c768fc4
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 12 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ bitflags = "1.0"
glium = { version = "0.28", default-features = false, optional = true }
gfx = { version = "0.18", optional = true }
imgui-sys = { version = "0.6.0", path = "imgui-sys" }
lazy_static = "1.1"
parking_lot = "0.11"

[features]
Expand Down
1 change: 0 additions & 1 deletion imgui-examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,9 @@ pub struct Context {
clipboard_ctx: Option<Box<ClipboardContext>>,
}

lazy_static! {
// This mutex needs to be used to guard all public functions that can affect the underlying
// Dear ImGui active context
static ref CTX_MUTEX: ReentrantMutex<()> = ReentrantMutex::new(());
}
// This mutex needs to be used to guard all public functions that can affect the underlying
// Dear ImGui active context
static CTX_MUTEX: ReentrantMutex<()> = parking_lot::const_reentrant_mutex(());

fn clear_current_context() {
unsafe {
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
pub extern crate imgui_sys as sys;
#[macro_use]
extern crate lazy_static;

use std::cell;
use std::ffi::CStr;
Expand Down
4 changes: 1 addition & 3 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ use std::ptr;

use crate::context::Context;

lazy_static! {
pub static ref TEST_MUTEX: ReentrantMutex<()> = ReentrantMutex::new(());
}
pub static TEST_MUTEX: ReentrantMutex<()> = parking_lot::const_reentrant_mutex(());

pub fn test_ctx() -> (ReentrantMutexGuard<'static, ()>, Context) {
let guard = TEST_MUTEX.lock();
Expand Down

0 comments on commit c768fc4

Please sign in to comment.