Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "JsiMain.h"
#include <ReactCommon/CallInvoker.h>
#include <ReactCommon/CallInvokerHolder.h>
#include <fbjni/detail/Registration.h>
#include <fbjni/fbjni.h>
#include <jni.h>
#include <jsi/jsi.h>
#include <memory>
 
using namespace facebook;
 
class OnnxruntimeModule
    : public jni::JavaClass<OnnxruntimeModule> {
 public:
  static constexpr auto kJavaDescriptor =
      "Lai/onnxruntime/reactnative/OnnxruntimeModule;";
 
  static void registerNatives() {
    javaClassStatic()->registerNatives(
        {makeNativeMethod("nativeInstall",
                          OnnxruntimeModule::nativeInstall),
         makeNativeMethod("nativeCleanup",
                          OnnxruntimeModule::nativeCleanup)});
  }
 
 private:
  static jlong nativeInstall(
      jni::alias_ref<jni::JObject> thiz, jlong jsContextNativePointer,
      jni::alias_ref<react::CallInvokerHolder::javaobject>
          jsCallInvokerHolder) {
    auto runtime = reinterpret_cast<jsi::Runtime*>(jsContextNativePointer);
    auto jsCallInvoker = jsCallInvokerHolder->cthis()->getCallInvoker();
    auto env = onnxruntimejsi::install(*runtime, jsCallInvoker);
    return reinterpret_cast<jlong>(
        new std::shared_ptr<onnxruntimejsi::Env>(std::move(env)));
  }
 
  static void nativeCleanup(jni::alias_ref<jni::JObject> thiz,
                            jlong envHandle) {
    auto env = std::unique_ptr<std::shared_ptr<onnxruntimejsi::Env>>(
        reinterpret_cast<std::shared_ptr<onnxruntimejsi::Env>*>(envHandle));
    // invalidate() runs first because this hook is not guaranteed to run on the JS thread: it
    // stops dispatching to a runtime that is going away and releases any thread blocked on it.
    if (env && *env) {
      (*env)->invalidate();
    }
  }
};
 
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void*) {
  return jni::initialize(
      vm, [] { OnnxruntimeModule::registerNatives(); });
}