Skip to content

Commit

Permalink
Move has_lock checks to the destructors
Browse files Browse the repository at this point in the history
  • Loading branch information
NicksWorld committed Jan 13, 2025
1 parent 5accca1 commit bb0a211
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions library/include/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,6 @@ namespace DFHack

void unlock()
{
if (!owns_lock())
return;
/* Restore core owner to previous value */
if (tid == std::thread::id{})
Lua::Core::Reset(core.getConsole(), "suspend");
Expand All @@ -386,7 +384,8 @@ namespace DFHack
}

~CoreSuspenderBase() {
unlock();
if (owns_lock())
unlock();
}

protected:
Expand Down Expand Up @@ -438,7 +437,8 @@ namespace DFHack

// note that this is needed so the destructor will call CoreSuspender::unlock instead of CoreSuspenderBase::unlock
~CoreSuspender() {
unlock();
if (owns_lock())
unlock();
}

protected:
Expand All @@ -465,8 +465,6 @@ namespace DFHack

void unlock()
{
if (!owns_lock())
return;
parent_t::unlock();
dec_tool_count();
}
Expand Down

0 comments on commit bb0a211

Please sign in to comment.