|
9 | 9 | #include "core/libraries/kernel/sync/semaphore.h"
|
10 | 10 |
|
11 | 11 | #include "common/logging/log.h"
|
| 12 | +#include "common/slot_vector.h" |
12 | 13 | #include "core/libraries/kernel/kernel.h"
|
13 | 14 | #include "core/libraries/kernel/orbis_error.h"
|
14 | 15 | #include "core/libraries/kernel/posix_error.h"
|
@@ -188,55 +189,58 @@ class OrbisSem {
|
188 | 189 | bool is_fifo;
|
189 | 190 | };
|
190 | 191 |
|
191 |
| -using OrbisKernelSema = OrbisSem*; |
| 192 | +using OrbisKernelSema = Common::SlotId; |
| 193 | + |
| 194 | +static Common::SlotVector<std::unique_ptr<OrbisSem>> orbis_sems; |
192 | 195 |
|
193 | 196 | s32 PS4_SYSV_ABI sceKernelCreateSema(OrbisKernelSema* sem, const char* pName, u32 attr,
|
194 | 197 | s32 initCount, s32 maxCount, const void* pOptParam) {
|
195 | 198 | if (!pName || attr > 2 || initCount < 0 || maxCount <= 0 || initCount > maxCount) {
|
196 | 199 | LOG_ERROR(Lib_Kernel, "Semaphore creation parameters are invalid!");
|
197 | 200 | return ORBIS_KERNEL_ERROR_EINVAL;
|
198 | 201 | }
|
199 |
| - *sem = new OrbisSem(initCount, maxCount, pName, attr == 1); |
| 202 | + *sem = orbis_sems.insert( |
| 203 | + std::move(std::make_unique<OrbisSem>(initCount, maxCount, pName, attr == 1))); |
200 | 204 | return ORBIS_OK;
|
201 | 205 | }
|
202 | 206 |
|
203 | 207 | s32 PS4_SYSV_ABI sceKernelWaitSema(OrbisKernelSema sem, s32 needCount, u32* pTimeout) {
|
204 |
| - if (!sem) { |
| 208 | + if (!orbis_sems.is_allocated(sem)) { |
205 | 209 | return ORBIS_KERNEL_ERROR_ESRCH;
|
206 | 210 | }
|
207 |
| - return sem->Wait(true, needCount, pTimeout); |
| 211 | + return orbis_sems[sem]->Wait(true, needCount, pTimeout); |
208 | 212 | }
|
209 | 213 |
|
210 | 214 | s32 PS4_SYSV_ABI sceKernelSignalSema(OrbisKernelSema sem, s32 signalCount) {
|
211 |
| - if (!sem) { |
| 215 | + if (!orbis_sems.is_allocated(sem)) { |
212 | 216 | return ORBIS_KERNEL_ERROR_ESRCH;
|
213 | 217 | }
|
214 |
| - if (!sem->Signal(signalCount)) { |
| 218 | + if (!orbis_sems[sem]->Signal(signalCount)) { |
215 | 219 | return ORBIS_KERNEL_ERROR_EINVAL;
|
216 | 220 | }
|
217 | 221 | return ORBIS_OK;
|
218 | 222 | }
|
219 | 223 |
|
220 | 224 | s32 PS4_SYSV_ABI sceKernelPollSema(OrbisKernelSema sem, s32 needCount) {
|
221 |
| - if (!sem) { |
| 225 | + if (!orbis_sems.is_allocated(sem)) { |
222 | 226 | return ORBIS_KERNEL_ERROR_ESRCH;
|
223 | 227 | }
|
224 |
| - return sem->Wait(false, needCount, nullptr); |
| 228 | + return orbis_sems[sem]->Wait(false, needCount, nullptr); |
225 | 229 | }
|
226 | 230 |
|
227 | 231 | int PS4_SYSV_ABI sceKernelCancelSema(OrbisKernelSema sem, s32 setCount, s32* pNumWaitThreads) {
|
228 |
| - if (!sem) { |
| 232 | + if (!orbis_sems.is_allocated(sem)) { |
229 | 233 | return ORBIS_KERNEL_ERROR_ESRCH;
|
230 | 234 | }
|
231 |
| - return sem->Cancel(setCount, pNumWaitThreads); |
| 235 | + return orbis_sems[sem]->Cancel(setCount, pNumWaitThreads); |
232 | 236 | }
|
233 | 237 |
|
234 | 238 | int PS4_SYSV_ABI sceKernelDeleteSema(OrbisKernelSema sem) {
|
235 |
| - if (!sem) { |
| 239 | + if (!orbis_sems.is_allocated(sem)) { |
236 | 240 | return ORBIS_KERNEL_ERROR_ESRCH;
|
237 | 241 | }
|
238 |
| - sem->Delete(); |
239 |
| - delete sem; |
| 242 | + orbis_sems[sem]->Delete(); |
| 243 | + orbis_sems.erase(sem); |
240 | 244 | return ORBIS_OK;
|
241 | 245 | }
|
242 | 246 |
|
|
0 commit comments