use std::mem;
use std::ptr;
use std::slice;
use std::cell::Ref;
use std::fmt::Debug;
use crate::ffi::{cl_platform_id, cl_device_id, cl_context, cl_command_queue, cl_mem, cl_program,
cl_kernel, cl_event, cl_sampler, c_void};
use crate::{CommandExecutionStatus, OpenclVersion, PlatformInfo, DeviceInfo, DeviceInfoResult,
ContextInfo, ContextInfoResult, CommandQueueInfo, CommandQueueInfoResult, ProgramInfo,
ProgramInfoResult, KernelInfo, KernelInfoResult, Status, EventCallbackFn, OclPrm,
EventInfo, EventInfoResult, DeviceType};
use crate::error::{Result as OclCoreResult};
use crate::functions::{self, ApiFunction, VersionKind};
pub trait AsMem<T>
where T: OclPrm {
fn as_mem(&self) -> &Mem;
}
impl<'a, T, M> AsMem<T> for &'a M where T: OclPrm, M: AsMem<T> {
fn as_mem(&self) -> &Mem {
(**self).as_mem()
}
}
impl<'a, T, M> AsMem<T> for &'a mut M where T: OclPrm, M: AsMem<T> {
fn as_mem(&self) -> &Mem {
(**self).as_mem()
}
}
pub unsafe trait MemCmdRw {}
pub unsafe trait MemCmdAll {}
pub trait ClVersions {
fn device_versions(&self) -> OclCoreResult<Vec<OpenclVersion>>;
fn platform_version(&self) -> OclCoreResult<OpenclVersion>;
fn verify_device_versions(&self, required_version: [u16; 2]) -> OclCoreResult<()> {
functions::verify_versions(&r#try!(self.device_versions()), required_version,
ApiFunction::None, VersionKind::Device)
}
fn verify_platform_version(&self, required_version: [u16; 2]) -> OclCoreResult<()> {
let ver = [r#try!(self.platform_version())];
functions::verify_versions(&ver, required_version, ApiFunction::None,
VersionKind::Platform)
}
}
impl ClVersions for cl_context {
fn device_versions(&self) -> OclCoreResult<Vec<OpenclVersion>> {
let devices = match functions::get_context_info(self, ContextInfo::Devices) {
Ok(ContextInfoResult::Devices(ds)) => Ok(ds),
Err(err) => Err(err),
_ => unreachable!(),
};
let devices = match devices {
Ok(d) => d,
Err(e) => return Err(e),
};
functions::device_versions(&devices)
}
fn platform_version(&self) -> OclCoreResult<OpenclVersion> {
let devices = match functions::get_context_info(self, ContextInfo::Devices) {
Ok(ContextInfoResult::Devices(ds)) => Ok(ds),
Err(err) => Err(err),
_ => unreachable!(),
};
let devices = match devices {
Ok(d) => d,
Err(e) => return Err(e),
};
devices[0].platform_version()
}
}
pub unsafe trait ClEventPtrRef<'e> {
unsafe fn as_ptr_ref(&'e self) -> &'e cl_event;
}
unsafe impl<'e> ClEventPtrRef<'e> for &'e cl_event {
unsafe fn as_ptr_ref(&'e self) -> &'e cl_event {
self
}
}
unsafe impl<'e, L> ClEventPtrRef<'e> for &'e L where L: ClEventPtrRef<'e> {
unsafe fn as_ptr_ref(&'e self) -> &'e cl_event {
(*self).as_ptr_ref()
}
}
pub unsafe trait ClNullEventPtr: Debug {
fn alloc_new(&mut self) -> *mut cl_event;
unsafe fn clone_from<E: AsRef<Event>>(&mut self, ev: E);
}
unsafe impl ClNullEventPtr for () {
fn alloc_new(&mut self) -> *mut cl_event {
panic!("Void events may not be used.");
}
unsafe fn clone_from<E: AsRef<Event>>(&mut self, _: E) {
panic!("Void events may not be used.");
}
}
pub unsafe trait ClWaitListPtr: Debug {
unsafe fn as_ptr_ptr(&self) -> *const cl_event;
fn count (&self) -> u32;
}
unsafe impl<'a, W> ClWaitListPtr for Ref<'a, W> where W: ClWaitListPtr {
unsafe fn as_ptr_ptr(&self) -> *const cl_event {
(*(*self)).as_ptr_ptr()
}
fn count (&self) -> u32 {
0 as u32
}
}
unsafe impl<'a> ClWaitListPtr for &'a [cl_event] {
unsafe fn as_ptr_ptr(&self) -> *const cl_event {
self.as_ptr()
}
fn count (&self) -> u32 {
self.len() as u32
}
}
unsafe impl<'a> ClWaitListPtr for &'a [Event] {
unsafe fn as_ptr_ptr(&self) -> *const cl_event {
self.as_ptr() as *const _ as *const cl_event
}
fn count (&self) -> u32 {
self.len() as u32
}
}
unsafe impl<'a> ClWaitListPtr for () {
unsafe fn as_ptr_ptr(&self) -> *const cl_event {
ptr::null() as *const _ as *const cl_event
}
fn count (&self) -> u32 {
0 as u32
}
}
pub unsafe trait ClPlatformIdPtr: Debug + Copy {
fn as_ptr(&self) -> cl_platform_id;
}
unsafe impl<'a, P> ClPlatformIdPtr for &'a P where P: ClPlatformIdPtr {
fn as_ptr(&self) -> cl_platform_id {
(*self).as_ptr()
}
}
unsafe impl ClPlatformIdPtr for () {
fn as_ptr(&self) -> cl_platform_id {
ptr::null_mut() as *mut _ as cl_platform_id
}
}
pub unsafe trait ClDeviceIdPtr: Debug + Copy {
fn as_ptr(&self) -> cl_device_id;
}
unsafe impl ClDeviceIdPtr for () {
fn as_ptr(&self) -> cl_device_id {
ptr::null_mut() as *mut _ as cl_device_id
}
}
pub unsafe trait ClContextPtr: Debug + Copy {
fn as_ptr(&self) -> cl_context;
}
unsafe impl ClContextPtr for cl_context {
fn as_ptr(&self) -> cl_context {
*self
}
}
unsafe impl<'a> ClContextPtr for &'a cl_context {
fn as_ptr(&self) -> cl_context {
**self
}
}
#[repr(C)]
pub struct EventRefWrapper(cl_event);
impl EventRefWrapper {
pub unsafe fn new(ptr: cl_event) -> EventRefWrapper {
EventRefWrapper(ptr)
}
}
unsafe impl<'e> ClEventPtrRef<'e> for EventRefWrapper {
unsafe fn as_ptr_ref(&'e self) -> &'e cl_event {
&self.0
}
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
pub struct PlatformId(cl_platform_id);
impl PlatformId {
pub unsafe fn from_raw(ptr: cl_platform_id) -> PlatformId {
PlatformId(ptr)
}
pub unsafe fn null() -> PlatformId {
PlatformId(ptr::null_mut())
}
pub fn as_ptr(&self) -> cl_platform_id {
self.0
}
pub fn version(&self) -> OclCoreResult<OpenclVersion> {
if !self.0.is_null() {
functions::get_platform_info(self, PlatformInfo::Version)?.as_opencl_version()
} else {
Err("PlatformId::version(): This platform_id is invalid.".into())
}
}
}
unsafe impl ClPlatformIdPtr for PlatformId {
fn as_ptr(&self) -> cl_platform_id {
self.0
}
}
unsafe impl Sync for PlatformId {}
unsafe impl Send for PlatformId {}
impl ClVersions for PlatformId {
fn device_versions(&self) -> OclCoreResult<Vec<OpenclVersion>> {
let devices = r#try!(functions::get_device_ids(self, Some(DeviceType::ALL), None));
functions::device_versions(&devices)
}
fn platform_version(&self) -> OclCoreResult<OpenclVersion> {
self.version()
}
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
pub struct DeviceId(cl_device_id);
impl DeviceId {
pub unsafe fn from_raw(ptr: cl_device_id) -> DeviceId {
assert!(!ptr.is_null(), "Null pointer passed.");
DeviceId(ptr)
}
pub unsafe fn null() -> DeviceId {
DeviceId(ptr::null_mut())
}
pub fn as_raw(&self) -> cl_device_id {
self.0
}
pub fn version(&self) -> OclCoreResult<OpenclVersion> {
if !self.0.is_null() {
functions::get_device_info(self, DeviceInfo::Version)?.as_opencl_version()
} else {
Err("DeviceId::device_versions(): This device_id is invalid.".into())
}
}
}
unsafe impl ClDeviceIdPtr for DeviceId {
fn as_ptr(&self) -> cl_device_id {
self.0
}
}
unsafe impl<'a> ClDeviceIdPtr for &'a DeviceId {
fn as_ptr(&self) -> cl_device_id {
self.0
}
}
unsafe impl Sync for DeviceId {}
unsafe impl Send for DeviceId {}
impl ClVersions for DeviceId {
fn device_versions(&self) -> OclCoreResult<Vec<OpenclVersion>> {
self.version().map(|dv| vec![dv])
}
fn platform_version(&self) -> OclCoreResult<OpenclVersion> {
let platform = match functions::get_device_info(self, DeviceInfo::Platform) {
Ok(DeviceInfoResult::Platform(p)) => p,
Err(err) => return Err(err),
_ => unreachable!(),
};
functions::get_platform_info(&platform, PlatformInfo::Version)?.as_opencl_version()
}
}
#[repr(C)]
#[derive(Debug)]
pub struct Context(cl_context);
impl Context {
pub unsafe fn from_raw_create_ptr(ptr: cl_context) -> Context {
assert!(!ptr.is_null(), "Null pointer passed.");
Context(ptr)
}
pub unsafe fn from_raw_copied_ptr(ptr: cl_context) -> Context {
assert!(!ptr.is_null(), "Null pointer passed.");
let copy = Context(ptr);
functions::retain_context(©).unwrap();
copy
}
pub fn as_ptr(&self) -> cl_context {
self.0
}
pub fn devices(&self) -> OclCoreResult<Vec<DeviceId>> {
match functions::get_context_info(self, ContextInfo::Devices) {
Ok(ContextInfoResult::Devices(ds)) => Ok(ds),
Err(err) => Err(err),
_ => unreachable!(),
}
}
pub fn platform(&self) -> OclCoreResult<Option<PlatformId>> {
functions::get_context_platform(self)
}
}
unsafe impl Sync for Context {}
unsafe impl Send for Context {}
impl Clone for Context {
fn clone(&self) -> Context {
unsafe { functions::retain_context(self).unwrap(); }
Context(self.0)
}
}
impl Drop for Context {
fn drop(&mut self) {
unsafe {
if let Err(e) = functions::release_context(self as &Context) {
if let Some(Status::CL_INVALID_CONTEXT) = e.api_status() {
return;
}
panic!("{:?}", e);
}
}
}
}
impl PartialEq<Context> for Context {
fn eq(&self, other: &Context) -> bool {
self.0 == other.0
}
}
unsafe impl<'a> ClContextPtr for &'a Context {
fn as_ptr(&self) -> cl_context {
self.0
}
}
impl ClVersions for Context {
fn device_versions(&self) -> OclCoreResult<Vec<OpenclVersion>> {
let devices = r#try!(self.devices());
functions::device_versions(&devices)
}
fn platform_version(&self) -> OclCoreResult<OpenclVersion> {
let devices = r#try!(self.devices());
devices[0].platform_version()
}
}
impl<'a> ClVersions for &'a Context {
fn device_versions(&self) -> OclCoreResult<Vec<OpenclVersion>> {
(*self).device_versions()
}
fn platform_version(&self) -> OclCoreResult<OpenclVersion> {
(*self).platform_version()
}
}
#[repr(C)]
#[derive(Debug)]
pub struct CommandQueue(cl_command_queue);
impl CommandQueue {
pub unsafe fn from_raw_create_ptr(ptr: cl_command_queue) -> CommandQueue {
assert!(!ptr.is_null(), "Null pointer passed.");
CommandQueue(ptr)
}
pub unsafe fn from_raw_copied_ptr(ptr: cl_command_queue) -> CommandQueue {
assert!(!ptr.is_null(), "Null pointer passed.");
let copy = CommandQueue(ptr);
functions::retain_command_queue(©).unwrap();
copy
}
pub fn as_ptr(&self) -> cl_command_queue {
self.0
}
pub fn device(&self) -> OclCoreResult<DeviceId> {
match functions::get_command_queue_info(self, CommandQueueInfo::Device) {
Ok(CommandQueueInfoResult::Device(d)) => Ok(d),
Err(err) => Err(err),
_ => unreachable!(),
}
}
pub fn context(&self) -> OclCoreResult<Context> {
self.context_ptr().map(|ptr| unsafe { Context::from_raw_copied_ptr(ptr) })
}
pub fn context_ptr(&self) -> OclCoreResult<cl_context> {
functions::get_command_queue_context_ptr(self)
}
}
impl Clone for CommandQueue {
fn clone(&self) -> CommandQueue {
unsafe { functions::retain_command_queue(self).unwrap(); }
CommandQueue(self.0)
}
}
impl Drop for CommandQueue {
fn drop(&mut self) {
unsafe { functions::release_command_queue(self).unwrap(); }
}
}
impl AsRef<CommandQueue> for CommandQueue {
fn as_ref(&self) -> &CommandQueue {
self
}
}
unsafe impl<'a> ClContextPtr for &'a CommandQueue {
fn as_ptr(&self) -> cl_context {
self.context_ptr().expect("<&CommandQueue as ClContextPtr>::as_ptr: \
Unable to obtain a context pointer.")
}
}
unsafe impl Sync for CommandQueue {}
unsafe impl Send for CommandQueue {}
impl ClVersions for CommandQueue{
fn device_versions(&self) -> OclCoreResult<Vec<OpenclVersion>> {
let device = r#try!(self.device());
device.version().map(|dv| vec![dv])
}
fn platform_version(&self) -> OclCoreResult<OpenclVersion> {
r#try!(self.device()).platform_version()
}
}
#[repr(C)]
#[derive(Debug)]
pub struct Mem(cl_mem);
impl Mem {
pub unsafe fn from_raw_create_ptr(ptr: cl_mem) -> Mem {
assert!(!ptr.is_null(), "Null pointer passed.");
Mem(ptr)
}
pub unsafe fn from_raw_copied_ptr(ptr: cl_mem) -> Mem {
assert!(!ptr.is_null(), "Null pointer passed.");
let copy = Mem(ptr);
functions::retain_mem_object(©).unwrap();
copy
}
#[inline(always)]
pub fn as_ptr(&self) -> cl_mem {
self.0
}
}
impl Clone for Mem {
fn clone(&self) -> Mem {
unsafe { functions::retain_mem_object(self).unwrap(); }
Mem(self.0)
}
}
impl Drop for Mem {
fn drop(&mut self) {
unsafe { functions::release_mem_object(self).unwrap(); }
}
}
impl<T: OclPrm> AsMem<T> for Mem {
#[inline(always)]
fn as_mem(&self) -> &Mem {
self
}
}
unsafe impl<'a> MemCmdRw for Mem {}
unsafe impl<'a> MemCmdRw for &'a Mem {}
unsafe impl<'a> MemCmdRw for &'a mut Mem {}
unsafe impl<'a> MemCmdRw for &'a &'a Mem {}
unsafe impl<'a> MemCmdRw for &'a &'a mut Mem {}
unsafe impl<'a> MemCmdAll for Mem {}
unsafe impl<'a> MemCmdAll for &'a Mem {}
unsafe impl<'a> MemCmdAll for &'a mut Mem {}
unsafe impl<'a> MemCmdAll for &'a &'a Mem {}
unsafe impl<'a> MemCmdAll for &'a &'a mut Mem {}
unsafe impl Sync for Mem {}
unsafe impl Send for Mem {}
#[repr(C)]
#[derive(Debug)]
pub struct MemMap<T>(*mut T);
impl<T: OclPrm> MemMap<T> {
#[inline(always)]
pub unsafe fn from_raw(ptr: *mut T) -> MemMap<T> {
assert!(!ptr.is_null(), "MemMap::from_raw: Null pointer passed.");
MemMap(ptr)
}
#[inline(always)]
pub fn as_ptr(&self) -> *const T {
self.0
}
#[inline(always)]
pub fn as_mut_ptr(&mut self) -> *mut T {
self.0
}
#[inline(always)]
pub fn as_void_ptr(&self) -> *mut c_void {
self.0 as *mut _ as *mut c_void
}
#[inline(always)]
pub unsafe fn as_slice<'a>(&self, len: usize) -> &'a [T] {
slice::from_raw_parts(self.0, len)
}
#[inline(always)]
pub unsafe fn as_slice_mut<'a>(&mut self, len: usize) -> &'a mut [T] {
slice::from_raw_parts_mut(self.0, len)
}
}
impl<T> AsMem<T> for MemMap<T> where T: OclPrm {
#[inline(always)]
fn as_mem(&self) -> &Mem {
unsafe { &*(self as *const _ as *const Mem) }
}
}
unsafe impl<T: OclPrm> MemCmdRw for MemMap<T> {}
unsafe impl<'a, T: OclPrm> MemCmdRw for &'a MemMap<T> {}
unsafe impl<'a, T: OclPrm> MemCmdRw for &'a mut MemMap<T> {}
unsafe impl<T: OclPrm> Send for MemMap<T> {}
#[repr(C)]
#[derive(Debug)]
pub struct Program(cl_program);
impl Program {
pub unsafe fn from_raw_create_ptr(ptr: cl_program) -> Program {
assert!(!ptr.is_null(), "Null pointer passed.");
Program(ptr)
}
pub unsafe fn from_raw_copied_ptr(ptr: cl_program) -> Program {
assert!(!ptr.is_null(), "Null pointer passed.");
let copy = Program(ptr);
functions::retain_program(©).unwrap();
copy
}
#[inline(always)]
pub fn as_ptr(&self) -> cl_program {
self.0
}
pub fn devices(&self) -> OclCoreResult<Vec<DeviceId>> {
match functions::get_program_info(self, ProgramInfo::Devices) {
Ok(ProgramInfoResult::Devices(d)) => Ok(d),
Err(err) => Err(err),
_ => unreachable!(),
}
}
}
impl Clone for Program {
fn clone(&self) -> Program {
unsafe { functions::retain_program(self).unwrap(); }
Program(self.0)
}
}
impl Drop for Program {
fn drop(&mut self) {
unsafe { functions::release_program(self).unwrap(); }
}
}
unsafe impl Sync for Program {}
unsafe impl Send for Program {}
impl ClVersions for Program {
fn device_versions(&self) -> OclCoreResult<Vec<OpenclVersion>> {
let devices = r#try!(self.devices());
functions::device_versions(&devices)
}
fn platform_version(&self) -> OclCoreResult<OpenclVersion> {
let devices = r#try!(self.devices());
devices[0].platform_version()
}
}
#[repr(C)]
#[derive(Debug)]
pub struct Kernel(cl_kernel);
impl Kernel {
pub unsafe fn from_raw_create_ptr(ptr: cl_kernel) -> Kernel {
assert!(!ptr.is_null(), "Null pointer passed.");
Kernel(ptr)
}
pub unsafe fn from_raw_copied_ptr(ptr: cl_kernel) -> Kernel {
assert!(!ptr.is_null(), "Null pointer passed.");
let copy = Kernel(ptr);
functions::retain_kernel(©).unwrap();
copy
}
#[inline(always)]
pub fn as_ptr(&self) -> cl_kernel {
self.0
}
pub fn program(&self) -> OclCoreResult<Program> {
match functions::get_kernel_info(self, KernelInfo::Program) {
Ok(KernelInfoResult::Program(d)) => Ok(d),
Err(err) => Err(err),
_ => unreachable!(),
}
}
pub fn devices(&self) -> OclCoreResult<Vec<DeviceId>> {
self.program().and_then(|p| p.devices())
}
}
impl Clone for Kernel {
fn clone(&self) -> Kernel {
unsafe { functions::retain_kernel(self).unwrap(); }
Kernel(self.0)
}
}
impl Drop for Kernel {
fn drop(&mut self) {
unsafe { functions::release_kernel(self).unwrap(); }
}
}
impl ClVersions for Kernel {
fn device_versions(&self) -> OclCoreResult<Vec<OpenclVersion>> {
let devices = r#try!(r#try!(self.program()).devices());
functions::device_versions(&devices)
}
fn platform_version(&self) -> OclCoreResult<OpenclVersion> {
let devices = r#try!(r#try!(self.program()).devices());
devices[0].platform_version()
}
}
unsafe impl Send for Kernel {}
#[repr(C)]
#[derive(Debug, Hash, PartialEq, Eq)]
pub struct Event(cl_event);
impl Event {
#[inline]
pub fn null() -> Event {
Event(0 as cl_event)
}
#[inline]
pub fn user<C: ClContextPtr>(context: C) -> OclCoreResult<Event> {
functions::create_user_event(context)
}
#[inline]
pub unsafe fn from_raw_create_ptr(ptr: cl_event) -> Event {
assert!(!ptr.is_null(), "ocl_core::Event::from_raw_create_ptr: Null pointer passed.");
Event(ptr)
}
#[inline]
pub unsafe fn from_raw_copied_ptr(ptr: cl_event) -> OclCoreResult<Event> {
assert!(!ptr.is_null(), "ocl_core::Event::from_raw_copied_ptr: Null pointer passed.");
let copy = Event(ptr);
functions::retain_event(©)?;
Ok(copy)
}
#[inline]
pub fn set_complete(&self) -> OclCoreResult<()> {
functions::set_user_event_status(self, CommandExecutionStatus::Complete)
}
#[inline]
pub fn is_complete(&self) -> OclCoreResult<bool> {
functions::event_is_complete(self)
}
#[inline]
pub fn wait_for(&self) -> OclCoreResult <()> {
crate::wait_for_event(self)
}
#[inline]
pub fn is_null(&self) -> bool {
self.0.is_null()
}
#[inline]
pub fn is_valid(&self) -> bool {
!self.0.is_null()
}
pub unsafe fn set_callback(&self,
callback_receiver: EventCallbackFn,
user_data_ptr: *mut c_void,
) -> OclCoreResult<()>
{
if self.is_valid() {
crate::set_event_callback(self, CommandExecutionStatus::Complete,
Some(callback_receiver), user_data_ptr as *mut _ as *mut c_void)
} else {
Err("ocl_core::Event::set_callback: This event is null. Cannot set callback until \
internal event pointer is actually created by a `clCreate...` function.".into())
}
}
pub fn context(&self) -> OclCoreResult<Context> {
match functions::get_event_info(self, EventInfo::Context) {
Ok(EventInfoResult::Context(c)) => Ok(c),
Err(err) => Err(err),
_ => unreachable!(),
}
}
#[inline]
pub unsafe fn as_ptr_ref(&self) -> &cl_event {
&self.0
}
#[inline]
pub unsafe fn as_ptr_mut(&mut self) -> &mut cl_event {
&mut self.0
}
pub fn into_raw(self) -> cl_event {
let ptr = self.0;
mem::forget(self);
ptr
}
#[inline]
pub unsafe fn from_raw(ptr: cl_event) -> Event {
assert!(!ptr.is_null(), "Null pointer passed.");
Event(ptr)
}
fn _alloc_new(&mut self) -> *mut cl_event {
assert!(self.0.is_null(), "ocl_core::Event::alloc_new: An 'Event' cannot be \
used as target for event creation (as a new event) more than once.");
&mut self.0
}
unsafe fn _as_ptr_ptr(&self) -> *const cl_event {
if self.0.is_null() { ptr::null() } else { &self.0 as *const cl_event }
}
fn _count(&self) -> u32 {
if self.0.is_null() { 0 } else { 1 }
}
}
unsafe impl<'a> ClNullEventPtr for &'a mut Event {
#[inline(always)] fn alloc_new(&mut self) -> *mut cl_event { self._alloc_new() }
#[inline(always)] unsafe fn clone_from<E: AsRef<Event>>(&mut self, ev: E) {
let ptr = ev.as_ref().clone().into_raw();
assert!(!ptr.is_null());
self.0 = ptr;
}
}
unsafe impl ClWaitListPtr for Event {
#[inline(always)] unsafe fn as_ptr_ptr(&self) -> *const cl_event { self._as_ptr_ptr() }
#[inline(always)] fn count(&self) -> u32 { self._count() }
}
unsafe impl<'a> ClWaitListPtr for &'a Event {
#[inline(always)] unsafe fn as_ptr_ptr(&self) -> *const cl_event { self._as_ptr_ptr() }
#[inline(always)] fn count(&self) -> u32 { self._count() }
}
unsafe impl<'e> ClEventPtrRef<'e> for Event {
#[inline(always)] unsafe fn as_ptr_ref(&'e self) -> &'e cl_event { &self.0 }
}
impl AsRef<Event> for Event {
fn as_ref(&self) -> &Event {
self
}
}
impl Clone for Event {
fn clone(&self) -> Event {
assert!(!self.0.is_null(), "ocl_core::Event::clone: \
Cannot clone a null (empty) event.");
unsafe { functions::retain_event(self).expect("core::Event::clone"); }
Event(self.0)
}
}
impl Drop for Event {
fn drop(&mut self) {
if !self.0.is_null() {
unsafe { functions::release_event(self).unwrap(); }
}
}
}
unsafe impl Sync for Event {}
unsafe impl Send for Event {}
#[repr(C)]
#[derive(Debug)]
pub struct Sampler(cl_sampler);
impl Sampler {
pub unsafe fn from_raw_create_ptr(ptr: cl_sampler) -> Sampler {
assert!(!ptr.is_null(), "Null pointer passed.");
Sampler(ptr)
}
pub unsafe fn as_ptr(&self) -> cl_sampler {
self.0
}
}
impl Clone for Sampler {
fn clone(&self) -> Sampler {
unsafe { functions::retain_sampler(self).unwrap(); }
Sampler(self.0)
}
}
impl Drop for Sampler {
fn drop(&mut self) {
unsafe { functions::release_sampler(self).unwrap(); }
}
}
unsafe impl Sync for Sampler {}
unsafe impl Send for Sampler {}