Port yuzu-emu/yuzu#4437: "core_timing: Make use of uintptr_t to represent user_data" (#5499)

Co-authored-by: LC <lioncash@users.noreply.github.com>
This commit is contained in:
Tobias 2022-11-06 02:24:45 +01:00 committed by GitHub
parent 7801907288
commit 3201943423
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 62 additions and 58 deletions

View File

@ -102,7 +102,7 @@ void CheatEngine::LoadCheatFile() {
}
}
void CheatEngine::RunCallback([[maybe_unused]] u64 userdata, s64 cycles_late) {
void CheatEngine::RunCallback([[maybe_unused]] std::uintptr_t user_data, s64 cycles_late) {
{
std::shared_lock<std::shared_mutex> lock(cheats_list_mutex);
for (auto& cheat : cheats_list) {

View File

@ -35,7 +35,7 @@ public:
private:
void LoadCheatFile();
void RunCallback(u64 userdata, s64 cycles_late);
void RunCallback(std::uintptr_t user_data, s64 cycles_late);
std::vector<std::shared_ptr<CheatBase>> cheats_list;
mutable std::shared_mutex cheats_list_mutex;
Core::TimingEventType* event;

View File

@ -47,8 +47,8 @@ TimingEventType* Timing::RegisterEvent(const std::string& name, TimedCallback ca
return event_type;
}
void Timing::ScheduleEvent(s64 cycles_into_future, const TimingEventType* event_type, u64 userdata,
std::size_t core_id) {
void Timing::ScheduleEvent(s64 cycles_into_future, const TimingEventType* event_type,
std::uintptr_t user_data, std::size_t core_id) {
if (event_queue_locked) {
return;
}
@ -69,22 +69,22 @@ void Timing::ScheduleEvent(s64 cycles_into_future, const TimingEventType* event_
timer->ForceExceptionCheck(cycles_into_future);
timer->event_queue.emplace_back(
Event{timeout, timer->event_fifo_id++, userdata, event_type});
Event{timeout, timer->event_fifo_id++, user_data, event_type});
std::push_heap(timer->event_queue.begin(), timer->event_queue.end(), std::greater<>());
} else {
timer->ts_queue.Push(Event{static_cast<s64>(timer->GetTicks() + cycles_into_future), 0,
userdata, event_type});
user_data, event_type});
}
}
void Timing::UnscheduleEvent(const TimingEventType* event_type, u64 userdata) {
void Timing::UnscheduleEvent(const TimingEventType* event_type, std::uintptr_t user_data) {
if (event_queue_locked) {
return;
}
for (auto timer : timers) {
auto itr = std::remove_if(
timer->event_queue.begin(), timer->event_queue.end(),
[&](const Event& e) { return e.type == event_type && e.userdata == userdata; });
[&](const Event& e) { return e.type == event_type && e.user_data == user_data; });
// Removing random items breaks the invariant so we have to re-establish it.
if (itr != timer->event_queue.end()) {
@ -215,7 +215,7 @@ void Timing::Timer::Advance() {
std::pop_heap(event_queue.begin(), event_queue.end(), std::greater<>());
event_queue.pop_back();
if (evt.type->callback != nullptr) {
evt.type->callback(evt.userdata, static_cast<int>(executed_ticks - evt.time));
evt.type->callback(evt.user_data, static_cast<int>(executed_ticks - evt.time));
} else {
LOG_ERROR(Core, "Event '{}' has no callback", *evt.type->name);
}

View File

@ -128,7 +128,7 @@ constexpr u64 cyclesToMs(s64 cycles) {
namespace Core {
using TimedCallback = std::function<void(u64 userdata, int cycles_late)>;
using TimedCallback = std::function<void(std::uintptr_t user_data, int cycles_late)>;
struct TimingEventType {
TimedCallback callback;
@ -141,7 +141,7 @@ public:
struct Event {
s64 time;
u64 fifo_order;
u64 userdata;
std::uintptr_t user_data;
const TimingEventType* type;
bool operator>(const Event& right) const;
@ -152,7 +152,7 @@ public:
void save(Archive& ar, const unsigned int) const {
ar& time;
ar& fifo_order;
ar& userdata;
ar& user_data;
std::string name = *(type->name);
ar << name;
}
@ -161,7 +161,7 @@ public:
void load(Archive& ar, const unsigned int) {
ar& time;
ar& fifo_order;
ar& userdata;
ar& user_data;
std::string name;
ar >> name;
type = Global<Timing>().RegisterEvent(name, nullptr);
@ -265,10 +265,11 @@ public:
*/
TimingEventType* RegisterEvent(const std::string& name, TimedCallback callback);
void ScheduleEvent(s64 cycles_into_future, const TimingEventType* event_type, u64 userdata = 0,
void ScheduleEvent(s64 cycles_into_future, const TimingEventType* event_type,
std::uintptr_t user_data = 0,
std::size_t core_id = std::numeric_limits<std::size_t>::max());
void UnscheduleEvent(const TimingEventType* event_type, u64 userdata);
void UnscheduleEvent(const TimingEventType* event_type, std::uintptr_t user_data);
/// We only permit one event of each type in the queue at a time.
void RemoveEvent(const TimingEventType* event_type);

View File

@ -108,7 +108,7 @@ u64 Handler::GetSystemTime() const {
return console_time;
}
void Handler::UpdateTimeCallback(u64 userdata, int cycles_late) {
void Handler::UpdateTimeCallback(std::uintptr_t user_data, int cycles_late) {
DateTime& date_time =
shared_page.date_time_counter % 2 ? shared_page.date_time_0 : shared_page.date_time_1;

View File

@ -114,7 +114,7 @@ public:
private:
u64 GetSystemTime() const;
void UpdateTimeCallback(u64 userdata, int cycles_late);
void UpdateTimeCallback(std::uintptr_t user_data, int cycles_late);
Core::Timing& timing;
Core::TimingEventType* update_time_event;
std::chrono::seconds init_time;

View File

@ -1118,11 +1118,12 @@ Module::Module(Core::System& system) : system(system) {
system.Kernel().CreateEvent(ResetType::OneShot, "CAM::vsync_interrupt_event");
}
completion_event_callback = system.CoreTiming().RegisterEvent(
"CAM::CompletionEventCallBack",
[this](u64 userdata, s64 cycles_late) { CompletionEventCallBack(userdata, cycles_late); });
"CAM::CompletionEventCallBack", [this](std::uintptr_t user_data, s64 cycles_late) {
CompletionEventCallBack(user_data, cycles_late);
});
vsync_interrupt_event_callback = system.CoreTiming().RegisterEvent(
"CAM::VsyncInterruptEventCallBack", [this](u64 userdata, s64 cycles_late) {
VsyncInterruptEventCallBack(userdata, cycles_late);
"CAM::VsyncInterruptEventCallBack", [this](std::uintptr_t user_data, s64 cycles_late) {
VsyncInterruptEventCallBack(user_data, cycles_late);
});
}

View File

@ -105,7 +105,7 @@ void Module::LoadInputDevices() {
}
}
void Module::UpdatePadCallback(u64 userdata, s64 cycles_late) {
void Module::UpdatePadCallback(std::uintptr_t user_data, s64 cycles_late) {
SharedMem* mem = reinterpret_cast<SharedMem*>(shared_mem->GetPointer());
if (is_device_reload_pending.exchange(false))
@ -225,7 +225,7 @@ void Module::UpdatePadCallback(u64 userdata, s64 cycles_late) {
system.CoreTiming().ScheduleEvent(pad_update_ticks - cycles_late, pad_update_event);
}
void Module::UpdateAccelerometerCallback(u64 userdata, s64 cycles_late) {
void Module::UpdateAccelerometerCallback(std::uintptr_t user_data, s64 cycles_late) {
SharedMem* mem = reinterpret_cast<SharedMem*>(shared_mem->GetPointer());
mem->accelerometer.index = next_accelerometer_index;
@ -270,7 +270,7 @@ void Module::UpdateAccelerometerCallback(u64 userdata, s64 cycles_late) {
accelerometer_update_event);
}
void Module::UpdateGyroscopeCallback(u64 userdata, s64 cycles_late) {
void Module::UpdateGyroscopeCallback(std::uintptr_t user_data, s64 cycles_late) {
SharedMem* mem = reinterpret_cast<SharedMem*>(shared_mem->GetPointer());
mem->gyroscope.index = next_gyroscope_index;
@ -438,17 +438,17 @@ Module::Module(Core::System& system) : system(system) {
// Register update callbacks
Core::Timing& timing = system.CoreTiming();
pad_update_event =
timing.RegisterEvent("HID::UpdatePadCallback", [this](u64 userdata, s64 cycles_late) {
UpdatePadCallback(userdata, cycles_late);
pad_update_event = timing.RegisterEvent("HID::UpdatePadCallback",
[this](std::uintptr_t user_data, s64 cycles_late) {
UpdatePadCallback(user_data, cycles_late);
});
accelerometer_update_event = timing.RegisterEvent(
"HID::UpdateAccelerometerCallback", [this](u64 userdata, s64 cycles_late) {
UpdateAccelerometerCallback(userdata, cycles_late);
"HID::UpdateAccelerometerCallback", [this](std::uintptr_t user_data, s64 cycles_late) {
UpdateAccelerometerCallback(user_data, cycles_late);
});
gyroscope_update_event =
timing.RegisterEvent("HID::UpdateGyroscopeCallback", [this](u64 userdata, s64 cycles_late) {
UpdateGyroscopeCallback(userdata, cycles_late);
gyroscope_update_event = timing.RegisterEvent(
"HID::UpdateGyroscopeCallback", [this](std::uintptr_t user_data, s64 cycles_late) {
UpdateGyroscopeCallback(user_data, cycles_late);
});
timing.ScheduleEvent(pad_update_ticks, pad_update_event);

View File

@ -307,9 +307,9 @@ public:
private:
void LoadInputDevices();
void UpdatePadCallback(u64 userdata, s64 cycles_late);
void UpdateAccelerometerCallback(u64 userdata, s64 cycles_late);
void UpdateGyroscopeCallback(u64 userdata, s64 cycles_late);
void UpdatePadCallback(std::uintptr_t user_data, s64 cycles_late);
void UpdateAccelerometerCallback(std::uintptr_t user_data, s64 cycles_late);
void UpdateGyroscopeCallback(std::uintptr_t user_data, s64 cycles_late);
Core::System& system;

View File

@ -66,7 +66,7 @@ void IR_RST::UnloadInputDevices() {
c_stick = nullptr;
}
void IR_RST::UpdateCallback(u64 userdata, s64 cycles_late) {
void IR_RST::UpdateCallback(std::uintptr_t user_data, s64 cycles_late) {
SharedMem* mem = reinterpret_cast<SharedMem*>(shared_memory->GetPointer());
if (is_device_reload_pending.exchange(false))
@ -175,8 +175,9 @@ IR_RST::IR_RST(Core::System& system) : ServiceFramework("ir:rst", 1), system(sys
update_event = system.Kernel().CreateEvent(ResetType::OneShot, "IRRST:UpdateEvent");
update_callback_id = system.CoreTiming().RegisterEvent(
"IRRST:UpdateCallBack",
[this](u64 userdata, s64 cycles_late) { UpdateCallback(userdata, cycles_late); });
"IRRST:UpdateCallBack", [this](std::uintptr_t user_data, s64 cycles_late) {
UpdateCallback(user_data, cycles_late);
});
static const FunctionInfo functions[] = {
{0x00010000, &IR_RST::GetHandles, "GetHandles"},

View File

@ -74,7 +74,7 @@ private:
void LoadInputDevices();
void UnloadInputDevices();
void UpdateCallback(u64 userdata, s64 cycles_late);
void UpdateCallback(std::uintptr_t user_data, s64 cycles_late);
Core::System& system;
std::shared_ptr<Kernel::Event> update_event;

View File

@ -126,9 +126,9 @@ struct MIC_U::Impl {
explicit Impl(Core::System& system) : timing(system.CoreTiming()) {
buffer_full_event =
system.Kernel().CreateEvent(Kernel::ResetType::OneShot, "MIC_U::buffer_full_event");
buffer_write_event =
timing.RegisterEvent("MIC_U::UpdateBuffer", [this](u64 userdata, s64 cycles_late) {
UpdateSharedMemBuffer(userdata, cycles_late);
buffer_write_event = timing.RegisterEvent(
"MIC_U::UpdateBuffer", [this](std::uintptr_t user_data, s64 cycles_late) {
UpdateSharedMemBuffer(user_data, cycles_late);
});
}
@ -158,7 +158,7 @@ struct MIC_U::Impl {
LOG_TRACE(Service_MIC, "called");
}
void UpdateSharedMemBuffer(u64 userdata, s64 cycles_late) {
void UpdateSharedMemBuffer(std::uintptr_t user_data, s64 cycles_late) {
if (change_mic_impl_requested.exchange(false)) {
CreateMic();
}

View File

@ -1443,7 +1443,7 @@ void NWM_UDS::DecryptBeaconData(Kernel::HLERequestContext& ctx) {
}
// Sends a 802.11 beacon frame with information about the current network.
void NWM_UDS::BeaconBroadcastCallback(u64 userdata, s64 cycles_late) {
void NWM_UDS::BeaconBroadcastCallback(std::uintptr_t user_data, s64 cycles_late) {
// Don't do anything if we're not actually hosting a network
if (connection_status.status != static_cast<u32>(NetworkStatus::ConnectedAsHost))
return;
@ -1503,8 +1503,9 @@ NWM_UDS::NWM_UDS(Core::System& system) : ServiceFramework("nwm::UDS"), system(sy
RegisterHandlers(functions);
beacon_broadcast_event = system.CoreTiming().RegisterEvent(
"UDS::BeaconBroadcastCallback",
[this](u64 userdata, s64 cycles_late) { BeaconBroadcastCallback(userdata, cycles_late); });
"UDS::BeaconBroadcastCallback", [this](std::uintptr_t user_data, s64 cycles_late) {
BeaconBroadcastCallback(user_data, cycles_late);
});
CryptoPP::AutoSeededRandomPool rng;
auto mac = SharedPage::DefaultMac;

View File

@ -459,7 +459,7 @@ private:
const u8* network_info_buffer, std::size_t network_info_size,
u8 connection_type, std::vector<u8> passphrase);
void BeaconBroadcastCallback(u64 userdata, s64 cycles_late);
void BeaconBroadcastCallback(std::uintptr_t user_data, s64 cycles_late);
/**
* Returns a list of received 802.11 beacon frames from the specified sender since the last

View File

@ -503,7 +503,7 @@ template void Write<u16>(u32 addr, const u16 data);
template void Write<u8>(u32 addr, const u8 data);
/// Update hardware
static void VBlankCallback(u64 userdata, s64 cycles_late) {
static void VBlankCallback(std::uintptr_t user_data, s64 cycles_late) {
VideoCore::g_renderer->SwapBuffers();
// Signal to GSP that GPU interrupt has occurred

View File

@ -21,10 +21,10 @@ static u64 expected_callback = 0;
static s64 lateness = 0;
template <unsigned int IDX>
void CallbackTemplate(u64 userdata, s64 cycles_late) {
void CallbackTemplate(std::uintptr_t user_data, s64 cycles_late) {
static_assert(IDX < CB_IDS.size(), "IDX out of range");
callbacks_ran_flags.set(IDX);
REQUIRE(CB_IDS[IDX] == userdata);
REQUIRE(CB_IDS[IDX] == user_data);
REQUIRE(CB_IDS[IDX] == expected_callback);
REQUIRE(lateness == cycles_late);
}
@ -81,10 +81,10 @@ namespace SharedSlotTest {
static unsigned int counter = 0;
template <unsigned int ID>
void FifoCallback(u64 userdata, s64 cycles_late) {
void FifoCallback(std::uintptr_t user_data, s64 cycles_late) {
static_assert(ID < CB_IDS.size(), "ID out of range");
callbacks_ran_flags.set(ID);
REQUIRE(CB_IDS[ID] == userdata);
REQUIRE(CB_IDS[ID] == user_data);
REQUIRE(ID == counter);
REQUIRE(lateness == cycles_late);
++counter;
@ -143,13 +143,13 @@ TEST_CASE("CoreTiming[PredictableLateness]", "[core]") {
namespace ChainSchedulingTest {
static int reschedules = 0;
static void RescheduleCallback(Core::Timing& timing, u64 userdata, s64 cycles_late) {
static void RescheduleCallback(Core::Timing& timing, std::uintptr_t user_data, s64 cycles_late) {
--reschedules;
REQUIRE(reschedules >= 0);
REQUIRE(lateness == cycles_late);
if (reschedules > 0)
timing.ScheduleEvent(1000, reinterpret_cast<Core::TimingEventType*>(userdata), userdata);
timing.ScheduleEvent(1000, reinterpret_cast<Core::TimingEventType*>(user_data), user_data);
}
} // namespace ChainSchedulingTest
@ -161,9 +161,9 @@ TEST_CASE("CoreTiming[ChainScheduling]", "[core]") {
Core::TimingEventType* cb_a = timing.RegisterEvent("callbackA", CallbackTemplate<0>);
Core::TimingEventType* cb_b = timing.RegisterEvent("callbackB", CallbackTemplate<1>);
Core::TimingEventType* cb_c = timing.RegisterEvent("callbackC", CallbackTemplate<2>);
Core::TimingEventType* cb_rs =
timing.RegisterEvent("callbackReschedule", [&timing](u64 userdata, s64 cycles_late) {
RescheduleCallback(timing, userdata, cycles_late);
Core::TimingEventType* cb_rs = timing.RegisterEvent(
"callbackReschedule", [&timing](std::uintptr_t user_data, s64 cycles_late) {
RescheduleCallback(timing, user_data, cycles_late);
});
// Enter slice 0