use std::intrinsics::transmute;
use opencl_sys::{CL_QUEUED, CL_SUBMITTED, CL_RUNNING, CL_COMPLETE};
use crate::core::Error;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(i32)]
pub enum EventStatus {
Queued = CL_QUEUED,
Submitted = CL_SUBMITTED,
Running = CL_RUNNING,
Complete = CL_COMPLETE
}
impl EventStatus {
#[inline(always)]
pub const fn has_completed (&self) -> bool {
match self {
Self::Complete => true,
_ => false
}
}
#[inline(always)]
pub const fn is_running (&self) -> bool {
match self {
Self::Running => true,
_ => false
}
}
#[inline(always)]
pub const fn is_submitted (&self) -> bool {
match self {
Self::Submitted => true,
_ => false
}
}
#[inline(always)]
pub const fn is_queued (&self) -> bool {
match self {
Self::Queued => true,
_ => false
}
}
#[inline(always)]
pub const fn has_started_running (&self) -> bool {
(*self as i32) <= CL_RUNNING
}
#[inline(always)]
pub const fn has_submitted (&self) -> bool {
(*self as i32) <= CL_SUBMITTED
}
}
impl TryFrom<i32> for EventStatus {
type Error = Error;
#[inline(always)]
fn try_from(value: i32) -> Result<Self, Self::Error> {
if value < 0 {
return Err(Error::try_from(value).unwrap())
}
return unsafe { Ok(transmute(value)) }
}
}
impl Into<i32> for EventStatus {
#[inline(always)]
fn into(self) -> i32 {
self as i32
}
}