diff a/cr-examples/onnx/src/main/java/oracle/code/onnx/foreign/OrtThreadPoolWorkStartFn.java b/cr-examples/onnx/src/main/java/oracle/code/onnx/foreign/OrtThreadPoolWorkStartFn.java --- /dev/null +++ b/cr-examples/onnx/src/main/java/oracle/code/onnx/foreign/OrtThreadPoolWorkStartFn.java @@ -0,0 +1,70 @@ +// Generated by jextract + +package oracle.code.onnx.foreign; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * typedef void (*OrtThreadPoolWorkStartFn)(void *, void *) + * } + */ +public final class OrtThreadPoolWorkStartFn { + + private OrtThreadPoolWorkStartFn() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + void apply(MemorySegment user_context, MemorySegment enqueue_data); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.ofVoid( + onnxruntime_c_api_h.C_POINTER, + onnxruntime_c_api_h.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = onnxruntime_c_api_h.upcallHandle(OrtThreadPoolWorkStartFn.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(OrtThreadPoolWorkStartFn.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static void invoke(MemorySegment funcPtr, MemorySegment user_context, MemorySegment enqueue_data) { + try { + DOWN$MH.invokeExact(funcPtr, user_context, enqueue_data); + } catch (Error | RuntimeException ex) { + throw ex; + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } +} +