GCAdapter: Exit early if the adapter fails to open on Android

This is only so that indentation is consistent with the non-android code.
This commit is contained in:
Pokechu22 2022-04-20 18:52:04 -07:00
parent 749a4ad1ef
commit 0fa92694d1
1 changed files with 36 additions and 30 deletions

View File

@ -192,43 +192,49 @@ static void Read()
bool connected = env->CallStaticBooleanMethod(s_adapter_class, openadapter_func); bool connected = env->CallStaticBooleanMethod(s_adapter_class, openadapter_func);
if (connected) if (!connected)
{ {
s_write_adapter_thread_running.Set(true); s_fd = 0;
s_write_adapter_thread = std::thread(Write); s_detected = false;
// Reset rumble once on initial reading NOTICE_LOG_FMT(CONTROLLERINTERFACE, "GC Adapter failed to open!");
ResetRumble(); return;
}
while (s_read_adapter_thread_running.IsSet()) s_write_adapter_thread_running.Set(true);
s_write_adapter_thread = std::thread(Write);
// Reset rumble once on initial reading
ResetRumble();
while (s_read_adapter_thread_running.IsSet())
{
int read_size = env->CallStaticIntMethod(s_adapter_class, input_func);
jbyte* java_data = env->GetByteArrayElements(*java_controller_payload, nullptr);
{ {
int read_size = env->CallStaticIntMethod(s_adapter_class, input_func); 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);
jbyte* java_data = env->GetByteArrayElements(*java_controller_payload, nullptr); if (first_read)
{ {
std::lock_guard<std::mutex> lk(s_read_mutex); first_read = false;
std::copy(java_data, java_data + CONTROLER_INPUT_PAYLOAD_EXPECTED_SIZE, s_fd = env->CallStaticIntMethod(s_adapter_class, getfd_func);
s_controller_payload.begin());
s_controller_payload_size = read_size;
}
env->ReleaseByteArrayElements(*java_controller_payload, java_data, 0);
if (first_read)
{
first_read = false;
s_fd = env->CallStaticIntMethod(s_adapter_class, getfd_func);
}
Common::YieldCPU();
} }
// Terminate the write thread on leaving Common::YieldCPU();
if (s_write_adapter_thread_running.TestAndClear()) }
{
s_controller_write_payload_size.store(0); // Terminate the write thread on leaving
s_write_happened.Set(); // Kick the waiting event if (s_write_adapter_thread_running.TestAndClear())
write_adapter_thread.join(); {
} s_controller_write_payload_size.store(0);
s_write_happened.Set(); // Kick the waiting event
write_adapter_thread.join();
} }
s_fd = 0; s_fd = 0;