Skip to content

Commit 81519f3

Browse files
ids1024bilelmoussaoui
authored andcommitted
gdk4-x11: Make assert_initialized_main_thread a no-op
GDK4 does not require initialization, and this was previously broken since `INITIALIZED` and `IS_MAIN_THREAD` were never set.
1 parent b801a72 commit 81519f3

File tree

1 file changed

+1
-34
lines changed

1 file changed

+1
-34
lines changed

gdk4-x11/src/rt.rs

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,10 @@
11
// Take a look at the license at the top of the repository in the LICENSE file.
22

3-
use std::cell::Cell;
4-
use std::sync::atomic::{AtomicBool, Ordering};
5-
6-
thread_local! {
7-
static IS_MAIN_THREAD: Cell<bool> = Cell::new(false)
8-
}
9-
10-
static INITIALIZED: AtomicBool = AtomicBool::new(false);
11-
123
macro_rules! assert_initialized_main_thread {
13-
() => {
14-
#[allow(unknown_lints)]
15-
#[allow(clippy::if_then_panic)]
16-
if !crate::rt::is_initialized_main_thread() {
17-
if crate::rt::is_initialized() {
18-
panic!("GDK may only be used from the main thread.");
19-
} else {
20-
panic!("GDK has not been initialized. Call `gtk::init` first.");
21-
}
22-
}
23-
};
4+
() => {};
245
}
256

267
/// No-op.
278
macro_rules! skip_assert_initialized {
289
() => {};
2910
}
30-
31-
/// Returns `true` if GDK has been initialized.
32-
#[inline]
33-
pub fn is_initialized() -> bool {
34-
skip_assert_initialized!();
35-
INITIALIZED.load(Ordering::Acquire)
36-
}
37-
38-
/// Returns `true` if GDK has been initialized and this is the main thread.
39-
#[inline]
40-
pub fn is_initialized_main_thread() -> bool {
41-
skip_assert_initialized!();
42-
IS_MAIN_THREAD.with(|c| c.get())
43-
}

0 commit comments

Comments
 (0)