From f401a352f4930bc8c98ee63679fa111493018c4e Mon Sep 17 00:00:00 2001 From: Josh Watson Date: Sat, 6 Mar 2021 15:41:06 -0800 Subject: Implement BackgroundTask::running_tasks() --- rust/src/backgroundtask.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'rust/src') diff --git a/rust/src/backgroundtask.rs b/rust/src/backgroundtask.rs index 985b8a83..363b91a8 100644 --- a/rust/src/backgroundtask.rs +++ b/rust/src/backgroundtask.rs @@ -85,6 +85,15 @@ impl BackgroundTask { ) } } + + pub fn running_tasks() -> Array { + unsafe { + let mut count = 0; + let handles = BNGetRunningBackgroundTasks(&mut count); + + Array::new(handles, count, ()) + } + } } unsafe impl RefCountable for BackgroundTask { @@ -99,6 +108,23 @@ unsafe impl RefCountable for BackgroundTask { } } +unsafe impl CoreOwnedArrayProvider for BackgroundTask { + type Raw = *mut BNBackgroundTask; + type Context = (); + + unsafe fn free(raw: *mut *mut BNBackgroundTask, count: usize, _context: &()) { + BNFreeBackgroundTaskList(raw, count); + } +} + +unsafe impl<'a> CoreOwnedArrayWrapper<'a> for BackgroundTask { + type Wrapped = Guard<'a, BackgroundTask>; + + unsafe fn wrap_raw(raw: &'a *mut BNBackgroundTask, context: &'a ()) -> Guard<'a, BackgroundTask> { + Guard::new(BackgroundTask::from_raw(*raw), context) + } +} + impl AsRef for BackgroundTask { fn as_ref(&self) -> &Self { self -- cgit v1.3.1