Clear filewrapper info on exit

This commit is contained in:
Maschell 2022-02-14 19:28:23 +01:00
parent f5ab00a4d9
commit e882e0b1e0
3 changed files with 24 additions and 1 deletions

View File

@ -26,6 +26,27 @@ int FileHandleWrapper_GetSlot() {
return res;
}
bool FileHandleWrapper_FreeSlot(uint32_t slot) {
if (slot >= FILE_WRAPPER_SIZE) {
return false;
}
OSLockMutex(&fileWrapperMutex);
gFileHandleWrapper[slot].handle = 0;
gFileHandleWrapper[slot].inUse = false;
OSMemoryBarrier();
OSUnlockMutex(&fileWrapperMutex);
return -1;
}
bool FileHandleWrapper_FreeAll() {
OSLockMutex(&fileWrapperMutex);
for (int i = 0; i < FILE_WRAPPER_SIZE; i++) {
FileHandleWrapper_FreeSlot(i);
}
OSUnlockMutex(&fileWrapperMutex);
return -1;
}
int OpenFileForID(int id, const char *filepath, int *handle) {
if (!mountRomfs(id)) {
return -1;

View File

@ -10,3 +10,4 @@ typedef struct FileHandleWrapper_t {
extern FileHandleWrapper gFileHandleWrapper[FILE_WRAPPER_SIZE];
int OpenFileForID(int id, const char *path, int32_t *handle);
bool FileHandleWrapper_FreeAll();

View File

@ -72,6 +72,7 @@ ON_APPLICATION_START() {
}
ON_APPLICATION_ENDS() {
FileHandleWrapper_FreeAll();
deinitLogging();
}