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 void (*OrtCustomJoinThreadFn)(OrtCustomThreadHandle)
18  * }
19  */
20 public class OrtCustomJoinThreadFn {
21 
22     OrtCustomJoinThreadFn() {
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         void apply(MemorySegment ort_custom_thread_handle);
31     }
32 
33     private static final FunctionDescriptor $DESC = FunctionDescriptor.ofVoid(
34         onnxruntime_c_api_h.C_POINTER
35     );
36 
37     /**
38      * The descriptor of this function pointer
39      */
40     public static FunctionDescriptor descriptor() {
41         return $DESC;
42     }
43 
44     private static final MethodHandle UP$MH = onnxruntime_c_api_h.upcallHandle(OrtCustomJoinThreadFn.Function.class, "apply", $DESC);
45 
46     /**
47      * Allocates a new upcall stub, whose implementation is defined by {@code fi}.
48      * The lifetime of the returned segment is managed by {@code arena}
49      */
50     public static MemorySegment allocate(OrtCustomJoinThreadFn.Function fi, Arena arena) {
51         return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
52     }
53 
54     private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);
55 
56     /**
57      * Invoke the upcall stub {@code funcPtr}, with given parameters
58      */
59     public static void invoke(MemorySegment funcPtr,MemorySegment ort_custom_thread_handle) {
60         try {
61              DOWN$MH.invokeExact(funcPtr, ort_custom_thread_handle);
62         } catch (Throwable ex$) {
63             throw new AssertionError("should not reach here", ex$);
64         }
65     }
66 }
67