Skip to content

Commit 2a735f1

Browse files
committed
coreinit: Use native COS locks instead of STL
1 parent 14dd7a7 commit 2a735f1

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/Cafe/OS/libs/coreinit/coreinit_FS.cpp

+9-8
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,16 @@ bool strcpy_whole(char* dst, size_t dstLength, const char* src)
4242

4343
namespace coreinit
4444
{
45-
std::mutex sFSClientLock;
46-
std::recursive_mutex sFSGlobalMutex;
45+
SysAllocator<OSMutex> s_fsGlobalMutex;
4746

4847
inline void FSLockMutex()
4948
{
50-
sFSGlobalMutex.lock();
49+
OSLockMutex(&s_fsGlobalMutex);
5150
}
5251

5352
inline void FSUnlockMutex()
5453
{
55-
sFSGlobalMutex.unlock();
54+
OSUnlockMutex(&s_fsGlobalMutex);
5655
}
5756

5857
void _debugVerifyCommand(const char* stage, FSCmdBlockBody_t* fsCmdBlockBody);
@@ -251,7 +250,7 @@ namespace coreinit
251250
fsCmdQueueBE->dequeueHandlerFuncMPTR = _swapEndianU32(dequeueHandlerFuncMPTR);
252251
fsCmdQueueBE->numCommandsInFlight = 0;
253252
fsCmdQueueBE->numMaxCommandsInFlight = numMaxCommandsInFlight;
254-
coreinit::OSInitMutexEx(&fsCmdQueueBE->mutex, nullptr);
253+
coreinit::OSFastMutex_Init(&fsCmdQueueBE->fastMutex, nullptr);
255254
fsCmdQueueBE->firstMPTR = _swapEndianU32(0);
256255
fsCmdQueueBE->lastMPTR = _swapEndianU32(0);
257256
}
@@ -672,12 +671,12 @@ namespace coreinit
672671
_debugVerifyCommand("FSCmdSubmitResult", fsCmdBlockBody);
673672

674673
FSClientBody_t* fsClientBody = fsCmdBlockBody->fsClientBody.GetPtr();
675-
sFSClientLock.lock(); // OSFastMutex_Lock(&fsClientBody->fsCmdQueue.mutex)
674+
OSFastMutex_Lock(&fsClientBody->fsCmdQueue.fastMutex);
676675
fsCmdBlockBody->cancelState &= ~(1 << 0); // clear cancel bit
677676
if (fsClientBody->currentCmdBlockBody.GetPtr() == fsCmdBlockBody)
678677
fsClientBody->currentCmdBlockBody = nullptr;
679678
fsCmdBlockBody->statusCode = _swapEndianU32(FSA_CMD_STATUS_CODE_D900A24);
680-
sFSClientLock.unlock();
679+
OSFastMutex_Unlock(&fsClientBody->fsCmdQueue.fastMutex);
681680
// send result via msg queue or callback
682681
cemu_assert_debug(!fsCmdBlockBody->asyncResult.fsAsyncParamsNew.ioMsgQueue != !fsCmdBlockBody->asyncResult.fsAsyncParamsNew.userCallback); // either must be set
683682
fsCmdBlockBody->ukn09EA = 0;
@@ -1433,7 +1432,7 @@ namespace coreinit
14331432
return (FSStatus)FS_RESULT::SUCCESS;
14341433
}
14351434

1436-
sint32 FSAppendFile(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, uint32 size, uint32 count, uint32 fileHandle, uint32 errorMask)
1435+
sint32 FSAppendFile(FSClient_t* fsClient, FSCmdBlock_t* fsCmdBlock, uint32 size, uint32 count, uint32 fileHandle, uint32 errorMask)
14371436
{
14381437
StackAllocator<FSAsyncParamsNew_t> asyncParams;
14391438
__FSAsyncToSyncInit(fsClient, fsCmdBlock, asyncParams);
@@ -2640,6 +2639,8 @@ namespace coreinit
26402639

26412640
void InitializeFS()
26422641
{
2642+
OSInitMutex(&s_fsGlobalMutex);
2643+
26432644
cafeExportRegister("coreinit", FSInit, LogType::CoreinitFile);
26442645
cafeExportRegister("coreinit", FSShutdown, LogType::CoreinitFile);
26452646

src/Cafe/OS/libs/coreinit/coreinit_FS.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,16 @@ namespace coreinit
4242

4343
/* +0x00 */ MPTR firstMPTR;
4444
/* +0x04 */ MPTR lastMPTR;
45-
/* +0x08 */ OSMutex mutex;
45+
/* +0x08 */ OSFastMutex fastMutex;
4646
/* +0x34 */ MPTR dequeueHandlerFuncMPTR;
4747
/* +0x38 */ uint32be numCommandsInFlight;
4848
/* +0x3C */ uint32 numMaxCommandsInFlight;
4949
/* +0x40 */ betype<QUEUE_FLAG> queueFlags;
5050
};
5151
DEFINE_ENUM_FLAG_OPERATORS(FSCmdQueue::QUEUE_FLAG);
5252

53+
static_assert(sizeof(FSCmdQueue) == 0x44);
54+
5355
#define FS_CLIENT_BUFFER_SIZE (5888)
5456
#define FS_CMD_BLOCK_SIZE (2688)
5557

0 commit comments

Comments
 (0)