Skip to content

Commit

Permalink
fix: Replaced mutex with recursive_mutex (hoffstadt#1985)
Browse files Browse the repository at this point in the history
  • Loading branch information
v-ein committed Jan 6, 2023
1 parent 7901915 commit a82f84c
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 122 deletions.
220 changes: 109 additions & 111 deletions src/dearpygui_commands.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/mvContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ Render()
mvToolManager::Draw();

{
std::lock_guard<std::mutex> lk(GContext->mutex);
std::lock_guard<std::recursive_mutex> lk(GContext->mutex);
if (GContext->resetTheme)
{
SetDefaultTheme();
Expand Down
3 changes: 1 addition & 2 deletions src/mvContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,8 @@ struct mvIO
struct mvContext
{
std::atomic_bool waitOneFrame = false;
std::atomic_bool manualMutexControl = false;
std::atomic_bool started = false;
std::mutex mutex;
std::recursive_mutex mutex;
std::future<bool> future;
float deltaTime = 0.0f; // time since last frame
double time = 0.0; // total time since starting
Expand Down
2 changes: 1 addition & 1 deletion src/mvItemRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,7 @@ AddItemWithRuntimeChecks(mvItemRegistry& registry, std::shared_ptr<mvAppItem> it
};
AddTechnique technique = AddTechnique::NONE;

if (!GContext->manualMutexControl) std::lock_guard<std::mutex> lk(GContext->mutex);
std::lock_guard<std::recursive_mutex> lk(GContext->mutex);

//---------------------------------------------------------------------------
// STEP 2: handle root case
Expand Down
2 changes: 1 addition & 1 deletion src/mvLayoutWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void mvLayoutWindow::renderTreeNode(std::shared_ptr<mvAppItem>& item)
void mvLayoutWindow::drawWidgets()
{

std::lock_guard<std::mutex> lk(GContext->mutex);
std::lock_guard<std::recursive_mutex> lk(GContext->mutex);

mvUUID parentName = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/mvToolWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void mvToolWindow::draw()
GContext->input.mousePos.x = (int)x;
GContext->input.mousePos.y = (int)y;

std::lock_guard<std::mutex> lk(GContext->mutex);
std::lock_guard<std::recursive_mutex> lk(GContext->mutex);

if (GContext->itemRegistry->activeWindow != getUUID())
GContext->itemRegistry->activeWindow = getUUID();
Expand Down
10 changes: 5 additions & 5 deletions src/mvViewport_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ mvPrerender(mvViewport& viewport)

{
// TODO: we probably need a separate mutex for this
std::lock_guard<std::mutex> lk(GContext->mutex);
std::lock_guard<std::recursive_mutex> lk(GContext->mutex);

if (viewport.posDirty)
{
Expand Down Expand Up @@ -103,7 +103,7 @@ mvPrerender(mvViewport& viewport)

{
// Font manager is thread-unsafe, so we'd better sync it
std::lock_guard<std::mutex> lk(GContext->mutex);
std::lock_guard<std::recursive_mutex> lk(GContext->mutex);

if (mvToolManager::GetFontManager().isInvalid())
{
Expand Down Expand Up @@ -157,7 +157,7 @@ mvHandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) noexcept
}

{
std::lock_guard<std::mutex> lk(GContext->mutex);
std::lock_guard<std::recursive_mutex> lk(GContext->mutex);

viewport->actualWidth = awidth;
viewport->actualHeight = aheight;
Expand Down Expand Up @@ -208,7 +208,7 @@ mvHandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) noexcept

case WM_MOVING:
{
std::lock_guard<std::mutex> lk(GContext->mutex);
std::lock_guard<std::recursive_mutex> lk(GContext->mutex);

int horizontal_shift = get_horizontal_shift(viewportData->handle);
RECT rect = *(RECT*)(lParam);
Expand Down Expand Up @@ -239,7 +239,7 @@ mvHandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) noexcept
cheight = crect.bottom - crect.top;
}

std::lock_guard<std::mutex> lk(GContext->mutex);
std::lock_guard<std::recursive_mutex> lk(GContext->mutex);

viewport->actualWidth = awidth;
viewport->actualHeight = aheight;
Expand Down

0 comments on commit a82f84c

Please sign in to comment.