2023-11-05 12:41:10 +01:00
|
|
|
#include "common/debug.h"
|
2023-11-06 00:11:54 +01:00
|
|
|
#include "common/log.h"
|
|
|
|
#include "core/hle/kernel/event_queues.h"
|
|
|
|
#include "core/hle/error_codes.h"
|
|
|
|
#include "core/hle/libraries/libs.h"
|
|
|
|
|
|
|
|
namespace Core::Kernel {
|
2023-08-17 09:10:13 +02:00
|
|
|
|
|
|
|
constexpr bool log_file_equeues = true; // disable it to disable logging
|
|
|
|
|
|
|
|
int PS4_SYSV_ABI sceKernelCreateEqueue(SceKernelEqueue* eq, const char* name) {
|
|
|
|
PRINT_FUNCTION_NAME();
|
2023-08-17 09:11:50 +02:00
|
|
|
|
2023-08-17 09:10:13 +02:00
|
|
|
if (eq == nullptr) {
|
|
|
|
LOG_TRACE_IF(log_file_equeues, "sceKernelCreateEqueue returned SCE_KERNEL_ERROR_EINVAL eq invalid\n");
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
if (name == nullptr) {
|
|
|
|
LOG_TRACE_IF(log_file_equeues, "sceKernelCreateEqueue returned SCE_KERNEL_ERROR_EFAULT name invalid\n");
|
|
|
|
return SCE_KERNEL_ERROR_EFAULT;
|
|
|
|
}
|
|
|
|
if (name == NULL) {
|
|
|
|
LOG_TRACE_IF(log_file_equeues, "sceKernelCreateEqueue returned SCE_KERNEL_ERROR_EINVAL name is null\n");
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
2023-08-17 09:11:50 +02:00
|
|
|
|
2023-08-17 09:10:13 +02:00
|
|
|
if (strlen(name) > 31) { // max is 32 including null terminator
|
|
|
|
LOG_TRACE_IF(log_file_equeues, "sceKernelCreateEqueue returned SCE_KERNEL_ERROR_ENAMETOOLONG name size exceeds 32 bytes\n");
|
|
|
|
return SCE_KERNEL_ERROR_ENAMETOOLONG;
|
|
|
|
}
|
2023-11-06 00:11:54 +01:00
|
|
|
*eq = new EqueueInternal;
|
2023-08-17 09:10:13 +02:00
|
|
|
(*eq)->setName(std::string(name));
|
|
|
|
|
|
|
|
LOG_INFO_IF(log_file_equeues, "sceKernelCreateEqueue created with name \"{}\"\n", name);
|
|
|
|
return SCE_OK;
|
|
|
|
}
|
2023-09-08 07:28:01 +02:00
|
|
|
|
2023-11-06 00:11:54 +01:00
|
|
|
int PS4_SYSV_ABI sceKernelWaitEqueue(SceKernelEqueue eq, SceKernelEvent* ev,
|
|
|
|
int num, int* out, SceKernelUseconds* timo) {
|
2023-09-08 07:28:01 +02:00
|
|
|
PRINT_FUNCTION_NAME();
|
|
|
|
|
|
|
|
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
|
|
|
|
2023-09-08 07:28:01 +02:00
|
|
|
if (timo == nullptr) { // wait until an event arrives without timing out
|
2023-09-10 00:06:14 +02:00
|
|
|
*out = eq->waitForEvents(ev, num, 0);
|
2023-09-08 07:28:01 +02:00
|
|
|
}
|
2023-11-06 00:11:54 +01:00
|
|
|
|
2023-09-08 07:28:01 +02: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) {
|
2023-09-08 07:28:01 +02:00
|
|
|
BREAKPOINT();
|
2023-11-06 00:11:54 +01:00
|
|
|
} else {
|
|
|
|
// Wait until an event arrives with timing out
|
2023-09-08 07:28:01 +02:00
|
|
|
BREAKPOINT();
|
|
|
|
}
|
|
|
|
}
|
2023-11-06 00:11:54 +01:00
|
|
|
|
2023-09-08 07:28:01 +02:00
|
|
|
return SCE_OK;
|
|
|
|
}
|
|
|
|
|
2023-11-06 00:11:54 +01:00
|
|
|
} // namespace Core::Kernel
|