Skip to content

Commit

Permalink
Revert "semaphore: Use handles to properly handle semaphore double-de…
Browse files Browse the repository at this point in the history
…lete. (shadps4-emu#1728)"

This reverts commit 41fd1c8.
  • Loading branch information
MajorP93 committed Dec 10, 2024
1 parent e5e1aba commit c152afb
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/core/libraries/kernel/threads/semaphore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "core/libraries/kernel/sync/semaphore.h"

#include "common/logging/log.h"
#include "common/slot_vector.h"
#include "core/libraries/kernel/kernel.h"
#include "core/libraries/kernel/orbis_error.h"
#include "core/libraries/kernel/posix_error.h"
Expand Down Expand Up @@ -189,58 +188,55 @@ class OrbisSem {
bool is_fifo;
};

using OrbisKernelSema = Common::SlotId;

static Common::SlotVector<std::unique_ptr<OrbisSem>> orbis_sems;
using OrbisKernelSema = OrbisSem*;

s32 PS4_SYSV_ABI sceKernelCreateSema(OrbisKernelSema* sem, const char* pName, u32 attr,
s32 initCount, s32 maxCount, const void* pOptParam) {
if (!pName || attr > 2 || initCount < 0 || maxCount <= 0 || initCount > maxCount) {
LOG_ERROR(Lib_Kernel, "Semaphore creation parameters are invalid!");
return ORBIS_KERNEL_ERROR_EINVAL;
}
*sem = orbis_sems.insert(
std::move(std::make_unique<OrbisSem>(initCount, maxCount, pName, attr == 1)));
*sem = new OrbisSem(initCount, maxCount, pName, attr == 1);
return ORBIS_OK;
}

s32 PS4_SYSV_ABI sceKernelWaitSema(OrbisKernelSema sem, s32 needCount, u32* pTimeout) {
if (!orbis_sems.is_allocated(sem)) {
if (!sem) {
return ORBIS_KERNEL_ERROR_ESRCH;
}
return orbis_sems[sem]->Wait(true, needCount, pTimeout);
return sem->Wait(true, needCount, pTimeout);
}

s32 PS4_SYSV_ABI sceKernelSignalSema(OrbisKernelSema sem, s32 signalCount) {
if (!orbis_sems.is_allocated(sem)) {
if (!sem) {
return ORBIS_KERNEL_ERROR_ESRCH;
}
if (!orbis_sems[sem]->Signal(signalCount)) {
if (!sem->Signal(signalCount)) {
return ORBIS_KERNEL_ERROR_EINVAL;
}
return ORBIS_OK;
}

s32 PS4_SYSV_ABI sceKernelPollSema(OrbisKernelSema sem, s32 needCount) {
if (!orbis_sems.is_allocated(sem)) {
if (!sem) {
return ORBIS_KERNEL_ERROR_ESRCH;
}
return orbis_sems[sem]->Wait(false, needCount, nullptr);
return sem->Wait(false, needCount, nullptr);
}

int PS4_SYSV_ABI sceKernelCancelSema(OrbisKernelSema sem, s32 setCount, s32* pNumWaitThreads) {
if (!orbis_sems.is_allocated(sem)) {
if (!sem) {
return ORBIS_KERNEL_ERROR_ESRCH;
}
return orbis_sems[sem]->Cancel(setCount, pNumWaitThreads);
return sem->Cancel(setCount, pNumWaitThreads);
}

int PS4_SYSV_ABI sceKernelDeleteSema(OrbisKernelSema sem) {
if (!orbis_sems.is_allocated(sem)) {
if (!sem) {
return ORBIS_KERNEL_ERROR_ESRCH;
}
orbis_sems[sem]->Delete();
orbis_sems.erase(sem);
sem->Delete();
delete sem;
return ORBIS_OK;
}

Expand Down

0 comments on commit c152afb

Please sign in to comment.