kernel: event_queue: slight event class refactoring

This commit is contained in:
psucien 2024-06-18 09:22:51 +02:00
parent 76c92a9dfb
commit fe30369349
4 changed files with 22 additions and 14 deletions

View File

@ -11,9 +11,11 @@ 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(!event.isTriggered); ASSERT(!event.IsTriggered());
const auto& it = std::ranges::find(m_events, event);
ASSERT(it == m_events.cend()); // TODO: update event if found
// TODO check if event is already exists and return it. Currently we just add in m_events array
m_events.push_back(event); m_events.push_back(event);
return 0; return 0;
} }
@ -51,7 +53,7 @@ bool EqueueInternal::triggerEvent(u64 ident, s16 filter, void* trigger_data) {
for (auto& event : m_events) { for (auto& event : m_events) {
if (event.event.ident == ident) { // event filter? if (event.event.ident == ident) { // event filter?
event.trigger(trigger_data); event.Trigger(trigger_data);
} }
} }
} }
@ -64,9 +66,9 @@ int EqueueInternal::getTriggeredEvents(SceKernelEvent* ev, int num) {
int ret = 0; int ret = 0;
for (auto& event : m_events) { for (auto& event : m_events) {
if (event.isTriggered) { if (event.IsTriggered()) {
ev[ret++] = event.event; ev[ret++] = event.event;
event.reset(); event.Reset();
} }
} }

View File

@ -73,21 +73,31 @@ struct Filter {
}; };
struct EqueueEvent { struct EqueueEvent {
bool isTriggered = false;
SceKernelEvent event; SceKernelEvent event;
Filter filter; Filter filter;
void reset() { void Reset() {
isTriggered = false; is_triggered = false;
event.fflags = 0; event.fflags = 0;
event.data = 0; event.data = 0;
} }
void trigger(void* data) { void Trigger(void* data) {
isTriggered = true; is_triggered = true;
event.fflags++; event.fflags++;
event.data = reinterpret_cast<uintptr_t>(data); event.data = reinterpret_cast<uintptr_t>(data);
} }
bool IsTriggered() const {
return is_triggered;
}
bool operator==(const EqueueEvent& ev) const {
return ev.event.ident == event.ident;
}
private:
bool is_triggered = false;
}; };
class EqueueInternal { class EqueueInternal {

View File

@ -84,7 +84,6 @@ int PS4_SYSV_ABI sceKernelAddUserEvent(SceKernelEqueue eq, int id) {
} }
Kernel::EqueueEvent event{}; Kernel::EqueueEvent event{};
event.isTriggered = false;
event.event.ident = id; event.event.ident = id;
event.event.filter = Kernel::EVFILT_USER; event.event.filter = Kernel::EVFILT_USER;
event.event.udata = 0; event.event.udata = 0;
@ -101,7 +100,6 @@ int PS4_SYSV_ABI sceKernelAddUserEventEdge(SceKernelEqueue eq, int id) {
} }
Kernel::EqueueEvent event{}; Kernel::EqueueEvent event{};
event.isTriggered = false;
event.event.ident = id; event.event.ident = id;
event.event.filter = Kernel::EVFILT_USER; event.event.filter = Kernel::EVFILT_USER;
event.event.udata = 0; event.event.udata = 0;

View File

@ -48,7 +48,6 @@ s32 PS4_SYSV_ABI sceVideoOutAddFlipEvent(Kernel::SceKernelEqueue eq, s32 handle,
} }
Kernel::EqueueEvent event{}; Kernel::EqueueEvent event{};
event.isTriggered = false;
event.event.ident = SCE_VIDEO_OUT_EVENT_FLIP; event.event.ident = SCE_VIDEO_OUT_EVENT_FLIP;
event.event.filter = Kernel::EVFILT_VIDEO_OUT; event.event.filter = Kernel::EVFILT_VIDEO_OUT;
event.event.udata = udata; event.event.udata = udata;
@ -73,7 +72,6 @@ s32 PS4_SYSV_ABI sceVideoOutAddVblankEvent(Kernel::SceKernelEqueue eq, s32 handl
} }
Kernel::EqueueEvent event{}; Kernel::EqueueEvent event{};
event.isTriggered = false;
event.event.ident = SCE_VIDEO_OUT_EVENT_VBLANK; event.event.ident = SCE_VIDEO_OUT_EVENT_VBLANK;
event.event.filter = Kernel::EVFILT_VIDEO_OUT; event.event.filter = Kernel::EVFILT_VIDEO_OUT;
event.event.udata = udata; event.event.udata = udata;