2020-01-24 04:53:40 +00:00
|
|
|
#include "timing_event.h"
|
|
|
|
#include "common/assert.h"
|
2020-07-31 07:09:18 +00:00
|
|
|
#include "common/log.h"
|
|
|
|
#include "common/state_wrapper.h"
|
2020-01-24 04:53:40 +00:00
|
|
|
#include "cpu_core.h"
|
2020-10-16 15:28:08 +00:00
|
|
|
#include "cpu_core_private.h"
|
2020-01-24 04:53:40 +00:00
|
|
|
#include "system.h"
|
2020-07-31 07:09:18 +00:00
|
|
|
Log_SetChannel(TimingEvents);
|
2020-01-24 04:53:40 +00:00
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
namespace TimingEvents {
|
|
|
|
|
2020-08-31 10:54:59 +00:00
|
|
|
static TimingEvent* s_active_events_head;
|
|
|
|
static TimingEvent* s_active_events_tail;
|
|
|
|
static TimingEvent* s_current_event = nullptr;
|
|
|
|
static u32 s_active_event_count = 0;
|
2020-07-31 07:09:18 +00:00
|
|
|
static u32 s_global_tick_counter = 0;
|
|
|
|
|
|
|
|
u32 GetGlobalTickCounter()
|
|
|
|
{
|
|
|
|
return s_global_tick_counter;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Initialize()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Reset()
|
|
|
|
{
|
|
|
|
s_global_tick_counter = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Shutdown()
|
|
|
|
{
|
2020-08-31 10:54:59 +00:00
|
|
|
Assert(s_active_event_count == 0);
|
2020-07-31 07:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<TimingEvent> CreateTimingEvent(std::string name, TickCount period, TickCount interval,
|
2021-01-09 15:43:59 +00:00
|
|
|
TimingEventCallback callback, void* callback_param, bool activate)
|
2020-07-31 07:09:18 +00:00
|
|
|
{
|
|
|
|
std::unique_ptr<TimingEvent> event =
|
2021-01-09 15:43:59 +00:00
|
|
|
std::make_unique<TimingEvent>(std::move(name), period, interval, callback, callback_param);
|
2020-07-31 07:09:18 +00:00
|
|
|
if (activate)
|
|
|
|
event->Activate();
|
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateCPUDowncount()
|
|
|
|
{
|
2020-12-16 15:18:02 +00:00
|
|
|
if (!CPU::g_state.frame_done && (!CPU::HasPendingInterrupt() || CPU::g_using_interpreter))
|
2020-10-16 15:28:08 +00:00
|
|
|
{
|
2020-08-31 10:54:59 +00:00
|
|
|
CPU::g_state.downcount = s_active_events_head->GetDowncount();
|
2020-10-16 15:28:08 +00:00
|
|
|
}
|
2020-07-31 07:09:18 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 04:43:09 +00:00
|
|
|
TimingEvent** GetHeadEventPtr()
|
|
|
|
{
|
|
|
|
return &s_active_events_head;
|
|
|
|
}
|
|
|
|
|
2020-08-31 10:54:59 +00:00
|
|
|
static void SortEvent(TimingEvent* event)
|
2020-07-31 07:09:18 +00:00
|
|
|
{
|
2020-08-31 10:54:59 +00:00
|
|
|
const TickCount event_downcount = event->m_downcount;
|
|
|
|
|
|
|
|
if (event->prev && event->prev->m_downcount > event_downcount)
|
|
|
|
{
|
|
|
|
// move backwards
|
|
|
|
TimingEvent* current = event->prev;
|
|
|
|
while (current && current->m_downcount > event_downcount)
|
|
|
|
current = current->prev;
|
|
|
|
|
|
|
|
// unlink
|
|
|
|
if (event->prev)
|
|
|
|
event->prev->next = event->next;
|
|
|
|
else
|
|
|
|
s_active_events_head = event->next;
|
|
|
|
if (event->next)
|
|
|
|
event->next->prev = event->prev;
|
|
|
|
else
|
|
|
|
s_active_events_tail = event->prev;
|
|
|
|
|
|
|
|
// insert after current
|
|
|
|
if (current)
|
|
|
|
{
|
|
|
|
event->next = current->next;
|
|
|
|
if (current->next)
|
|
|
|
current->next->prev = event;
|
|
|
|
else
|
|
|
|
s_active_events_tail = event;
|
|
|
|
|
|
|
|
event->prev = current;
|
|
|
|
current->next = event;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// insert at front
|
|
|
|
DebugAssert(s_active_events_head);
|
|
|
|
s_active_events_head->prev = event;
|
|
|
|
event->prev = nullptr;
|
|
|
|
event->next = s_active_events_head;
|
|
|
|
s_active_events_head = event;
|
|
|
|
UpdateCPUDowncount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (event->next && event_downcount > event->next->m_downcount)
|
|
|
|
{
|
|
|
|
// move forwards
|
|
|
|
TimingEvent* current = event->next;
|
|
|
|
while (current && event_downcount > current->m_downcount)
|
|
|
|
current = current->next;
|
|
|
|
|
|
|
|
// unlink
|
|
|
|
if (event->prev)
|
|
|
|
event->prev->next = event->next;
|
|
|
|
else
|
|
|
|
s_active_events_head = event->next;
|
|
|
|
if (event->next)
|
|
|
|
event->next->prev = event->prev;
|
|
|
|
else
|
|
|
|
s_active_events_tail = event->prev;
|
|
|
|
|
|
|
|
// insert before current
|
|
|
|
if (current)
|
|
|
|
{
|
|
|
|
event->next = current;
|
|
|
|
event->prev = current->prev;
|
|
|
|
|
|
|
|
if (current->prev)
|
|
|
|
current->prev->next = event;
|
|
|
|
else
|
|
|
|
s_active_events_head = event;
|
|
|
|
|
|
|
|
current->prev = event;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// insert at back
|
|
|
|
DebugAssert(s_active_events_tail);
|
|
|
|
s_active_events_tail->next = event;
|
|
|
|
event->next = nullptr;
|
|
|
|
event->prev = s_active_events_tail;
|
|
|
|
s_active_events_tail = event;
|
|
|
|
}
|
|
|
|
}
|
2020-07-31 07:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void AddActiveEvent(TimingEvent* event)
|
|
|
|
{
|
2020-08-31 10:54:59 +00:00
|
|
|
DebugAssert(!event->prev && !event->next);
|
|
|
|
s_active_event_count++;
|
|
|
|
|
|
|
|
TimingEvent* current = nullptr;
|
|
|
|
TimingEvent* next = s_active_events_head;
|
|
|
|
while (next && event->m_downcount > next->m_downcount)
|
|
|
|
{
|
|
|
|
current = next;
|
|
|
|
next = next->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!next)
|
|
|
|
{
|
|
|
|
// new tail
|
|
|
|
event->prev = s_active_events_tail;
|
|
|
|
if (s_active_events_tail)
|
|
|
|
{
|
|
|
|
s_active_events_tail->next = event;
|
|
|
|
s_active_events_tail = event;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// first event
|
|
|
|
s_active_events_tail = event;
|
|
|
|
s_active_events_head = event;
|
|
|
|
UpdateCPUDowncount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!current)
|
2020-07-31 07:09:18 +00:00
|
|
|
{
|
2020-08-31 10:54:59 +00:00
|
|
|
// new head
|
|
|
|
event->next = s_active_events_head;
|
|
|
|
s_active_events_head->prev = event;
|
|
|
|
s_active_events_head = event;
|
2020-07-31 07:09:18 +00:00
|
|
|
UpdateCPUDowncount();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-31 10:54:59 +00:00
|
|
|
// inbetween current < event > next
|
|
|
|
event->prev = current;
|
|
|
|
event->next = next;
|
|
|
|
current->next = event;
|
|
|
|
next->prev = event;
|
2020-07-31 07:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void RemoveActiveEvent(TimingEvent* event)
|
|
|
|
{
|
2020-08-31 10:54:59 +00:00
|
|
|
DebugAssert(s_active_event_count > 0);
|
|
|
|
|
|
|
|
if (event->next)
|
2020-07-31 07:09:18 +00:00
|
|
|
{
|
2020-08-31 10:54:59 +00:00
|
|
|
event->next->prev = event->prev;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s_active_events_tail = event->prev;
|
2020-07-31 07:09:18 +00:00
|
|
|
}
|
|
|
|
|
2020-08-31 10:54:59 +00:00
|
|
|
if (event->prev)
|
2020-07-31 07:09:18 +00:00
|
|
|
{
|
2020-08-31 10:54:59 +00:00
|
|
|
event->prev->next = event->next;
|
2020-07-31 07:09:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-31 10:54:59 +00:00
|
|
|
s_active_events_head = event->next;
|
2020-09-06 07:47:49 +00:00
|
|
|
if (s_active_events_head)
|
|
|
|
UpdateCPUDowncount();
|
2020-07-31 07:09:18 +00:00
|
|
|
}
|
|
|
|
|
2020-08-31 10:54:59 +00:00
|
|
|
event->prev = nullptr;
|
|
|
|
event->next = nullptr;
|
2020-07-31 07:09:18 +00:00
|
|
|
|
2020-08-31 10:54:59 +00:00
|
|
|
s_active_event_count--;
|
2020-07-31 07:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void SortEvents()
|
|
|
|
{
|
2020-08-31 10:54:59 +00:00
|
|
|
std::vector<TimingEvent*> events;
|
|
|
|
events.reserve(s_active_event_count);
|
|
|
|
|
|
|
|
TimingEvent* next = s_active_events_head;
|
|
|
|
while (next)
|
2020-07-31 07:09:18 +00:00
|
|
|
{
|
2020-08-31 10:54:59 +00:00
|
|
|
TimingEvent* current = next;
|
|
|
|
events.push_back(current);
|
|
|
|
next = current->next;
|
|
|
|
current->prev = nullptr;
|
|
|
|
current->next = nullptr;
|
2020-07-31 07:09:18 +00:00
|
|
|
}
|
2020-08-31 10:54:59 +00:00
|
|
|
|
|
|
|
s_active_events_head = nullptr;
|
|
|
|
s_active_events_tail = nullptr;
|
|
|
|
s_active_event_count = 0;
|
|
|
|
|
|
|
|
for (TimingEvent* event : events)
|
|
|
|
AddActiveEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static TimingEvent* FindActiveEvent(const char* name)
|
|
|
|
{
|
|
|
|
for (TimingEvent* event = s_active_events_head; event; event = event->next)
|
2020-07-31 07:09:18 +00:00
|
|
|
{
|
2020-08-31 10:54:59 +00:00
|
|
|
if (event->GetName().compare(name) == 0)
|
|
|
|
return event;
|
2020-07-31 07:09:18 +00:00
|
|
|
}
|
2020-08-31 10:54:59 +00:00
|
|
|
|
|
|
|
return nullptr;
|
2020-07-31 07:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RunEvents()
|
|
|
|
{
|
2020-08-31 10:54:59 +00:00
|
|
|
DebugAssert(!s_current_event);
|
2020-07-31 07:09:18 +00:00
|
|
|
|
2020-10-18 04:43:48 +00:00
|
|
|
TickCount pending_ticks = CPU::GetPendingTicks();
|
2020-07-31 07:09:18 +00:00
|
|
|
CPU::ResetPendingTicks();
|
|
|
|
while (pending_ticks > 0)
|
|
|
|
{
|
2020-08-31 10:54:59 +00:00
|
|
|
const TickCount time = std::min(pending_ticks, s_active_events_head->GetDowncount());
|
2020-07-31 07:09:18 +00:00
|
|
|
s_global_tick_counter += static_cast<u32>(time);
|
|
|
|
pending_ticks -= time;
|
|
|
|
|
|
|
|
// Apply downcount to all events.
|
|
|
|
// This will result in a negative downcount for those events which are late.
|
2020-08-31 10:54:59 +00:00
|
|
|
for (TimingEvent* event = s_active_events_head; event; event = event->next)
|
2020-07-31 07:09:18 +00:00
|
|
|
{
|
2020-08-31 10:54:59 +00:00
|
|
|
event->m_downcount -= time;
|
|
|
|
event->m_time_since_last_run += time;
|
2020-07-31 07:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now we can actually run the callbacks.
|
2020-08-31 10:54:59 +00:00
|
|
|
while (s_active_events_head->m_downcount <= 0)
|
2020-07-31 07:09:18 +00:00
|
|
|
{
|
2020-08-31 10:54:59 +00:00
|
|
|
// move it to the end, since that'll likely be its new position
|
|
|
|
TimingEvent* event = s_active_events_head;
|
|
|
|
s_current_event = event;
|
2020-07-31 07:09:18 +00:00
|
|
|
|
|
|
|
// Factor late time into the time for the next invocation.
|
2020-08-31 10:54:59 +00:00
|
|
|
const TickCount ticks_late = -event->m_downcount;
|
|
|
|
const TickCount ticks_to_execute = event->m_time_since_last_run;
|
|
|
|
event->m_downcount += event->m_interval;
|
|
|
|
event->m_time_since_last_run = 0;
|
2020-07-31 07:09:18 +00:00
|
|
|
|
|
|
|
// The cycles_late is only an indicator, it doesn't modify the cycles to execute.
|
2021-01-09 15:43:59 +00:00
|
|
|
event->m_callback(event->m_callback_param, ticks_to_execute, ticks_late);
|
2020-08-31 10:54:59 +00:00
|
|
|
if (event->m_active)
|
|
|
|
SortEvent(event);
|
2020-07-31 07:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-31 10:54:59 +00:00
|
|
|
s_current_event = nullptr;
|
2020-07-31 07:09:18 +00:00
|
|
|
UpdateCPUDowncount();
|
|
|
|
}
|
|
|
|
|
2020-08-15 04:56:20 +00:00
|
|
|
bool DoState(StateWrapper& sw)
|
2020-07-31 07:09:18 +00:00
|
|
|
{
|
2020-08-15 04:56:20 +00:00
|
|
|
sw.Do(&s_global_tick_counter);
|
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
if (sw.IsReading())
|
|
|
|
{
|
|
|
|
// Load timestamps for the clock events.
|
|
|
|
// Any oneshot events should be recreated by the load state method, so we can fix up their times here.
|
|
|
|
u32 event_count = 0;
|
|
|
|
sw.Do(&event_count);
|
|
|
|
|
|
|
|
for (u32 i = 0; i < event_count; i++)
|
|
|
|
{
|
|
|
|
std::string event_name;
|
|
|
|
TickCount downcount, time_since_last_run, period, interval;
|
|
|
|
sw.Do(&event_name);
|
|
|
|
sw.Do(&downcount);
|
|
|
|
sw.Do(&time_since_last_run);
|
|
|
|
sw.Do(&period);
|
|
|
|
sw.Do(&interval);
|
|
|
|
if (sw.HasError())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
TimingEvent* event = FindActiveEvent(event_name.c_str());
|
|
|
|
if (!event)
|
|
|
|
{
|
|
|
|
Log_WarningPrintf("Save state has event '%s', but couldn't find this event when loading.", event_name.c_str());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Using reschedule is safe here since we call sort afterwards.
|
|
|
|
event->m_downcount = downcount;
|
|
|
|
event->m_time_since_last_run = time_since_last_run;
|
|
|
|
event->m_period = period;
|
|
|
|
event->m_interval = interval;
|
|
|
|
}
|
|
|
|
|
2020-10-18 04:43:48 +00:00
|
|
|
if (sw.GetVersion() < 43)
|
|
|
|
{
|
|
|
|
u32 last_event_run_time = 0;
|
|
|
|
sw.Do(&last_event_run_time);
|
|
|
|
}
|
2020-07-31 07:09:18 +00:00
|
|
|
|
|
|
|
Log_DevPrintf("Loaded %u events from save state.", event_count);
|
|
|
|
SortEvents();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
2020-08-31 10:54:59 +00:00
|
|
|
sw.Do(&s_active_event_count);
|
|
|
|
|
|
|
|
for (TimingEvent* event = s_active_events_head; event; event = event->next)
|
2020-07-31 07:09:18 +00:00
|
|
|
{
|
2020-08-31 10:54:59 +00:00
|
|
|
sw.Do(&event->m_name);
|
|
|
|
sw.Do(&event->m_downcount);
|
|
|
|
sw.Do(&event->m_time_since_last_run);
|
|
|
|
sw.Do(&event->m_period);
|
|
|
|
sw.Do(&event->m_interval);
|
2020-07-31 07:09:18 +00:00
|
|
|
}
|
|
|
|
|
2020-08-31 10:54:59 +00:00
|
|
|
Log_DevPrintf("Wrote %u events to save state.", s_active_event_count);
|
2020-07-31 07:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return !sw.HasError();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace TimingEvents
|
|
|
|
|
2021-01-09 15:43:59 +00:00
|
|
|
TimingEvent::TimingEvent(std::string name, TickCount period, TickCount interval, TimingEventCallback callback,
|
|
|
|
void* callback_param)
|
2021-02-06 09:19:55 +00:00
|
|
|
: m_callback(callback), m_callback_param(callback_param), m_downcount(interval), m_time_since_last_run(0),
|
|
|
|
m_period(period), m_interval(interval), m_name(std::move(name))
|
2020-01-24 04:53:40 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TimingEvent::~TimingEvent()
|
|
|
|
{
|
|
|
|
if (m_active)
|
2020-07-31 07:09:18 +00:00
|
|
|
TimingEvents::RemoveActiveEvent(this);
|
2020-01-24 04:53:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TickCount TimingEvent::GetTicksSinceLastExecution() const
|
|
|
|
{
|
2020-07-31 07:09:18 +00:00
|
|
|
return CPU::GetPendingTicks() + m_time_since_last_run;
|
2020-01-24 04:53:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TickCount TimingEvent::GetTicksUntilNextExecution() const
|
|
|
|
{
|
2020-07-31 07:09:18 +00:00
|
|
|
return std::max(m_downcount - CPU::GetPendingTicks(), static_cast<TickCount>(0));
|
2020-01-24 04:53:40 +00:00
|
|
|
}
|
|
|
|
|
2021-06-14 04:55:20 +00:00
|
|
|
void TimingEvent::Delay(TickCount ticks)
|
|
|
|
{
|
|
|
|
if (!m_active)
|
|
|
|
{
|
|
|
|
Panic("Trying to delay an inactive event");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_downcount += ticks;
|
2021-07-31 03:25:03 +00:00
|
|
|
|
|
|
|
DebugAssert(TimingEvents::s_current_event != this);
|
|
|
|
TimingEvents::SortEvent(this);
|
2021-06-14 04:55:20 +00:00
|
|
|
}
|
|
|
|
|
2020-01-24 04:53:40 +00:00
|
|
|
void TimingEvent::Schedule(TickCount ticks)
|
|
|
|
{
|
2020-07-31 07:09:18 +00:00
|
|
|
const TickCount pending_ticks = CPU::GetPendingTicks();
|
2020-03-23 14:20:45 +00:00
|
|
|
m_downcount = pending_ticks + ticks;
|
2020-01-24 04:53:40 +00:00
|
|
|
|
2020-03-23 14:20:45 +00:00
|
|
|
if (!m_active)
|
2020-01-24 04:53:40 +00:00
|
|
|
{
|
2020-03-23 14:20:45 +00:00
|
|
|
// Event is going active, so we want it to only execute ticks from the current timestamp.
|
|
|
|
m_time_since_last_run = -pending_ticks;
|
|
|
|
m_active = true;
|
2020-07-31 07:09:18 +00:00
|
|
|
TimingEvents::AddActiveEvent(this);
|
2020-01-24 04:53:40 +00:00
|
|
|
}
|
2020-03-23 14:20:45 +00:00
|
|
|
else
|
2020-01-24 04:53:40 +00:00
|
|
|
{
|
2020-03-23 14:20:45 +00:00
|
|
|
// Event is already active, so we leave the time since last run alone, and just modify the downcount.
|
2020-01-24 04:53:40 +00:00
|
|
|
// If this is a call from an IO handler for example, re-sort the event queue.
|
2020-08-31 10:54:59 +00:00
|
|
|
if (TimingEvents::s_current_event != this)
|
|
|
|
TimingEvents::SortEvent(this);
|
2020-01-24 04:53:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TimingEvent::SetIntervalAndSchedule(TickCount ticks)
|
|
|
|
{
|
|
|
|
SetInterval(ticks);
|
|
|
|
Schedule(ticks);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TimingEvent::SetPeriodAndSchedule(TickCount ticks)
|
|
|
|
{
|
|
|
|
SetPeriod(ticks);
|
|
|
|
SetInterval(ticks);
|
|
|
|
Schedule(ticks);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TimingEvent::Reset()
|
|
|
|
{
|
|
|
|
if (!m_active)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_downcount = m_interval;
|
|
|
|
m_time_since_last_run = 0;
|
2020-08-31 10:54:59 +00:00
|
|
|
if (TimingEvents::s_current_event != this)
|
|
|
|
TimingEvents::SortEvent(this);
|
2020-01-24 04:53:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TimingEvent::InvokeEarly(bool force /* = false */)
|
|
|
|
{
|
|
|
|
if (!m_active)
|
|
|
|
return;
|
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
const TickCount pending_ticks = CPU::GetPendingTicks();
|
2020-01-24 04:53:40 +00:00
|
|
|
const TickCount ticks_to_execute = m_time_since_last_run + pending_ticks;
|
2021-07-03 04:29:39 +00:00
|
|
|
if ((!force && ticks_to_execute < m_period) || ticks_to_execute <= 0)
|
2020-01-24 04:53:40 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
m_downcount = pending_ticks + m_interval;
|
|
|
|
m_time_since_last_run -= ticks_to_execute;
|
2021-01-09 15:43:59 +00:00
|
|
|
m_callback(m_callback_param, ticks_to_execute, 0);
|
2020-01-24 04:53:40 +00:00
|
|
|
|
|
|
|
// Since we've changed the downcount, we need to re-sort the events.
|
2020-08-31 10:54:59 +00:00
|
|
|
DebugAssert(TimingEvents::s_current_event != this);
|
|
|
|
TimingEvents::SortEvent(this);
|
2020-01-24 04:53:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TimingEvent::Activate()
|
|
|
|
{
|
|
|
|
if (m_active)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// leave the downcount intact
|
2020-07-31 07:09:18 +00:00
|
|
|
const TickCount pending_ticks = CPU::GetPendingTicks();
|
2020-01-24 04:53:40 +00:00
|
|
|
m_downcount += pending_ticks;
|
|
|
|
m_time_since_last_run -= pending_ticks;
|
|
|
|
|
|
|
|
m_active = true;
|
2020-07-31 07:09:18 +00:00
|
|
|
TimingEvents::AddActiveEvent(this);
|
2020-01-24 04:53:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TimingEvent::Deactivate()
|
|
|
|
{
|
|
|
|
if (!m_active)
|
|
|
|
return;
|
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
const TickCount pending_ticks = CPU::GetPendingTicks();
|
2020-01-24 04:53:40 +00:00
|
|
|
m_downcount -= pending_ticks;
|
|
|
|
m_time_since_last_run += pending_ticks;
|
|
|
|
|
|
|
|
m_active = false;
|
2020-07-31 07:09:18 +00:00
|
|
|
TimingEvents::RemoveActiveEvent(this);
|
2020-01-24 04:53:40 +00:00
|
|
|
}
|