kernel: event queue improvements

This commit is contained in:
psucien 2024-05-17 23:32:15 +02:00
parent 133acdc120
commit 45e73d324a
2 changed files with 17 additions and 12 deletions

View File

@ -12,7 +12,6 @@ EqueueInternal::~EqueueInternal() = default;
int EqueueInternal::addEvent(const EqueueEvent& event) { int EqueueInternal::addEvent(const EqueueEvent& event) {
std::scoped_lock lock{m_mutex}; std::scoped_lock lock{m_mutex};
ASSERT(m_events.empty());
ASSERT(!event.isTriggered); ASSERT(!event.isTriggered);
// TODO check if event is already exists and return it. Currently we just add in m_events array // TODO check if event is already exists and return it. Currently we just add in m_events array
@ -21,6 +20,8 @@ int EqueueInternal::addEvent(const EqueueEvent& event) {
} }
int EqueueInternal::removeEvent(u64 id) { int EqueueInternal::removeEvent(u64 id) {
std::scoped_lock lock{m_mutex};
const auto& event_q = const auto& event_q =
std::ranges::find_if(m_events, [id](auto& ev) { return ev.event.ident == id; }); std::ranges::find_if(m_events, [id](auto& ev) { return ev.event.ident == id; });
ASSERT(event_q != m_events.cend()); ASSERT(event_q != m_events.cend());
@ -51,12 +52,15 @@ int EqueueInternal::waitForEvents(SceKernelEvent* ev, int num, u32 micros) {
} }
bool EqueueInternal::triggerEvent(u64 ident, s16 filter, void* trigger_data) { bool EqueueInternal::triggerEvent(u64 ident, s16 filter, void* trigger_data) {
{
std::scoped_lock lock{m_mutex}; std::scoped_lock lock{m_mutex};
ASSERT(m_events.size() <= 1); for (auto& event : m_events) {
if (event.event.ident == ident) { // event filter?
auto& event = m_events[0];
event.trigger(trigger_data); event.trigger(trigger_data);
}
}
}
m_cond.notify_one(); m_cond.notify_one();
return true; return true;
@ -65,13 +69,12 @@ bool EqueueInternal::triggerEvent(u64 ident, s16 filter, void* trigger_data) {
int EqueueInternal::getTriggeredEvents(SceKernelEvent* ev, int num) { int EqueueInternal::getTriggeredEvents(SceKernelEvent* ev, int num) {
int ret = 0; int ret = 0;
ASSERT(m_events.size() <= 1); for (auto& event : m_events) {
auto& event = m_events[0];
if (event.isTriggered) { if (event.isTriggered) {
ev[ret++] = event.event; ev[ret++] = event.event;
event.reset(); event.reset();
} }
}
return ret; return ret;
} }

View File

@ -196,6 +196,8 @@ void LibKernel_Register(Core::Loader::SymbolsResolver* sym) {
LIB_FUNCTION("D0OdFMjp46I", "libkernel", 1, "libkernel", 1, 1, sceKernelCreateEqueue); LIB_FUNCTION("D0OdFMjp46I", "libkernel", 1, "libkernel", 1, 1, sceKernelCreateEqueue);
LIB_FUNCTION("jpFjmgAC5AE", "libkernel", 1, "libkernel", 1, 1, sceKernelDeleteEqueue); LIB_FUNCTION("jpFjmgAC5AE", "libkernel", 1, "libkernel", 1, 1, sceKernelDeleteEqueue);
LIB_FUNCTION("fzyMKs9kim0", "libkernel", 1, "libkernel", 1, 1, sceKernelWaitEqueue); LIB_FUNCTION("fzyMKs9kim0", "libkernel", 1, "libkernel", 1, 1, sceKernelWaitEqueue);
LIB_FUNCTION("vz+pg2zdopI", "libkernel", 1, "libkernel", 1, 1, sceKernelGetEventUserData);
LIB_FUNCTION("4R6-OvI2cEA", "libkernel", 1, "libkernel", 1, 1, sceKernelAddUserEvent);
// misc // misc
LIB_FUNCTION("WslcK1FQcGI", "libkernel", 1, "libkernel", 1, 1, sceKernelIsNeoMode); LIB_FUNCTION("WslcK1FQcGI", "libkernel", 1, "libkernel", 1, 1, sceKernelIsNeoMode);
LIB_FUNCTION("Ou3iL1abvng", "libkernel", 1, "libkernel", 1, 1, stack_chk_fail); LIB_FUNCTION("Ou3iL1abvng", "libkernel", 1, "libkernel", 1, 1, stack_chk_fail);