CoreTiming: wrap into class

This commit is contained in:
Weiyi Wang 2018-10-27 15:53:20 -04:00
parent 7c3d325aff
commit 9458e4d8ec
34 changed files with 413 additions and 413 deletions

View file

@ -151,7 +151,7 @@ void Module::StartReceiving(int port_id) {
// schedules a completion event according to the frame rate. The event will block on the
// capture task if it is not finished within the expected time
CoreTiming::ScheduleEvent(
system.CoreTiming().ScheduleEvent(
msToCycles(LATENCY_BY_FRAME_RATE[static_cast<int>(camera.frame_rate)]),
completion_event_callback, port_id);
}
@ -160,7 +160,7 @@ void Module::CancelReceiving(int port_id) {
if (!ports[port_id].is_receiving)
return;
LOG_WARNING(Service_CAM, "tries to cancel an ongoing receiving process.");
CoreTiming::UnscheduleEvent(completion_event_callback, port_id);
system.CoreTiming().UnscheduleEvent(completion_event_callback, port_id);
ports[port_id].capture_result.wait();
ports[port_id].is_receiving = false;
}
@ -1019,7 +1019,7 @@ void Module::Interface::DriverFinalize(Kernel::HLERequestContext& ctx) {
LOG_DEBUG(Service_CAM, "called");
}
Module::Module(Core::System& system) {
Module::Module(Core::System& system) : system(system) {
using namespace Kernel;
for (PortConfig& port : ports) {
port.completion_event =
@ -1029,7 +1029,7 @@ Module::Module(Core::System& system) {
port.vsync_interrupt_event =
system.Kernel().CreateEvent(ResetType::OneShot, "CAM::vsync_interrupt_event");
}
completion_event_callback = CoreTiming::RegisterEvent(
completion_event_callback = system.CoreTiming().RegisterEvent(
"CAM::CompletionEventCallBack",
[this](u64 userdata, s64 cycles_late) { CompletionEventCallBack(userdata, cycles_late); });
}

View file

@ -21,8 +21,8 @@ namespace Camera {
class CameraInterface;
}
namespace CoreTiming {
struct EventType;
namespace Core {
struct TimingEventType;
}
namespace Kernel {
@ -779,9 +779,10 @@ private:
void LoadCameraImplementation(CameraConfig& camera, int camera_id);
Core::System& system;
std::array<CameraConfig, NumCameras> cameras;
std::array<PortConfig, 2> ports;
CoreTiming::EventType* completion_event_callback;
Core::TimingEventType* completion_event_callback;
std::atomic<bool> is_camera_reload_pending{false};
};

View file

@ -128,7 +128,7 @@ void Module::UpdatePadCallback(u64 userdata, s64 cycles_late) {
// If we just updated index 0, provide a new timestamp
if (mem->pad.index == 0) {
mem->pad.index_reset_ticks_previous = mem->pad.index_reset_ticks;
mem->pad.index_reset_ticks = (s64)CoreTiming::GetTicks();
mem->pad.index_reset_ticks = (s64)system.CoreTiming().GetTicks();
}
mem->touch.index = next_touch_index;
@ -152,7 +152,7 @@ void Module::UpdatePadCallback(u64 userdata, s64 cycles_late) {
// If we just updated index 0, provide a new timestamp
if (mem->touch.index == 0) {
mem->touch.index_reset_ticks_previous = mem->touch.index_reset_ticks;
mem->touch.index_reset_ticks = (s64)CoreTiming::GetTicks();
mem->touch.index_reset_ticks = (s64)system.CoreTiming().GetTicks();
}
// Signal both handles when there's an update to Pad or touch
@ -160,7 +160,7 @@ void Module::UpdatePadCallback(u64 userdata, s64 cycles_late) {
event_pad_or_touch_2->Signal();
// Reschedule recurrent event
CoreTiming::ScheduleEvent(pad_update_ticks - cycles_late, pad_update_event);
system.CoreTiming().ScheduleEvent(pad_update_ticks - cycles_late, pad_update_event);
}
void Module::UpdateAccelerometerCallback(u64 userdata, s64 cycles_late) {
@ -198,13 +198,14 @@ void Module::UpdateAccelerometerCallback(u64 userdata, s64 cycles_late) {
// If we just updated index 0, provide a new timestamp
if (mem->accelerometer.index == 0) {
mem->accelerometer.index_reset_ticks_previous = mem->accelerometer.index_reset_ticks;
mem->accelerometer.index_reset_ticks = (s64)CoreTiming::GetTicks();
mem->accelerometer.index_reset_ticks = (s64)system.CoreTiming().GetTicks();
}
event_accelerometer->Signal();
// Reschedule recurrent event
CoreTiming::ScheduleEvent(accelerometer_update_ticks - cycles_late, accelerometer_update_event);
system.CoreTiming().ScheduleEvent(accelerometer_update_ticks - cycles_late,
accelerometer_update_event);
}
void Module::UpdateGyroscopeCallback(u64 userdata, s64 cycles_late) {
@ -233,13 +234,13 @@ void Module::UpdateGyroscopeCallback(u64 userdata, s64 cycles_late) {
// If we just updated index 0, provide a new timestamp
if (mem->gyroscope.index == 0) {
mem->gyroscope.index_reset_ticks_previous = mem->gyroscope.index_reset_ticks;
mem->gyroscope.index_reset_ticks = (s64)CoreTiming::GetTicks();
mem->gyroscope.index_reset_ticks = (s64)system.CoreTiming().GetTicks();
}
event_gyroscope->Signal();
// Reschedule recurrent event
CoreTiming::ScheduleEvent(gyroscope_update_ticks - cycles_late, gyroscope_update_event);
system.CoreTiming().ScheduleEvent(gyroscope_update_ticks - cycles_late, gyroscope_update_event);
}
void Module::Interface::GetIPCHandles(Kernel::HLERequestContext& ctx) {
@ -257,7 +258,8 @@ void Module::Interface::EnableAccelerometer(Kernel::HLERequestContext& ctx) {
// Schedules the accelerometer update event if the accelerometer was just enabled
if (hid->enable_accelerometer_count == 1) {
CoreTiming::ScheduleEvent(accelerometer_update_ticks, hid->accelerometer_update_event);
hid->system.CoreTiming().ScheduleEvent(accelerometer_update_ticks,
hid->accelerometer_update_event);
}
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
@ -273,7 +275,7 @@ void Module::Interface::DisableAccelerometer(Kernel::HLERequestContext& ctx) {
// Unschedules the accelerometer update event if the accelerometer was just disabled
if (hid->enable_accelerometer_count == 0) {
CoreTiming::UnscheduleEvent(hid->accelerometer_update_event, 0);
hid->system.CoreTiming().UnscheduleEvent(hid->accelerometer_update_event, 0);
}
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
@ -289,7 +291,7 @@ void Module::Interface::EnableGyroscopeLow(Kernel::HLERequestContext& ctx) {
// Schedules the gyroscope update event if the gyroscope was just enabled
if (hid->enable_gyroscope_count == 1) {
CoreTiming::ScheduleEvent(gyroscope_update_ticks, hid->gyroscope_update_event);
hid->system.CoreTiming().ScheduleEvent(gyroscope_update_ticks, hid->gyroscope_update_event);
}
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
@ -305,7 +307,7 @@ void Module::Interface::DisableGyroscopeLow(Kernel::HLERequestContext& ctx) {
// Unschedules the gyroscope update event if the gyroscope was just disabled
if (hid->enable_gyroscope_count == 0) {
CoreTiming::UnscheduleEvent(hid->gyroscope_update_event, 0);
hid->system.CoreTiming().UnscheduleEvent(hid->gyroscope_update_event, 0);
}
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
@ -371,19 +373,21 @@ Module::Module(Core::System& system) : system(system) {
event_debug_pad = system.Kernel().CreateEvent(ResetType::OneShot, "HID:EventDebugPad");
// Register update callbacks
Core::Timing& timing = system.CoreTiming();
pad_update_event =
CoreTiming::RegisterEvent("HID::UpdatePadCallback", [this](u64 userdata, s64 cycles_late) {
timing.RegisterEvent("HID::UpdatePadCallback", [this](u64 userdata, s64 cycles_late) {
UpdatePadCallback(userdata, cycles_late);
});
accelerometer_update_event = CoreTiming::RegisterEvent(
accelerometer_update_event = timing.RegisterEvent(
"HID::UpdateAccelerometerCallback", [this](u64 userdata, s64 cycles_late) {
UpdateAccelerometerCallback(userdata, cycles_late);
});
gyroscope_update_event = CoreTiming::RegisterEvent(
"HID::UpdateGyroscopeCallback",
[this](u64 userdata, s64 cycles_late) { UpdateGyroscopeCallback(userdata, cycles_late); });
gyroscope_update_event =
timing.RegisterEvent("HID::UpdateGyroscopeCallback", [this](u64 userdata, s64 cycles_late) {
UpdateGyroscopeCallback(userdata, cycles_late);
});
CoreTiming::ScheduleEvent(pad_update_ticks, pad_update_event);
timing.ScheduleEvent(pad_update_ticks, pad_update_event);
}
void Module::ReloadInputDevices() {

View file

@ -27,8 +27,8 @@ class Event;
class SharedMemory;
} // namespace Kernel
namespace CoreTiming {
struct EventType;
namespace Core {
struct TimingEventType;
};
namespace Service::HID {
@ -325,9 +325,9 @@ private:
int enable_accelerometer_count = 0; // positive means enabled
int enable_gyroscope_count = 0; // positive means enabled
CoreTiming::EventType* pad_update_event;
CoreTiming::EventType* accelerometer_update_event;
CoreTiming::EventType* gyroscope_update_event;
Core::TimingEventType* pad_update_event;
Core::TimingEventType* accelerometer_update_event;
Core::TimingEventType* gyroscope_update_event;
std::atomic<bool> is_device_reload_pending{true};
std::array<std::unique_ptr<Input::ButtonDevice>, Settings::NativeButton::NUM_BUTTONS_HID>

View file

@ -4,6 +4,7 @@
#include "common/alignment.h"
#include "common/string_util.h"
#include "core/core.h"
#include "core/core_timing.h"
#include "core/hle/service/ir/extra_hid.h"
#include "core/movie.h"
@ -144,11 +145,11 @@ ExtraHID::ExtraHID(SendFunc send_func) : IRDevice(send_func) {
0x65,
}};
hid_polling_callback_id =
CoreTiming::RegisterEvent("ExtraHID::SendHIDStatus", [this](u64, s64 cycles_late) {
hid_polling_callback_id = Core::System::GetInstance().CoreTiming().RegisterEvent(
"ExtraHID::SendHIDStatus", [this](u64, s64 cycles_late) {
SendHIDStatus();
CoreTiming::ScheduleEvent(msToCycles(hid_period) - cycles_late,
hid_polling_callback_id);
Core::System::GetInstance().CoreTiming().ScheduleEvent(
msToCycles(hid_period) - cycles_late, hid_polling_callback_id);
});
}
@ -159,7 +160,7 @@ ExtraHID::~ExtraHID() {
void ExtraHID::OnConnect() {}
void ExtraHID::OnDisconnect() {
CoreTiming::UnscheduleEvent(hid_polling_callback_id, 0);
Core::System::GetInstance().CoreTiming().UnscheduleEvent(hid_polling_callback_id, 0);
}
void ExtraHID::HandleConfigureHIDPollingRequest(const std::vector<u8>& request) {
@ -170,9 +171,10 @@ void ExtraHID::HandleConfigureHIDPollingRequest(const std::vector<u8>& request)
}
// Change HID input polling interval
CoreTiming::UnscheduleEvent(hid_polling_callback_id, 0);
Core::System::GetInstance().CoreTiming().UnscheduleEvent(hid_polling_callback_id, 0);
hid_period = request[1];
CoreTiming::ScheduleEvent(msToCycles(hid_period), hid_polling_callback_id);
Core::System::GetInstance().CoreTiming().ScheduleEvent(msToCycles(hid_period),
hid_polling_callback_id);
}
void ExtraHID::HandleReadCalibrationDataRequest(const std::vector<u8>& request_buf) {

View file

@ -11,9 +11,9 @@
#include "core/frontend/input.h"
#include "core/hle/service/ir/ir_user.h"
namespace CoreTiming {
struct EventType;
} // namespace CoreTiming
namespace Core {
struct TimingEventType;
} // namespace Core
namespace Service::IR {
@ -57,7 +57,7 @@ private:
void LoadInputDevices();
u8 hid_period;
CoreTiming::EventType* hid_polling_callback_id;
Core::TimingEventType* hid_polling_callback_id;
std::array<u8, 0x40> calibration_data;
std::unique_ptr<Input::ButtonDevice> zl;
std::unique_ptr<Input::ButtonDevice> zr;

View file

@ -100,13 +100,13 @@ void IR_RST::UpdateCallback(u64 userdata, s64 cycles_late) {
// If we just updated index 0, provide a new timestamp
if (mem->index == 0) {
mem->index_reset_ticks_previous = mem->index_reset_ticks;
mem->index_reset_ticks = CoreTiming::GetTicks();
mem->index_reset_ticks = system.CoreTiming().GetTicks();
}
update_event->Signal();
// Reschedule recurrent event
CoreTiming::ScheduleEvent(msToCycles(update_period) - cycles_late, update_callback_id);
system.CoreTiming().ScheduleEvent(msToCycles(update_period) - cycles_late, update_callback_id);
}
void IR_RST::GetHandles(Kernel::HLERequestContext& ctx) {
@ -126,7 +126,7 @@ void IR_RST::Initialize(Kernel::HLERequestContext& ctx) {
next_pad_index = 0;
is_device_reload_pending.store(true);
CoreTiming::ScheduleEvent(msToCycles(update_period), update_callback_id);
system.CoreTiming().ScheduleEvent(msToCycles(update_period), update_callback_id);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(RESULT_SUCCESS);
@ -137,7 +137,7 @@ void IR_RST::Initialize(Kernel::HLERequestContext& ctx) {
void IR_RST::Shutdown(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x03, 0, 0);
CoreTiming::UnscheduleEvent(update_callback_id, 0);
system.CoreTiming().UnscheduleEvent(update_callback_id, 0);
UnloadInputDevices();
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
@ -145,7 +145,7 @@ void IR_RST::Shutdown(Kernel::HLERequestContext& ctx) {
LOG_DEBUG(Service_IR, "called");
}
IR_RST::IR_RST(Core::System& system) : ServiceFramework("ir:rst", 1) {
IR_RST::IR_RST(Core::System& system) : ServiceFramework("ir:rst", 1), system(system) {
using namespace Kernel;
// Note: these two kernel objects are even available before Initialize service function is
// called.
@ -154,10 +154,9 @@ IR_RST::IR_RST(Core::System& system) : ServiceFramework("ir:rst", 1) {
MemoryRegion::BASE, "IRRST:SharedMemory");
update_event = system.Kernel().CreateEvent(ResetType::OneShot, "IRRST:UpdateEvent");
update_callback_id =
CoreTiming::RegisterEvent("IRRST:UpdateCallBack", [this](u64 userdata, s64 cycles_late) {
UpdateCallback(userdata, cycles_late);
});
update_callback_id = system.CoreTiming().RegisterEvent(
"IRRST:UpdateCallBack",
[this](u64 userdata, s64 cycles_late) { UpdateCallback(userdata, cycles_late); });
static const FunctionInfo functions[] = {
{0x00010000, &IR_RST::GetHandles, "GetHandles"},

View file

@ -18,8 +18,8 @@ class Event;
class SharedMemory;
} // namespace Kernel
namespace CoreTiming {
struct EventType;
namespace Core {
struct TimingEventType;
};
namespace Service::IR {
@ -77,10 +77,11 @@ private:
void UnloadInputDevices();
void UpdateCallback(u64 userdata, s64 cycles_late);
Core::System& system;
Kernel::SharedPtr<Kernel::Event> update_event;
Kernel::SharedPtr<Kernel::SharedMemory> shared_memory;
u32 next_pad_index{0};
CoreTiming::EventType* update_callback_id;
Core::TimingEventType* update_callback_id;
std::unique_ptr<Input::ButtonDevice> zl_button;
std::unique_ptr<Input::ButtonDevice> zr_button;
std::unique_ptr<Input::AnalogDevice> c_stick;

View file

@ -14,10 +14,6 @@ class Event;
class SharedMemory;
} // namespace Kernel
namespace CoreTiming {
struct EventType;
};
namespace Service::IR {
class BufferManager;

View file

@ -88,7 +88,7 @@ struct Node {
static std::map<MacAddress, Node> node_map;
// Event that will generate and send the 802.11 beacon frames.
static CoreTiming::EventType* beacon_broadcast_event;
static Core::TimingEventType* beacon_broadcast_event;
// Callback identifier for the OnWifiPacketReceived event.
static Network::RoomMember::CallbackHandle<Network::WifiPacket> wifi_packet_received;
@ -955,8 +955,8 @@ void NWM_UDS::BeginHostingNetwork(Kernel::HLERequestContext& ctx) {
connection_status_event->Signal();
// Start broadcasting the network, send a beacon frame every 102.4ms.
CoreTiming::ScheduleEvent(msToCycles(DefaultBeaconInterval * MillisecondsPerTU),
beacon_broadcast_event, 0);
system.CoreTiming().ScheduleEvent(msToCycles(DefaultBeaconInterval * MillisecondsPerTU),
beacon_broadcast_event, 0);
LOG_DEBUG(Service_NWM, "An UDS network has been created.");
@ -976,7 +976,7 @@ void NWM_UDS::DestroyNetwork(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x08, 0, 0);
// Unschedule the beacon broadcast event.
CoreTiming::UnscheduleEvent(beacon_broadcast_event, 0);
system.CoreTiming().UnscheduleEvent(beacon_broadcast_event, 0);
// Only a host can destroy
std::lock_guard<std::mutex> lock(connection_status_mutex);
@ -1336,7 +1336,7 @@ void NWM_UDS::DecryptBeaconData(Kernel::HLERequestContext& ctx) {
}
// Sends a 802.11 beacon frame with information about the current network.
static void BeaconBroadcastCallback(u64 userdata, s64 cycles_late) {
void NWM_UDS::BeaconBroadcastCallback(u64 userdata, 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;
@ -1353,8 +1353,9 @@ static void BeaconBroadcastCallback(u64 userdata, s64 cycles_late) {
SendPacket(packet);
// Start broadcasting the network, send a beacon frame every 102.4ms.
CoreTiming::ScheduleEvent(msToCycles(DefaultBeaconInterval * MillisecondsPerTU) - cycles_late,
beacon_broadcast_event, 0);
system.CoreTiming().ScheduleEvent(msToCycles(DefaultBeaconInterval * MillisecondsPerTU) -
cycles_late,
beacon_broadcast_event, 0);
}
NWM_UDS::NWM_UDS(Core::System& system) : ServiceFramework("nwm::UDS"), system(system) {
@ -1394,8 +1395,9 @@ NWM_UDS::NWM_UDS(Core::System& system) : ServiceFramework("nwm::UDS"), system(sy
RegisterHandlers(functions);
beacon_broadcast_event =
CoreTiming::RegisterEvent("UDS::BeaconBroadcastCallback", BeaconBroadcastCallback);
beacon_broadcast_event = system.CoreTiming().RegisterEvent(
"UDS::BeaconBroadcastCallback",
[this](u64 userdata, s64 cycles_late) { BeaconBroadcastCallback(userdata, cycles_late); });
CryptoPP::AutoSeededRandomPool rng;
auto mac = SharedPage::DefaultMac;
@ -1428,7 +1430,7 @@ NWM_UDS::~NWM_UDS() {
if (auto room_member = Network::GetRoomMember().lock())
room_member->Unbind(wifi_packet_received);
CoreTiming::UnscheduleEvent(beacon_broadcast_event, 0);
system.CoreTiming().UnscheduleEvent(beacon_broadcast_event, 0);
}
} // namespace Service::NWM

View file

@ -352,6 +352,8 @@ private:
* 2, 3: output buffer return descriptor & ptr
*/
void DecryptBeaconData(Kernel::HLERequestContext& ctx);
void BeaconBroadcastCallback(u64 userdata, s64 cycles_late);
};
} // namespace Service::NWM