diff options
| author | Pokechu22 <Pokechu022@gmail.com> | 2022-04-20 18:52:04 -0700 |
|---|---|---|
| committer | Pokechu22 <Pokechu022@gmail.com> | 2022-06-02 19:39:36 -0700 |
| commit | 0fa92694d120e2a68666c597cf40fc94ca3d4b23 (patch) | |
| tree | f9be5cb6b3759383579bf7fa3182d67fa9dc8576 /Source/Core | |
| parent | 749a4ad1ef785eb82e42cf083b6cd2511f40001c (diff) | |
GCAdapter: Exit early if the adapter fails to open on Android
This is only so that indentation is consistent with the non-android code.
Diffstat (limited to 'Source/Core')
| -rw-r--r-- | Source/Core/InputCommon/GCAdapter.cpp | 60 |
1 files changed, 33 insertions, 27 deletions
diff --git a/Source/Core/InputCommon/GCAdapter.cpp b/Source/Core/InputCommon/GCAdapter.cpp index 0f52305816..1a0844c42e 100644 --- a/Source/Core/InputCommon/GCAdapter.cpp +++ b/Source/Core/InputCommon/GCAdapter.cpp @@ -192,43 +192,49 @@ static void Read() bool connected = env->CallStaticBooleanMethod(s_adapter_class, openadapter_func); - if (connected) + if (!connected) { - s_write_adapter_thread_running.Set(true); - s_write_adapter_thread = std::thread(Write); + s_fd = 0; + s_detected = false; - // Reset rumble once on initial reading - ResetRumble(); + NOTICE_LOG_FMT(CONTROLLERINTERFACE, "GC Adapter failed to open!"); + return; + } - while (s_read_adapter_thread_running.IsSet()) - { - int read_size = env->CallStaticIntMethod(s_adapter_class, input_func); + s_write_adapter_thread_running.Set(true); + s_write_adapter_thread = std::thread(Write); - jbyte* java_data = env->GetByteArrayElements(*java_controller_payload, nullptr); - { - std::lock_guard<std::mutex> lk(s_read_mutex); - std::copy(java_data, java_data + CONTROLER_INPUT_PAYLOAD_EXPECTED_SIZE, - s_controller_payload.begin()); - s_controller_payload_size = read_size; - } - env->ReleaseByteArrayElements(*java_controller_payload, java_data, 0); + // Reset rumble once on initial reading + ResetRumble(); - if (first_read) - { - first_read = false; - s_fd = env->CallStaticIntMethod(s_adapter_class, getfd_func); - } + while (s_read_adapter_thread_running.IsSet()) + { + int read_size = env->CallStaticIntMethod(s_adapter_class, input_func); - Common::YieldCPU(); + jbyte* java_data = env->GetByteArrayElements(*java_controller_payload, nullptr); + { + std::lock_guard<std::mutex> lk(s_read_mutex); + std::copy(java_data, java_data + CONTROLER_INPUT_PAYLOAD_EXPECTED_SIZE, + s_controller_payload.begin()); + s_controller_payload_size = read_size; } + env->ReleaseByteArrayElements(*java_controller_payload, java_data, 0); - // Terminate the write thread on leaving - if (s_write_adapter_thread_running.TestAndClear()) + if (first_read) { - s_controller_write_payload_size.store(0); - s_write_happened.Set(); // Kick the waiting event - write_adapter_thread.join(); + first_read = false; + s_fd = env->CallStaticIntMethod(s_adapter_class, getfd_func); } + + Common::YieldCPU(); + } + + // Terminate the write thread on leaving + if (s_write_adapter_thread_running.TestAndClear()) + { + s_controller_write_payload_size.store(0); + s_write_happened.Set(); // Kick the waiting event + write_adapter_thread.join(); } s_fd = 0; |
