diff options
author | t895 <clombardo169@gmail.com> | 2024-02-05 12:07:29 +0100 |
---|---|---|
committer | t895 <clombardo169@gmail.com> | 2024-02-08 19:45:26 +0100 |
commit | e7c4c8b993ce27a50b7a56f90247056048d20f7d (patch) | |
tree | b87c275f4ea92092f7c8b6cdcb0f50d32819490f /src/common/android/id_cache.h | |
parent | Merge pull request #12892 from liamwhite/serialization-stuff (diff) | |
download | yuzu-e7c4c8b993ce27a50b7a56f90247056048d20f7d.tar yuzu-e7c4c8b993ce27a50b7a56f90247056048d20f7d.tar.gz yuzu-e7c4c8b993ce27a50b7a56f90247056048d20f7d.tar.bz2 yuzu-e7c4c8b993ce27a50b7a56f90247056048d20f7d.tar.lz yuzu-e7c4c8b993ce27a50b7a56f90247056048d20f7d.tar.xz yuzu-e7c4c8b993ce27a50b7a56f90247056048d20f7d.tar.zst yuzu-e7c4c8b993ce27a50b7a56f90247056048d20f7d.zip |
Diffstat (limited to '')
-rw-r--r-- | src/common/android/id_cache.h (renamed from src/android/app/src/main/jni/id_cache.h) | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/android/app/src/main/jni/id_cache.h b/src/common/android/id_cache.h index 00e48afc0..47802f96c 100644 --- a/src/android/app/src/main/jni/id_cache.h +++ b/src/common/android/id_cache.h @@ -3,20 +3,40 @@ #pragma once +#include <future> #include <jni.h> #include "video_core/rasterizer_interface.h" -namespace IDCache { +namespace Common::Android { JNIEnv* GetEnvForThread(); + +/** + * Starts a new thread to run JNI. Intended to be used when you must run JNI from a fiber. + * @tparam T Typename of the return value for the work param + * @param work Lambda that runs JNI code. This function will take care of attaching this thread to + * the JVM + * @return The result from the work lambda param + */ +template <typename T = void> +T RunJNIOnFiber(const std::function<T(JNIEnv*)>& work) { + std::future<T> j_result = std::async(std::launch::async, [&] { + auto env = GetEnvForThread(); + return work(env); + }); + return j_result.get(); +} + jclass GetNativeLibraryClass(); + jclass GetDiskCacheProgressClass(); jclass GetDiskCacheLoadCallbackStageClass(); jclass GetGameDirClass(); jmethodID GetGameDirConstructor(); -jmethodID GetExitEmulationActivity(); jmethodID GetDiskCacheLoadProgress(); + +jmethodID GetExitEmulationActivity(); jmethodID GetOnEmulationStarted(); jmethodID GetOnEmulationStopped(); jmethodID GetOnProgramChanged(); @@ -65,4 +85,4 @@ jclass GetBooleanClass(); jmethodID GetBooleanConstructor(); jfieldID GetBooleanValueField(); -} // namespace IDCache +} // namespace Common::Android |