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) {
std::scoped_lock lock{m_mutex};
ASSERT(m_events.empty());
ASSERT(!event.isTriggered);
// 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) {
std::scoped_lock lock{m_mutex};
const auto& event_q =
std::ranges::find_if(m_events, [id](auto& ev) { return ev.event.ident == id; });
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) {
std::scoped_lock lock{m_mutex};
{
std::scoped_lock lock{m_mutex};
ASSERT(m_events.size() <= 1);
auto& event = m_events[0];
event.trigger(trigger_data);
for (auto& event : m_events) {
if (event.event.ident == ident) { // event filter?
event.trigger(trigger_data);
}
}
}
m_cond.notify_one();
return true;
@ -65,12 +69,11 @@ bool EqueueInternal::triggerEvent(u64 ident, s16 filter, void* trigger_data) {
int EqueueInternal::getTriggeredEvents(SceKernelEvent* ev, int num) {
int ret = 0;
ASSERT(m_events.size() <= 1);
auto& event = m_events[0];
if (event.isTriggered) {
ev[ret++] = event.event;
event.reset();
for (auto& event : m_events) {
if (event.isTriggered) {
ev[ret++] = event.event;
event.reset();
}
}
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("jpFjmgAC5AE", "libkernel", 1, "libkernel", 1, 1, sceKernelDeleteEqueue);
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
LIB_FUNCTION("WslcK1FQcGI", "libkernel", 1, "libkernel", 1, 1, sceKernelIsNeoMode);
LIB_FUNCTION("Ou3iL1abvng", "libkernel", 1, "libkernel", 1, 1, stack_chk_fail);