-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check resources prior to running tasks (#3297)
* basic resource checking prior to running tasks # Conflicts: # src/OSLikeStuff/task_scheduler/task_scheduler.cpp * fix tests * add test and fix bug caught by test * add a license format * prefix with resource * prefix defines
- Loading branch information
Showing
10 changed files
with
202 additions
and
73 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,51 @@ | ||
/* | ||
* Copyright © 2025 Mark Adams | ||
* | ||
* This file is part of The Synthstrom Audible Deluge Firmware. | ||
* | ||
* The Synthstrom Audible Deluge Firmware 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 3 of the License, or (at your option) any later version. | ||
* | ||
* This program 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 along with this program. | ||
* If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
#ifndef RESOURCE_CHECKER_H | ||
#define RESOURCE_CHECKER_H | ||
#include <OSLikeStuff/scheduler_api.h> | ||
#include <bitset> | ||
#include <extern.h> | ||
extern uint8_t currentlyAccessingCard; | ||
extern uint32_t usbLock; | ||
// this is basically a bitset however the enums need to be exposed to C code and this is easier to keep synced | ||
class ResourceChecker { | ||
uint32_t resources_{0}; | ||
|
||
public: | ||
ResourceChecker() = default; | ||
ResourceChecker(ResourceID resources) : resources_(resources) {}; | ||
/// returns whether all resources are available. This is basically shitty priority ceiling to avoid the potential of | ||
/// a task locking one resource and then trying to yield while it waits for another | ||
bool checkResources() const { | ||
if (resources_ == RESOURCE_NONE) { | ||
return true; | ||
} | ||
bool anythingLocked = false; | ||
if ((resources_ & RESOURCE_SD) != 0u) { | ||
anythingLocked |= currentlyAccessingCard; | ||
} | ||
if ((resources_ & RESOURCE_USB) != 0u) { | ||
anythingLocked |= usbLock; | ||
} | ||
if ((resources_ & RESOURCE_SD_ROUTINE) != 0u) { | ||
anythingLocked |= sdRoutineLock; | ||
} | ||
return !anythingLocked; | ||
} | ||
}; | ||
|
||
#endif // RESOURCE_CHECKER_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
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
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.