Replace std::mutex with std::recursive_mutex

This commit is contained in:
Maschell 2026-01-21 19:50:49 +01:00
parent ffddd49812
commit 5c4670a420
11 changed files with 33 additions and 32 deletions

View File

@ -6,7 +6,7 @@
#include <wums.h>
void ExportCleanUp() {
std::lock_guard<std::mutex> lock(gNotificationListMutex);
std::lock_guard<std::recursive_mutex> lock(gNotificationListMutex);
gNotificationList.clear();
std::lock_guard overlay_lock(gOverlayFrameMutex);
@ -119,7 +119,7 @@ NotificationModuleStatus NMAddDynamicNotificationV2(const char *text,
}
{
std::lock_guard<std::mutex> lock(gNotificationListMutex);
std::lock_guard<std::recursive_mutex> lock(gNotificationListMutex);
*outHandle = notification->getHandle();
{
std::lock_guard overlay_lock(gOverlayFrameMutex);
@ -147,7 +147,7 @@ NotificationModuleStatus NMAddDynamicNotification(const char *text,
NotificationModuleStatus NMUpdateDynamicNotificationText(NotificationModuleHandle handle,
const char *text) {
NotificationModuleStatus res = NOTIFICATION_MODULE_RESULT_INVALID_HANDLE;
std::lock_guard<std::mutex> lock(gNotificationListMutex);
std::lock_guard<std::recursive_mutex> lock(gNotificationListMutex);
for (auto &cur : gNotificationList) {
if (cur->getHandle() == handle) {
cur->updateText(text);
@ -161,7 +161,7 @@ NotificationModuleStatus NMUpdateDynamicNotificationText(NotificationModuleHandl
NotificationModuleStatus NMUpdateDynamicNotificationBackgroundColor(NotificationModuleHandle handle,
NMColor backgroundColor) {
NotificationModuleStatus res = NOTIFICATION_MODULE_RESULT_INVALID_HANDLE;
std::lock_guard<std::mutex> lock(gNotificationListMutex);
std::lock_guard<std::recursive_mutex> lock(gNotificationListMutex);
for (auto &cur : gNotificationList) {
if (cur->getHandle() == handle) {
cur->updateBackgroundColor((GX2Color){backgroundColor.r, backgroundColor.g, backgroundColor.b, backgroundColor.a});
@ -175,7 +175,7 @@ NotificationModuleStatus NMUpdateDynamicNotificationBackgroundColor(Notification
NotificationModuleStatus NMUpdateDynamicNotificationTextColor(NotificationModuleHandle handle,
NMColor textColor) {
NotificationModuleStatus res = NOTIFICATION_MODULE_RESULT_INVALID_HANDLE;
std::lock_guard<std::mutex> lock(gNotificationListMutex);
std::lock_guard<std::recursive_mutex> lock(gNotificationListMutex);
for (auto &cur : gNotificationList) {
if (cur->getHandle() == handle) {
cur->updateTextColor((GX2Color){textColor.r, textColor.g, textColor.b, textColor.a});
@ -203,7 +203,7 @@ NotificationModuleStatus NMFinishDynamicNotification(NotificationModuleHandle ha
}
NotificationModuleStatus res = NOTIFICATION_MODULE_RESULT_INVALID_HANDLE;
std::lock_guard<std::mutex> lock(gNotificationListMutex);
std::lock_guard<std::recursive_mutex> lock(gNotificationListMutex);
for (auto &cur : gNotificationList) {
if (cur->getHandle() == handle) {
cur->updateStatus(newStatus);

View File

@ -66,7 +66,7 @@ GuiText::GuiText(const char *t, int s, const glm::vec4 &c) {
blurGlowColor = glm::vec4(0.0f);
if (t) {
std::lock_guard<std::mutex> textLock(mTextLock);
std::lock_guard<std::recursive_mutex> textLock(mTextLock);
text = SchriftGX2::charToWideChar(t);
if (!text) {
return;
@ -81,14 +81,14 @@ GuiText::GuiText(const char *t, int s, const glm::vec4 &c) {
* Destructor for the GuiText class.
*/
GuiText::~GuiText() {
std::lock_guard<std::mutex> textLock(mTextLock);
std::lock_guard<std::recursive_mutex> textLock(mTextLock);
delete[] text;
text = nullptr;
}
void GuiText::setText(const char *t) {
std::lock_guard<std::mutex> textLock(mTextLock);
std::lock_guard<std::recursive_mutex> textLock(mTextLock);
delete[] text;
text = nullptr;
@ -115,7 +115,7 @@ void GuiText::setPresetFont(SchriftGX2 *f) {
}
void GuiText::setFontSize(int s) {
std::lock_guard<std::mutex> textLock(mTextLock);
std::lock_guard<std::recursive_mutex> textLock(mTextLock);
size = s;
}
@ -139,7 +139,7 @@ void GuiText::setBlurGlowColor(float blur, const glm::vec4 &c) {
* Change font
*/
bool GuiText::setFont(SchriftGX2 *f) {
std::lock_guard<std::mutex> textLock(mTextLock);
std::lock_guard<std::recursive_mutex> textLock(mTextLock);
if (!f) {
return false;
}
@ -161,7 +161,7 @@ void GuiText::draw(bool SRGBConversion) {
if (!isVisible()) {
return;
}
std::lock_guard<std::mutex> textLock(mTextLock);
std::lock_guard<std::recursive_mutex> textLock(mTextLock);
color[3] = getAlpha();
blurGlowColor[3] = blurAlpha * getAlpha();

View File

@ -100,5 +100,5 @@ protected:
float blurAlpha;
glm::vec4 blurGlowColor{};
std::mutex mTextLock;
std::recursive_mutex mTextLock;
};

View File

@ -97,4 +97,4 @@ void Notification::updateStatus(NotificationStatus newStatus) {
}
mWaitForReset = true;
this->mStatus = newStatus;
}
}

View File

@ -6,7 +6,7 @@ void OverlayFrame::addNotification(std::shared_ptr<Notification> status) {
status->setAlignment(ALIGN_TOP_LEFT);
status->setEffect(EFFECT_FADE, 55, 255);
{
std::lock_guard<std::mutex> lock(gNotificationListMutex);
std::lock_guard<std::recursive_mutex> lock(gNotificationListMutex);
list.push_front(std::move(status));
}
}
@ -28,7 +28,7 @@ void OverlayFrame::OnShakeFinished(GuiElement *element) {
}
void OverlayFrame::clearElements() {
std::lock_guard<std::mutex> lock(gNotificationListMutex);
std::lock_guard<std::recursive_mutex> lock(gNotificationListMutex);
for (auto &element : list) {
remove(element.get());
}
@ -38,7 +38,7 @@ void OverlayFrame::clearElements() {
void OverlayFrame::process() {
GuiFrame::process();
std::lock_guard<std::mutex> lock(gNotificationListMutex);
std::lock_guard<std::recursive_mutex> lock(gNotificationListMutex);
float offset = -25.0f;
for (auto &item : list) {

View File

@ -156,7 +156,7 @@ char *SchriftGX2::wideCharToUTF8(const wchar_t *strChar) {
* This routine clears all members of the font map structure and frees all allocated memory back to the system.
*/
void SchriftGX2::unloadFont() {
std::lock_guard<std::mutex> lock(fontDataMutex);
std::lock_guard<std::recursive_mutex> lock(fontDataMutex);
for (auto &dataForSize : fontData) {
for (auto &cur : dataForSize.second.ftgxCharMap) {
if (cur.second.texture) {
@ -182,7 +182,7 @@ void SchriftGX2::unloadFont() {
* @return A pointer to the allocated font structure.
*/
ftgxCharData *SchriftGX2::cacheGlyphData(wchar_t charCode, int16_t pixelSize) {
std::lock_guard<std::mutex> lock(fontDataMutex);
std::lock_guard<std::recursive_mutex> lock(fontDataMutex);
auto itr = fontData.find(pixelSize);
if (itr != fontData.end()) {
auto itr2 = itr->second.ftgxCharMap.find(charCode);
@ -347,7 +347,7 @@ int16_t SchriftGX2::getStyleOffsetWidth(uint16_t width, uint16_t format) {
* @param format Positional format of the string.
*/
int16_t SchriftGX2::getStyleOffsetHeight(int16_t format, uint16_t pixelSize) {
std::lock_guard<std::mutex> lock(fontDataMutex);
std::lock_guard<std::recursive_mutex> lock(fontDataMutex);
std::map<int16_t, ftGX2Data>::iterator itr = fontData.find(pixelSize);
if (itr == fontData.end()) return 0;
@ -397,7 +397,7 @@ uint16_t SchriftGX2::drawText(int16_t x, int16_t y, int16_t z, const wchar_t *te
return 0;
}
std::lock_guard<std::mutex> lock(fontDataMutex);
std::lock_guard<std::recursive_mutex> lock(fontDataMutex);
// uint16_t fullTextWidth = (textWidth > 0) ? textWidth : getWidth(text, pixelSize);
uint16_t x_pos = x, printed = 0;
@ -445,7 +445,7 @@ uint16_t SchriftGX2::getWidth(const wchar_t *text, int16_t pixelSize) {
if (!text) {
return 0;
}
std::lock_guard<std::mutex> lock(fontDataMutex);
std::lock_guard<std::recursive_mutex> lock(fontDataMutex);
uint16_t strWidth = 0;
int32_t i = 0;
@ -470,7 +470,7 @@ uint16_t SchriftGX2::getWidth(const wchar_t *text, int16_t pixelSize) {
* Single char width
*/
uint16_t SchriftGX2::getCharWidth(const wchar_t wChar, int16_t pixelSize, const wchar_t prevChar) {
std::lock_guard<std::mutex> lock(fontDataMutex);
std::lock_guard<std::recursive_mutex> lock(fontDataMutex);
uint16_t strWidth = 0;
ftgxCharData *glyphData = cacheGlyphData(wChar, pixelSize);
@ -496,7 +496,7 @@ uint16_t SchriftGX2::getCharWidth(const wchar_t wChar, int16_t pixelSize, const
* @return The height of the text string in pixels.
*/
uint16_t SchriftGX2::getHeight(const wchar_t *text, int16_t pixelSize) {
std::lock_guard<std::mutex> lock(fontDataMutex);
std::lock_guard<std::recursive_mutex> lock(fontDataMutex);
getOffset(text, pixelSize);
return fontData[pixelSize].ftgxAlign.max - fontData[pixelSize].ftgxAlign.min;
}
@ -515,7 +515,7 @@ void SchriftGX2::getOffset(const wchar_t *text, int16_t pixelSize, uint16_t widt
if (!text) {
return;
}
std::lock_guard<std::mutex> lock(fontDataMutex);
std::lock_guard<std::recursive_mutex> lock(fontDataMutex);
int16_t strMax = 0, strMin = 9999;
uint16_t currWidth = 0;

View File

@ -131,7 +131,7 @@ private:
void copyTextureToFramebuffer(GX2Texture *tex, int16_t screenX, int16_t screenY, int16_t screenZ, const glm::vec4 &color, const float &textBlur, const float &colorBlurIntensity, const glm::vec4 &blurColor);
std::mutex fontDataMutex;
std::recursive_mutex fontDataMutex;
public:
SchriftGX2(const uint8_t *fontBuffer, uint32_t bufferSize);

View File

@ -4,7 +4,7 @@ GX2SurfaceFormat gTVSurfaceFormat = GX2_SURF
GX2SurfaceFormat gDRCSurfaceFormat = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8;
GX2ContextState *gContextState = nullptr;
GX2ContextState *gOriginalContextState = nullptr;
std::mutex gOverlayFrameMutex = {};
std::recursive_mutex gOverlayFrameMutex = {};
std::vector<std::shared_ptr<Notification>> gOverlayQueueDuringStartup = {};
OverlayFrame *gOverlayFrame = nullptr;
SchriftGX2 *gFontSystem = nullptr;

View File

@ -2,12 +2,13 @@
#include "gui/OverlayFrame.h"
#include "gui/SchriftGX2.h"
#include <gx2/context.h>
#include <mutex>
extern GX2SurfaceFormat gTVSurfaceFormat;
extern GX2SurfaceFormat gDRCSurfaceFormat;
extern GX2ContextState *gContextState;
extern GX2ContextState *gOriginalContextState;
extern std::mutex gOverlayFrameMutex;
extern std::recursive_mutex gOverlayFrameMutex;
extern std::vector<std::shared_ptr<Notification>> gOverlayQueueDuringStartup;
extern OverlayFrame *gOverlayFrame;
extern SchriftGX2 *gFontSystem;

View File

@ -74,5 +74,5 @@ uint8_t SRGBComponentToRGBTable[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0
0xBE, 0xC0, 0xC1, 0xC3, 0xC5, 0xC7, 0xC9, 0xCB, 0xCD, 0xCF, 0xD1, 0xD3, 0xD5, 0xD7, 0xDA, 0xDC,
0xDE, 0xE0, 0xE2, 0xE4, 0xE6, 0xE8, 0xEB, 0xED, 0xEF, 0xF1, 0xF3, 0xF5, 0xF8, 0xFA, 0xFC, 0xFF};
std::mutex gNotificationListMutex;
std::recursive_mutex gNotificationListMutex;
std::forward_list<std::shared_ptr<Notification>> gNotificationList;

View File

@ -17,8 +17,8 @@ std::shared_ptr<T> make_shared_nothrow(Args &&...args) noexcept(noexcept(T(std::
}
template<typename T, class Allocator, class Predicate>
bool remove_locked_first_if(std::mutex &mutex, std::forward_list<T, Allocator> &list, Predicate pred) {
std::lock_guard<std::mutex> lock(mutex);
bool remove_locked_first_if(std::recursive_mutex &mutex, std::forward_list<T, Allocator> &list, Predicate pred) {
std::lock_guard<std::recursive_mutex> lock(mutex);
auto oit = list.before_begin(), it = std::next(oit);
while (it != list.end()) {
if (pred(*it)) {
@ -45,5 +45,5 @@ inline uint8_t RGBComponentToSRGB(uint8_t ci) {
return RGBComponentToSRGBTable[ci];
}
extern std::mutex gNotificationListMutex;
extern std::recursive_mutex gNotificationListMutex;
extern std::forward_list<std::shared_ptr<Notification>> gNotificationList;