1 // Generated by jextract
 2 
 3 package oracle.code.onnx.foreign;
 4 
 5 import java.lang.invoke.*;
 6 import java.lang.foreign.*;
 7 import java.nio.ByteOrder;
 8 import java.util.*;
 9 import java.util.function.*;
10 import java.util.stream.*;
11 
12 import static java.lang.foreign.ValueLayout.*;
13 import static java.lang.foreign.MemoryLayout.PathElement.*;
14 
15 /**
16  * {@snippet lang=c :
17  * typedef OrtCustomThreadHandle (*OrtCustomCreateThreadFn)(void *, OrtThreadWorkerFn, void *)
18  * }
19  */
20 public class OrtCustomCreateThreadFn {
21 
22     OrtCustomCreateThreadFn() {
23         // Should not be called directly
24     }
25 
26     /**
27      * The function pointer signature, expressed as a functional interface
28      */
29     public interface Function {
30         MemorySegment apply(MemorySegment ort_custom_thread_creation_options, MemorySegment ort_thread_worker_fn, MemorySegment ort_worker_fn_param);
31     }
32 
33     private static final FunctionDescriptor $DESC = FunctionDescriptor.of(
34         onnxruntime_c_api_h.C_POINTER,
35         onnxruntime_c_api_h.C_POINTER,
36         onnxruntime_c_api_h.C_POINTER,
37         onnxruntime_c_api_h.C_POINTER
38     );
39 
40     /**
41      * The descriptor of this function pointer
42      */
43     public static FunctionDescriptor descriptor() {
44         return $DESC;
45     }
46 
47     private static final MethodHandle UP$MH = onnxruntime_c_api_h.upcallHandle(OrtCustomCreateThreadFn.Function.class, "apply", $DESC);
48 
49     /**
50      * Allocates a new upcall stub, whose implementation is defined by {@code fi}.
51      * The lifetime of the returned segment is managed by {@code arena}
52      */
53     public static MemorySegment allocate(OrtCustomCreateThreadFn.Function fi, Arena arena) {
54         return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
55     }
56 
57     private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);
58 
59     /**
60      * Invoke the upcall stub {@code funcPtr}, with given parameters
61      */
62     public static MemorySegment invoke(MemorySegment funcPtr,MemorySegment ort_custom_thread_creation_options, MemorySegment ort_thread_worker_fn, MemorySegment ort_worker_fn_param) {
63         try {
64             return (MemorySegment) DOWN$MH.invokeExact(funcPtr, ort_custom_thread_creation_options, ort_thread_worker_fn, ort_worker_fn_param);
65         } catch (Throwable ex$) {
66             throw new AssertionError("should not reach here", ex$);
67         }
68     }
69 }
70