use crate::error::{KunQuantError, Result};
use crate::ffi;
pub struct Executor {
handle: ffi::KunExecutorHandle,
}
impl Executor {
pub fn single_thread() -> Result<Self> {
let handle = unsafe { ffi::kunCreateSingleThreadExecutor() };
if handle.is_null() {
return Err(KunQuantError::ExecutorCreationFailed);
}
Ok(Executor { handle })
}
pub fn multi_thread(num_threads: i32) -> Result<Self> {
let handle = unsafe { ffi::kunCreateMultiThreadExecutor(num_threads) };
if handle.is_null() {
return Err(KunQuantError::ExecutorCreationFailed);
}
Ok(Executor { handle })
}
pub(crate) fn handle(&self) -> ffi::KunExecutorHandle {
self.handle
}
}
impl Drop for Executor {
fn drop(&mut self) {
if !self.handle.is_null() {
unsafe {
ffi::kunDestoryExecutor(self.handle);
}
}
}
}
unsafe impl Send for Executor {}
unsafe impl Sync for Executor {}