mirror of
https://github.com/ivall/xcl.git
synced 2026-11-24 05:14:57 +01:00
XAsyncSchedule: a terminated queue takes no new work either
Like XTaskQueueSubmitDelayedCallback since #57 (libHttpClient schedules through it): E_ABORT, so XAsyncRun / XCL's own operations on a terminated queue fail through the block (#56) and their work never runs. Test async_work_on_a_terminated_queue_is_aborted; the task queue module comment follows #54 / #57.
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
//!
|
||||
//! Dispatch modes: Manual (caller pumps `XTaskQueueDispatch`), ThreadPool,
|
||||
//! SerializedThreadPool (pool, one at a time) and Immediate (run on the submitting
|
||||
//! thread). Callbacks submitted after `XTaskQueueTerminate` run with `canceled = true`.
|
||||
//! thread). `XTaskQueueTerminate` runs the queue's pending callbacks (delayed ones included)
|
||||
//! with `canceled = true` before its own callback; after it the queue takes no new work
|
||||
//! (`E_ABORT`, like libHttpClient's `VerifyNotTerminated`).
|
||||
//!
|
||||
//! Ports are reference-counted (`Arc<Port>`) so composite queues created via
|
||||
//! `XTaskQueueGetPort` + `XTaskQueueCreateComposite` can share underlying work/completion
|
||||
@@ -213,6 +215,10 @@ impl Queue {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn is_terminated(&self) -> bool {
|
||||
self.terminated.load(Ordering::Acquire)
|
||||
}
|
||||
|
||||
fn done_one(&self) {
|
||||
if self.inflight.fetch_sub(1, Ordering::AcqRel) == 1 {
|
||||
let _g = self.idle.0.lock().unwrap();
|
||||
|
||||
@@ -250,6 +250,10 @@ pub unsafe extern "system" fn XAsyncSchedule(b: *mut XAsyncBlock, delay_ms: u32)
|
||||
let Some(q) = taskqueue::queue_from((*b).queue) else {
|
||||
return if (*b).queue.is_null() { taskqueue::E_NO_TASK_QUEUE } else { E_INVALIDARG };
|
||||
};
|
||||
// a terminated queue takes no new work (libHttpClient: XTaskQueueSubmitDelayedCallback)
|
||||
if q.is_terminated() {
|
||||
return E_ABORT;
|
||||
}
|
||||
taskqueue::submit_delayed(&q, PORT_WORK, delay_ms, Item { cb: do_work_cb as usize, ctx: b as usize });
|
||||
S_OK
|
||||
}
|
||||
@@ -727,4 +731,25 @@ mod tests {
|
||||
assert_eq!(XAsyncGetStatus(&mut b, true), 3);
|
||||
}
|
||||
}
|
||||
|
||||
/// A terminated queue takes no new async work: the call fails with E_ABORT through the
|
||||
/// block, and the work never runs.
|
||||
#[test]
|
||||
fn async_work_on_a_terminated_queue_is_aborted() {
|
||||
let _g = crate::hle::xgameruntime::xasync::ASYNC_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
|
||||
unsafe {
|
||||
let mut q = std::ptr::null_mut();
|
||||
assert_eq!(taskqueue::XTaskQueueCreate(taskqueue::MODE_THREAD_POOL, taskqueue::MODE_THREAD_POOL, &mut q), S_OK);
|
||||
assert_eq!(taskqueue::XTaskQueueTerminate(q, true, std::ptr::null_mut(), 0), S_OK);
|
||||
let mut b: XAsyncBlock = std::mem::zeroed();
|
||||
b.queue = q;
|
||||
assert_eq!(XAsyncRun(&mut b, run_work as usize), S_OK);
|
||||
assert_eq!(XAsyncGetStatus(&mut b, true), E_ABORT);
|
||||
let mut b: XAsyncBlock = std::mem::zeroed();
|
||||
b.queue = q;
|
||||
assert_eq!(begin_with(&mut b, 9, || -> Result<Vec<u8>, HRESULT> { panic!("work ran on a terminated queue") }), S_OK);
|
||||
assert_eq!(XAsyncGetStatus(&mut b, true), E_ABORT);
|
||||
taskqueue::XTaskQueueCloseHandle(q);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user