Thread check improvement
This commit is contained in:
parent
3d8dcba9e6
commit
211ef0de58
15
src/ui.rs
15
src/ui.rs
@ -188,7 +188,7 @@ fn gtk_delete(comps: &UiMutex<Components>, shell: &RefCell<Shell>) -> Inhibit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct UiMutex<T: ?Sized> {
|
pub struct UiMutex<T: ?Sized> {
|
||||||
thread: String,
|
thread: thread::ThreadId,
|
||||||
data: RefCell<T>,
|
data: RefCell<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,10 +198,7 @@ unsafe impl<T: ?Sized> Sync for UiMutex<T> {}
|
|||||||
impl<T> UiMutex<T> {
|
impl<T> UiMutex<T> {
|
||||||
pub fn new(t: T) -> UiMutex<T> {
|
pub fn new(t: T) -> UiMutex<T> {
|
||||||
UiMutex {
|
UiMutex {
|
||||||
thread: thread::current()
|
thread: thread::current().id(),
|
||||||
.name()
|
|
||||||
.expect("Can create UI only from main thread, current thiread has no name")
|
|
||||||
.to_owned(),
|
|
||||||
data: RefCell::new(t),
|
data: RefCell::new(t),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -220,12 +217,8 @@ impl<T: ?Sized> UiMutex<T> {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn assert_ui_thread(&self) {
|
fn assert_ui_thread(&self) {
|
||||||
match thread::current().name() {
|
if thread::current().id() != self.thread {
|
||||||
Some(name) if name == self.thread => (),
|
panic!("Can access to UI only from main thread");
|
||||||
Some(name) => {
|
|
||||||
panic!("Can create UI only from main thread, {}", name);
|
|
||||||
}
|
|
||||||
None => panic!("Can create UI only from main thread, current thread has no name"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user