Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions library/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,17 +419,13 @@ bool is_builtin(color_ostream &con, const std::string &command) {
}

void get_commands(color_ostream &con, std::vector<std::string> &commands) {
#ifdef LINUX_BUILD
CoreSuspender suspend;
#else
ConditionalCoreSuspender suspend{};

if (!suspend) {
con.printerr("Cannot acquire core lock in helpdb.get_commands\n");
commands.clear();
return;
}
#endif

auto L = DFHack::Core::getInstance().getLuaState();
Lua::StackUnwinder top(L);
Expand Down Expand Up @@ -630,16 +626,12 @@ static std::string sc_event_name (state_change_event id) {
}

void help_helper(color_ostream &con, const std::string &entry_name) {
#ifdef LINUX_BUILD
CoreSuspender suspend;
#else
ConditionalCoreSuspender suspend{};

if (!suspend) {
con.printerr("Failed Lua call to helpdb.help (could not acquire core lock).\n");
return;
}
#endif

auto L = DFHack::Core::getInstance().getLuaState();
Lua::StackUnwinder top(L);
Expand All @@ -658,16 +650,12 @@ void help_helper(color_ostream &con, const std::string &entry_name) {
}

void tags_helper(color_ostream &con, const std::string &tag) {
#ifdef LINUX_BUILD
CoreSuspender suspend;
#else
ConditionalCoreSuspender suspend{};

if (!suspend) {
con.printerr("Failed Lua call to helpdb.help (could not acquire core lock).\n");
return;
}
#endif

auto L = DFHack::Core::getInstance().getLuaState();
Lua::StackUnwinder top(L);
Expand Down Expand Up @@ -705,16 +693,12 @@ void ls_helper(color_ostream &con, const std::vector<std::string> &params) {
filter.push_back(str);
}

#ifdef LINUX_BUILD
CoreSuspender suspend;
#else
ConditionalCoreSuspender suspend{};

if (!suspend) {
con.printerr("Failed Lua call to helpdb.help (could not acquire core lock).\n");
return;
}
#endif

auto L = DFHack::Core::getInstance().getLuaState();
Lua::StackUnwinder top(L);
Expand Down
8 changes: 4 additions & 4 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 Down
Loading