Skip to content

Commit

Permalink
simplifications
Browse files Browse the repository at this point in the history
no point in calling `owns_lock` twice
  • Loading branch information
ab9rf committed Dec 18, 2024
1 parent ff6d7a2 commit 0f326c1
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions library/include/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ namespace DFHack
}

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

protected:
Expand Down Expand Up @@ -448,13 +448,14 @@ namespace DFHack
lock();
}

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

protected:
// deferred locking is not part of CoreSuspender's public API
// these constructors are onmly for use in derived classes,
// these constructors are only for use in derived classes,
// specifically ConditionalCoreSuspender
CoreSuspender(std::defer_lock_t d) : CoreSuspender{ Core::getInstance(),d } {}
CoreSuspender(Core& core, std::defer_lock_t d) : CoreSuspenderBase{ core } {}
Expand Down

0 comments on commit 0f326c1

Please sign in to comment.