-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Populate metadata ahead of view in a thread.
- Loading branch information
Showing
7 changed files
with
214 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (c) 2024, Extrems <extrems@extremscorner.org> | ||
* | ||
* This file is part of Swiss. | ||
* | ||
* Swiss is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Swiss is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* with Swiss. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <ogc/lwp.h> | ||
#include <ogc/machine/processor.h> | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include "deviceHandler.h" | ||
|
||
static lwpq_t queue = LWP_TQUEUE_NULL; | ||
|
||
__attribute((constructor)) | ||
static void initQueue(void) | ||
{ | ||
LWP_InitQueue(&queue); | ||
} | ||
|
||
void lockFile(file_handle *file) | ||
{ | ||
uint32_t level; | ||
|
||
_CPU_ISR_Disable(level); | ||
|
||
while (file->lockCount != 0 && file->thread != LWP_GetSelf()) | ||
LWP_ThreadSleep(queue); | ||
|
||
file->lockCount++; | ||
file->thread = LWP_GetSelf(); | ||
|
||
_CPU_ISR_Restore(level); | ||
} | ||
|
||
bool trylockFile(file_handle *file) | ||
{ | ||
uint32_t level; | ||
|
||
_CPU_ISR_Disable(level); | ||
|
||
if (file->lockCount != 0 && file->thread != LWP_GetSelf()) { | ||
_CPU_ISR_Restore(level); | ||
return false; | ||
} | ||
|
||
file->lockCount++; | ||
file->thread = LWP_GetSelf(); | ||
|
||
_CPU_ISR_Restore(level); | ||
return true; | ||
} | ||
|
||
void unlockFile(file_handle *file) | ||
{ | ||
uint32_t level; | ||
|
||
_CPU_ISR_Disable(level); | ||
|
||
if (--file->lockCount == 0) | ||
LWP_ThreadBroadcast(queue); | ||
|
||
_CPU_ISR_Restore(level); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2024, Extrems <extrems@extremscorner.org> | ||
* | ||
* This file is part of Swiss. | ||
* | ||
* Swiss is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Swiss is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* with Swiss. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef __FILELOCK_H__ | ||
#define __FILELOCK_H__ | ||
|
||
#include <stdbool.h> | ||
#include "deviceHandler.h" | ||
|
||
void lockFile(file_handle *file); | ||
bool trylockFile(file_handle *file); | ||
void unlockFile(file_handle *file); | ||
|
||
#endif /* __FILELOCK_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.