Remove unnecessary atomic usage in GCAdapter.cpp

You can safely read or write non-atomic integers on multiple threads,
as long as every thread reading or writing it holds the same mutex
while doing so (here, s_mutex).

Removing the atomic accesses makes the code faster, but the actual
performance difference is probably negligible.
This commit is contained in:
nyanpasu64 2022-03-27 22:25:40 -07:00
parent c08a23b374
commit 871b01a5d9

View File

@ -51,7 +51,8 @@ static std::mutex s_mutex;
static u8 s_controller_payload[37];
static u8 s_controller_payload_swap[37];
static std::atomic<int> s_controller_payload_size = {0};
// Only access with s_mutex held!
static int s_controller_payload_size = {0};
static std::thread s_adapter_input_thread;
static std::thread s_adapter_output_thread;
@ -101,7 +102,7 @@ static void Read()
{
std::lock_guard<std::mutex> lk(s_mutex);
std::swap(s_controller_payload_swap, s_controller_payload);
s_controller_payload_size.store(payload_size);
s_controller_payload_size = payload_size;
}
Common::YieldCPU();
@ -459,7 +460,7 @@ GCPadStatus Input(int chan)
std::lock_guard<std::mutex> lk(s_mutex);
std::copy(std::begin(s_controller_payload), std::end(s_controller_payload),
std::begin(controller_payload_copy));
payload_size = s_controller_payload_size.load();
payload_size = s_controller_payload_size;
}
GCPadStatus pad = {};