Skip to main content

sycl_rs_sys/
event-sys.rs

1//
2// Copyright (C) 2026 Intel Corporation
3//
4// Under the MIT License or the Apache License v2.0.
5// See LICENSE-MIT and LICENSE-APACHE for license information.
6// SPDX-License-Identifier: MIT OR Apache-2.0
7//
8
9use std::sync::{Arc, atomic::Ordering::Relaxed};
10
11use crate::types::SharedWaker;
12
13#[cxx::bridge(namespace = "sycl_shims::event")]
14pub mod ffi {
15    #[namespace = "sycl_shims"]
16    extern "C++" {
17        include!("sycl-rs-sys/src/types-sys.rs.h");
18        type EventCommandStatus = crate::types::ffi::EventCommandStatus;
19    }
20
21    unsafe extern "C++" {
22        include!("sycl-rs-sys/include/event.hpp");
23
24        #[namespace = "sycl_shims"]
25        type Event = crate::types::ffi::Event;
26
27        #[namespace = "sycl_shims"]
28        type Queue = crate::types::ffi::Queue;
29
30        fn wait(event: &mut UniquePtr<Event>) -> Result<()>;
31
32        unsafe fn register_callback(
33            queue: &mut UniquePtr<Queue>,
34            event: &Event,
35            waker: *const SharedWaker,
36        ) -> Result<()>;
37
38        fn get_command_execution_status(event: &Event) -> EventCommandStatus;
39        fn clone(event: &Event) -> UniquePtr<Event>;
40    }
41
42    extern "Rust" {
43        type SharedWaker;
44        unsafe fn wake(ptr: *const SharedWaker);
45    }
46}
47
48// Safety: SharedWaker must by a pointer created by Arc::into_raw. The caller must increment the
49// SharedWaker's strong reference count before calling.
50unsafe fn wake(ptr: *const SharedWaker) {
51    unsafe {
52        (*ptr).done.store(true, Relaxed);
53        (*ptr).waker.wake();
54        Arc::decrement_strong_count(ptr);
55    }
56}