This commit is contained in:
Fire Cube 2025-06-14 23:30:24 +02:00
parent 623e195ee8
commit 95d592ebf0
2 changed files with 31 additions and 19 deletions

View File

@ -179,18 +179,19 @@ int EqueueInternal::GetTriggeredEvents(SceKernelEvent* ev, int num) {
} }
bool EqueueInternal::AddSmallTimer(EqueueEvent& ev) { bool EqueueInternal::AddSmallTimer(EqueueEvent& ev) {
// the small timer storage and wait logic should be reworked. SmallTimer st;
st.event = ev.event;
// id check st.added = std::chrono::steady_clock::now();
ev.time_added = std::chrono::steady_clock::now(); st.interval = std::chrono::microseconds{ev.event.data};
small_timer_event = std::move(ev); {
std::scoped_lock lock{m_mutex};
m_small_timers[st.event.ident] = std::move(st);
}
return true; return true;
} }
int EqueueInternal::WaitForSmallTimer(SceKernelEvent* ev, int num, u32 micros) { int EqueueInternal::WaitForSmallTimer(SceKernelEvent* ev, int num, u32 micros) {
int count{}; ASSERT(num == 1); // Could be extended to support more events if needed
ASSERT(num == 1);
auto curr_clock = std::chrono::steady_clock::now(); auto curr_clock = std::chrono::steady_clock::now();
const auto wait_end_us = (micros == 0) ? std::chrono::steady_clock::time_point::max() const auto wait_end_us = (micros == 0) ? std::chrono::steady_clock::time_point::max()
@ -200,17 +201,19 @@ int EqueueInternal::WaitForSmallTimer(SceKernelEvent* ev, int num, u32 micros) {
curr_clock = std::chrono::steady_clock::now(); curr_clock = std::chrono::steady_clock::now();
{ {
std::scoped_lock lock{m_mutex}; std::scoped_lock lock{m_mutex};
if ((curr_clock - small_timer_event.time_added) > for (auto it = m_small_timers.begin(); it != m_small_timers.end(); ++it) {
std::chrono::microseconds{small_timer_event.event.data}) { const SmallTimer& st = it->second;
ev[count++] = small_timer_event.event; if (curr_clock - st.added >= st.interval) {
small_timer_event.event.data = 0; ev[0] = st.event;
break; m_small_timers.erase(it);
return 1;
}
} }
} }
std::this_thread::yield(); std::this_thread::yield();
} while (curr_clock < wait_end_us); } while (curr_clock < wait_end_us);
return count; return 0;
} }
bool EqueueInternal::EventExists(u64 id, s16 filter) { bool EqueueInternal::EventExists(u64 id, s16 filter) {

View File

@ -9,6 +9,7 @@
#include <vector> #include <vector>
#include <boost/asio/steady_timer.hpp> #include <boost/asio/steady_timer.hpp>
#include <unordered_map>
#include "common/rdtsc.h" #include "common/rdtsc.h"
#include "common/types.h" #include "common/types.h"
@ -135,6 +136,12 @@ private:
}; };
class EqueueInternal { class EqueueInternal {
struct SmallTimer {
SceKernelEvent event;
std::chrono::steady_clock::time_point added;
std::chrono::microseconds interval;
};
public: public:
explicit EqueueInternal(std::string_view name) : m_name(name) {} explicit EqueueInternal(std::string_view name) : m_name(name) {}
@ -151,13 +158,14 @@ public:
int GetTriggeredEvents(SceKernelEvent* ev, int num); int GetTriggeredEvents(SceKernelEvent* ev, int num);
bool AddSmallTimer(EqueueEvent& event); bool AddSmallTimer(EqueueEvent& event);
bool HasSmallTimer() const { bool HasSmallTimer() {
return small_timer_event.event.data != 0; std::scoped_lock lock{m_mutex};
return !m_small_timers.empty();
} }
bool RemoveSmallTimer(u64 id) { bool RemoveSmallTimer(u64 id) {
if (HasSmallTimer() && small_timer_event.event.ident == id) { if (HasSmallTimer()) {
small_timer_event = {}; std::scoped_lock lock{m_mutex};
return true; return m_small_timers.erase(id) > 0;
} }
return false; return false;
} }
@ -172,6 +180,7 @@ private:
std::vector<EqueueEvent> m_events; std::vector<EqueueEvent> m_events;
EqueueEvent small_timer_event{}; EqueueEvent small_timer_event{};
std::condition_variable m_cond; std::condition_variable m_cond;
std::unordered_map<u64, SmallTimer> m_small_timers;
}; };
u64 PS4_SYSV_ABI sceKernelGetEventData(const SceKernelEvent* ev); u64 PS4_SYSV_ABI sceKernelGetEventData(const SceKernelEvent* ev);