diff --git a/src/export.cpp b/src/export.cpp index 170011f..5e45838 100644 --- a/src/export.cpp +++ b/src/export.cpp @@ -6,7 +6,7 @@ #include void ExportCleanUp() { - std::lock_guard lock(gNotificationListMutex); + std::lock_guard lock(gNotificationListMutex); gNotificationList.clear(); std::lock_guard overlay_lock(gOverlayFrameMutex); @@ -119,7 +119,7 @@ NotificationModuleStatus NMAddDynamicNotificationV2(const char *text, } { - std::lock_guard lock(gNotificationListMutex); + std::lock_guard 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 lock(gNotificationListMutex); + std::lock_guard 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 lock(gNotificationListMutex); + std::lock_guard 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 lock(gNotificationListMutex); + std::lock_guard 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 lock(gNotificationListMutex); + std::lock_guard lock(gNotificationListMutex); for (auto &cur : gNotificationList) { if (cur->getHandle() == handle) { cur->updateStatus(newStatus); diff --git a/src/gui/GuiText.cpp b/src/gui/GuiText.cpp index bf038e2..bfc205f 100644 --- a/src/gui/GuiText.cpp +++ b/src/gui/GuiText.cpp @@ -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 textLock(mTextLock); + std::lock_guard 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 textLock(mTextLock); + std::lock_guard textLock(mTextLock); delete[] text; text = nullptr; } void GuiText::setText(const char *t) { - std::lock_guard textLock(mTextLock); + std::lock_guard textLock(mTextLock); delete[] text; text = nullptr; @@ -115,7 +115,7 @@ void GuiText::setPresetFont(SchriftGX2 *f) { } void GuiText::setFontSize(int s) { - std::lock_guard textLock(mTextLock); + std::lock_guard 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 textLock(mTextLock); + std::lock_guard textLock(mTextLock); if (!f) { return false; } @@ -161,7 +161,7 @@ void GuiText::draw(bool SRGBConversion) { if (!isVisible()) { return; } - std::lock_guard textLock(mTextLock); + std::lock_guard textLock(mTextLock); color[3] = getAlpha(); blurGlowColor[3] = blurAlpha * getAlpha(); diff --git a/src/gui/GuiText.h b/src/gui/GuiText.h index 03c599c..35cab92 100644 --- a/src/gui/GuiText.h +++ b/src/gui/GuiText.h @@ -100,5 +100,5 @@ protected: float blurAlpha; glm::vec4 blurGlowColor{}; - std::mutex mTextLock; + std::recursive_mutex mTextLock; }; \ No newline at end of file diff --git a/src/gui/Notification.cpp b/src/gui/Notification.cpp index 1497742..c4f9bd6 100644 --- a/src/gui/Notification.cpp +++ b/src/gui/Notification.cpp @@ -97,4 +97,4 @@ void Notification::updateStatus(NotificationStatus newStatus) { } mWaitForReset = true; this->mStatus = newStatus; -} \ No newline at end of file +} diff --git a/src/gui/OverlayFrame.cpp b/src/gui/OverlayFrame.cpp index f240afc..79b1882 100644 --- a/src/gui/OverlayFrame.cpp +++ b/src/gui/OverlayFrame.cpp @@ -6,7 +6,7 @@ void OverlayFrame::addNotification(std::shared_ptr status) { status->setAlignment(ALIGN_TOP_LEFT); status->setEffect(EFFECT_FADE, 55, 255); { - std::lock_guard lock(gNotificationListMutex); + std::lock_guard lock(gNotificationListMutex); list.push_front(std::move(status)); } } @@ -28,7 +28,7 @@ void OverlayFrame::OnShakeFinished(GuiElement *element) { } void OverlayFrame::clearElements() { - std::lock_guard lock(gNotificationListMutex); + std::lock_guard lock(gNotificationListMutex); for (auto &element : list) { remove(element.get()); } @@ -38,7 +38,7 @@ void OverlayFrame::clearElements() { void OverlayFrame::process() { GuiFrame::process(); - std::lock_guard lock(gNotificationListMutex); + std::lock_guard lock(gNotificationListMutex); float offset = -25.0f; for (auto &item : list) { diff --git a/src/gui/SchriftGX2.cpp b/src/gui/SchriftGX2.cpp index e7daeb6..46ef508 100644 --- a/src/gui/SchriftGX2.cpp +++ b/src/gui/SchriftGX2.cpp @@ -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 lock(fontDataMutex); + std::lock_guard 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 lock(fontDataMutex); + std::lock_guard 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 lock(fontDataMutex); + std::lock_guard lock(fontDataMutex); std::map::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 lock(fontDataMutex); + std::lock_guard 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 lock(fontDataMutex); + std::lock_guard 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 lock(fontDataMutex); + std::lock_guard 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 lock(fontDataMutex); + std::lock_guard 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 lock(fontDataMutex); + std::lock_guard lock(fontDataMutex); int16_t strMax = 0, strMin = 9999; uint16_t currWidth = 0; diff --git a/src/gui/SchriftGX2.h b/src/gui/SchriftGX2.h index 869491d..32ad6a6 100644 --- a/src/gui/SchriftGX2.h +++ b/src/gui/SchriftGX2.h @@ -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); diff --git a/src/retain_vars.cpp b/src/retain_vars.cpp index e189435..4637b55 100644 --- a/src/retain_vars.cpp +++ b/src/retain_vars.cpp @@ -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> gOverlayQueueDuringStartup = {}; OverlayFrame *gOverlayFrame = nullptr; SchriftGX2 *gFontSystem = nullptr; diff --git a/src/retain_vars.hpp b/src/retain_vars.hpp index 3648cb2..051dfb4 100644 --- a/src/retain_vars.hpp +++ b/src/retain_vars.hpp @@ -2,12 +2,13 @@ #include "gui/OverlayFrame.h" #include "gui/SchriftGX2.h" #include +#include extern GX2SurfaceFormat gTVSurfaceFormat; extern GX2SurfaceFormat gDRCSurfaceFormat; extern GX2ContextState *gContextState; extern GX2ContextState *gOriginalContextState; -extern std::mutex gOverlayFrameMutex; +extern std::recursive_mutex gOverlayFrameMutex; extern std::vector> gOverlayQueueDuringStartup; extern OverlayFrame *gOverlayFrame; extern SchriftGX2 *gFontSystem; diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index 3319121..9fa4951 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -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> gNotificationList; \ No newline at end of file diff --git a/src/utils/utils.h b/src/utils/utils.h index 08f884b..6399ecd 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -17,8 +17,8 @@ std::shared_ptr make_shared_nothrow(Args &&...args) noexcept(noexcept(T(std:: } template -bool remove_locked_first_if(std::mutex &mutex, std::forward_list &list, Predicate pred) { - std::lock_guard lock(mutex); +bool remove_locked_first_if(std::recursive_mutex &mutex, std::forward_list &list, Predicate pred) { + std::lock_guard 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> gNotificationList; \ No newline at end of file