shadPS4/src/core/libraries/kernel/event_queues.cpp

102 lines
2.6 KiB
C++
Raw Normal View History

2024-02-23 22:32:32 +01:00
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/assert.h"
#include "common/logging/log.h"
2024-04-13 23:35:48 +02:00
#include "core/libraries/error_codes.h"
#include "core/libraries/kernel/event_queues.h"
2023-11-06 00:11:54 +01:00
2024-04-13 23:35:48 +02:00
namespace Libraries::Kernel {
2023-08-17 09:10:13 +02:00
int PS4_SYSV_ABI sceKernelCreateEqueue(SceKernelEqueue* eq, const char* name) {
if (eq == nullptr) {
LOG_ERROR(Kernel_Event, "Event queue is null!");
2024-05-10 22:04:41 +02:00
return ORBIS_KERNEL_ERROR_EINVAL;
2023-08-17 09:10:13 +02:00
}
if (name == nullptr) {
LOG_ERROR(Kernel_Event, "Event queue name is null!");
2024-05-10 22:04:41 +02:00
return ORBIS_KERNEL_ERROR_EINVAL;
2023-08-17 09:10:13 +02:00
}
2023-08-17 09:11:50 +02:00
// Maximum is 32 including null terminator
static constexpr size_t MaxEventQueueNameSize = 32;
if (std::strlen(name) > MaxEventQueueNameSize) {
LOG_ERROR(Kernel_Event, "Event queue name exceeds 32 bytes!");
2024-05-10 22:04:41 +02:00
return ORBIS_KERNEL_ERROR_ENAMETOOLONG;
2023-08-17 09:10:13 +02:00
}
LOG_INFO(Kernel_Event, "name = {}", name);
2023-11-06 00:11:54 +01:00
*eq = new EqueueInternal;
2023-08-17 09:10:13 +02:00
(*eq)->setName(std::string(name));
2024-05-10 22:04:41 +02:00
return ORBIS_OK;
}
int PS4_SYSV_ABI sceKernelDeleteEqueue(SceKernelEqueue eq) {
if (eq == nullptr) {
2024-05-17 23:29:10 +02:00
return ORBIS_KERNEL_ERROR_EBADF;
2024-05-10 22:04:41 +02:00
}
delete eq;
return ORBIS_OK;
2023-08-17 09:10:13 +02:00
}
int PS4_SYSV_ABI sceKernelWaitEqueue(SceKernelEqueue eq, SceKernelEvent* ev, int num, int* out,
SceKernelUseconds* timo) {
LOG_INFO(Kernel_Event, "num = {}", num);
if (eq == nullptr) {
2024-05-17 23:29:10 +02:00
return ORBIS_KERNEL_ERROR_EBADF;
}
if (ev == nullptr) {
return SCE_KERNEL_ERROR_EFAULT;
}
if (num < 1) {
return SCE_KERNEL_ERROR_EINVAL;
}
2023-11-06 00:11:54 +01:00
if (timo == nullptr) { // wait until an event arrives without timing out
*out = eq->waitForEvents(ev, num, 0);
}
2023-11-06 00:11:54 +01:00
if (timo != nullptr) {
2023-11-06 00:11:54 +01:00
// Only events that have already arrived at the time of this function call can be received
if (*timo == 0) {
UNREACHABLE();
2023-11-06 00:11:54 +01:00
} else {
// Wait until an event arrives with timing out
UNREACHABLE();
}
}
2023-11-06 00:11:54 +01:00
2024-05-17 23:29:10 +02:00
return ORBIS_OK;
}
int PS4_SYSV_ABI sceKernelAddUserEvent(SceKernelEqueue eq, int id) {
if (eq == nullptr) {
return ORBIS_KERNEL_ERROR_EBADF;
}
Kernel::EqueueEvent event{};
event.isTriggered = false;
event.event.ident = id;
event.event.filter = Kernel::EVFILT_USER;
event.event.udata = 0;
event.event.fflags = 0;
event.event.data = 0;
return eq->addEvent(event);
}
void* PS4_SYSV_ABI sceKernelGetEventUserData(const SceKernelEvent* ev) {
if (!ev) {
return nullptr;
}
return ev->udata;
}
2024-04-13 23:35:48 +02:00
} // namespace Libraries::Kernel