Struct Map

Source
pub struct Map { /* private fields */ }
Expand description

Abstracts data-parallel computation based on a map operation for a given job.

This struct wraps a FFI pointer to the C++ pxl::runtime::Map class. It provides methods for executing parallel processing, synchronizing operations, and setting up asynchronous callbacks and stream.

Implementations§

Source§

impl Map

Implementation of the Map struct.

Source

pub fn new(ptr: *mut Map) -> Self

Creates a new Map wrapper from a raw FFI pointer. This is called in runtime wrapper APIs requiring an actual Map object.

§Arguments
  • ptr - A raw pointer to the underlying FFI Map object.
§Safety

Caller must ensure that ptr is valid and remains valid for the lifetime of Map.

Source

pub fn execute(&self, args: &Vec<ArgInfo_t>) -> bool

Executes with the given arguments. This is called in execute! macro.

§Arguments
  • args - A vector of ArgInfo_t objects representing the arguments to be passed.
§Returns

Execution status as a boolean.

§Safety

Caller must ensure that the args vector is valid and contains valid pointers.

§Example

Please refer to usage of execute! macro.

Source

pub fn synchronize(&self) -> bool

Synchronizes the Map operation after execute request.

§Returns

Synchronization status as a boolean.

§Safety

Caller must ensure that execution status returned from execute is valid.

§Example
let ret = map.synchronize();
Source

pub fn set_stream(&mut self, stream: &Stream)

Sets the Stream for Map object.

§Arguments
  • stream - A reference to the Stream object to be set.
§Example
let stream = pxl::runtime::create_stream();
map.set_stream(&stream);
Source

pub fn set_success_callback( &self, callback: *mut c_void, user_data: *mut c_void, )

Sets success callback function with user data.

§Arguments
  • callback - Callback function as a c_void pointer.
  • user_data - User data as a c_void pointer.
§Safety

Caller must ensure that the callback, user data remain valid for the lifetime of Map.

§Example
use std::ffi::c_void;
use std::sync::{
    atomic::{AtomicBool, Ordering},
    Arc,
};    ///
unsafe extern "C" fn success_callback(ptr: *mut c_void) {
    let flag = ptr as *const AtomicBool;
    println!("✅ Success callback called with ptr: {:?}", flag);
    (*flag).store(true, Ordering::SeqCst);
}
let done_flag = Arc::new(AtomicBool::new(false));
let done_ptr = Arc::into_raw(done_flag.clone()) as *mut c_void;
map.set_success_callback(success_callback as *mut c_void, done_ptr);
Source

pub fn set_error_callback(&self, callback: *mut c_void, user_data: *mut c_void)

Sets error callback function with user data.

§Arguments
  • callback - Callback function as a c_void pointer.
  • user_data - User data as a c_void pointer.
§Safety

Caller must ensure that the callback and user data remain valid for the lifetime of Map.

§Example
use std::ffi::c_void;
use std::sync::{
    atomic::{AtomicBool, Ordering},
    Arc,
};
unsafe extern "C" fn error_callback(ptr: *mut c_void) {
    let flag = ptr as *const AtomicBool;
    println!("❌ Error callback called with ptr: {:?}", flag);
    (*flag).store(true, Ordering::SeqCst);
}
let error_flag = Arc::new(AtomicBool::new(false));
let error_ptr = Arc::into_raw(error_flag.clone()) as *mut c_void;
map.set_error_callback(error_callback as *mut c_void, error_ptr);
Source

pub fn set_message_callback( &self, callback: *mut c_void, user_data: *mut c_void, )

Sets message callback function with user data.

§Arguments
  • callback - Callback function as a c_void pointer.
  • user_data - User data as a c_void pointer.
§Safety

Caller must ensure that the callback and user data remain valid for the lifetime of Map.

§Example
use std::ffi::c_void;
use std::sync::Arc;
unsafe extern "C" fn message_callback(ptr: *mut c_void) {
    println!("📩 Message callback called with ptr: {:?}", ptr);
}
let message_data = Arc::new(42); // Example user data
let message_ptr = Arc::into_raw(message_data.clone()) as *mut c_void;
map.set_message_callback(message_callback as *mut c_void, message_ptr);

Auto Trait Implementations§

§

impl Freeze for Map

§

impl RefUnwindSafe for Map

§

impl !Send for Map

§

impl !Sync for Map

§

impl Unpin for Map

§

impl UnwindSafe for Map

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.