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

73 lines
2.0 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"
2023-11-06 00:11:54 +01:00
#include "core/hle/error_codes.h"
#include "core/hle/kernel/event_queues.h"
2023-11-06 00:11:54 +01:00
namespace Core::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!");
2023-08-17 09:10:13 +02:00
return SCE_KERNEL_ERROR_EINVAL;
}
if (name == nullptr) {
LOG_ERROR(Kernel_Event, "Event queue name is invalid!");
2023-08-17 09:10:13 +02:00
return SCE_KERNEL_ERROR_EFAULT;
}
if (name == NULL) {
LOG_ERROR(Kernel_Event, "Event queue name is null!");
2023-08-17 09:10:13 +02:00
return SCE_KERNEL_ERROR_EINVAL;
}
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!");
2023-08-17 09:10:13 +02:00
return SCE_KERNEL_ERROR_ENAMETOOLONG;
}
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));
return SCE_OK;
}
int PS4_SYSV_ABI sceKernelWaitEqueue(SceKernelEqueue eq, SceKernelEvent* ev, int num, int* out,
SceKernelUseconds* timo) {
LOG_INFO(Kernel_Event, "num = {}", num);
if (eq == nullptr) {
return SCE_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
return SCE_OK;
}
2023-11-06 00:11:54 +01:00
} // namespace Core::Kernel