From 0fa92694d120e2a68666c597cf40fc94ca3d4b23 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Wed, 20 Apr 2022 18:52:04 -0700 Subject: GCAdapter: Exit early if the adapter fails to open on Android This is only so that indentation is consistent with the non-android code. --- Source/Core/InputCommon/GCAdapter.cpp | 60 +++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 27 deletions(-) (limited to 'Source/Core/InputCommon/GCAdapter.cpp') 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 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 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; -- cgit v1.2.3