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.
impl Map
Implementation of the Map
struct.
Sourcepub fn execute(&self, args: &Vec<ArgInfo_t>) -> bool
pub fn execute(&self, args: &Vec<ArgInfo_t>) -> bool
Executes with the given arguments. This is called in execute! macro.
§Arguments
args
- A vector ofArgInfo_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.
Sourcepub fn synchronize(&self) -> bool
pub fn synchronize(&self) -> bool
Sourcepub fn set_stream(&mut self, stream: &Stream)
pub fn set_stream(&mut self, stream: &Stream)
Sourcepub fn set_success_callback(
&self,
callback: *mut c_void,
user_data: *mut c_void,
)
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);
Sourcepub fn set_error_callback(&self, callback: *mut c_void, user_data: *mut c_void)
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 ac_void
pointer.user_data
- User data as ac_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);
Sourcepub fn set_message_callback(
&self,
callback: *mut c_void,
user_data: *mut c_void,
)
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 ac_void
pointer.user_data
- User data as ac_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);