Use tokio tasks instead of threads

why is the github runner blocking on tests, it doesn't on my machine
This commit is contained in:
Ottatop 2024-04-20 21:25:53 -05:00
parent 931822976e
commit 6f6b91f4f8
2 changed files with 16 additions and 25 deletions

View file

@ -1,11 +1,10 @@
// SPDX-License-Identifier: GPL-3.0-or-later
use std::{
cell::RefCell,
hash::Hash,
sync::{
atomic::{AtomicU32, Ordering},
Arc, Mutex,
},
rc::Rc,
sync::atomic::{AtomicU32, Ordering},
};
use smithay::output::Output;
@ -64,31 +63,25 @@ impl Eq for TagInner {}
///
/// A window may have 0 or more tags, and you can display 0 or more tags
/// on each output at a time.
#[derive(Debug, Clone)]
pub struct Tag(Arc<Mutex<TagInner>>);
impl PartialEq for Tag {
fn eq(&self, other: &Self) -> bool {
Arc::ptr_eq(&self.0, &other.0)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Tag(Rc<RefCell<TagInner>>);
// RefCell Safety: These methods should never panic because they are all self-contained or Copy.
impl Tag {
pub fn id(&self) -> TagId {
self.0.lock().expect("tag already locked").id
self.0.borrow().id
}
pub fn name(&self) -> String {
self.0.lock().expect("tag already locked").name.clone()
self.0.borrow().name.clone()
}
pub fn active(&self) -> bool {
self.0.lock().expect("tag already locked").active
self.0.borrow().active
}
pub fn set_active(&self, active: bool, state: &mut State) {
self.0.lock().expect("tag already locked").active = active;
self.0.borrow_mut().active = active;
state.signal_state.tag_active.signal(|buf| {
buf.push_back(
@ -103,7 +96,7 @@ impl Tag {
impl Tag {
pub fn new(name: String) -> Self {
Self(Arc::new(Mutex::new(TagInner {
Self(Rc::new(RefCell::new(TagInner {
id: TagId::next(),
name,
active: false,

View file

@ -42,14 +42,9 @@ pub fn test_api(
let loop_signal = event_loop.get_signal();
let join_handle = std::thread::spawn(move || {
let res = std::panic::catch_unwind(|| {
test(sender);
});
let join_handle = tokio::task::spawn_blocking(move || {
test(sender);
loop_signal.stop();
if let Err(err) = res {
std::panic::resume_unwind(err);
}
});
event_loop.run(None, &mut state, |state| {
@ -71,7 +66,10 @@ pub fn test_api(
);
})?;
if let Err(err) = join_handle.join() {
if let Err(err) = tokio::task::block_in_place(|| {
let handle = tokio::runtime::Handle::current();
handle.block_on(join_handle)
}) {
panic!("{err:?}");
}