Skip to content

Commit

Permalink
chore: change locks to scoped_lock when appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxiao921 committed Apr 23, 2024
1 parent 2351892 commit 6d97562
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/logger/stack_trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace big
void stack_trace::new_stack_trace(EXCEPTION_POINTERS* exception_info)
{
static std::mutex m;
std::lock_guard lock(m);
std::scoped_lock lock(m);

m_exception_info = exception_info;

Expand Down
18 changes: 10 additions & 8 deletions src/lua/lua_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ namespace big
std::make_unique<wtr::watch>(m_plugins_folder.get_path(),
[](const wtr::event& e)
{
std::scoped_lock l(g_lua_manager_mutex);

if (!g_lua_manager || !g_lua_manager->m_is_all_mods_loaded)
{
return;
Expand Down Expand Up @@ -477,7 +479,7 @@ namespace big

void lua_manager::draw_menu_bar_callbacks()
{
std::lock_guard guard(m_module_lock);
std::scoped_lock guard(m_module_lock);

for (const auto& module : m_modules)
{
Expand Down Expand Up @@ -513,7 +515,7 @@ namespace big

void lua_manager::always_draw_independent_gui()
{
std::lock_guard guard(m_module_lock);
std::scoped_lock guard(m_module_lock);

for (const auto& module : m_modules)
{
Expand All @@ -526,7 +528,7 @@ namespace big

void lua_manager::draw_independent_gui()
{
std::lock_guard guard(m_module_lock);
std::scoped_lock guard(m_module_lock);

for (const auto& module : m_modules)
{
Expand All @@ -539,7 +541,7 @@ namespace big

void lua_manager::unload_module(const std::string& module_guid)
{
std::lock_guard guard(m_module_lock);
std::scoped_lock guard(m_module_lock);

std::erase_if(m_modules,
[&](auto& module)
Expand All @@ -555,7 +557,7 @@ namespace big
return load_module_result::FILE_MISSING;
}

std::lock_guard guard(m_module_lock);
std::scoped_lock guard(m_module_lock);
for (const auto& module : m_modules)
{
if (module->guid() == module_info.m_guid)
Expand Down Expand Up @@ -585,7 +587,7 @@ namespace big

bool lua_manager::module_exists(const std::string& module_guid)
{
std::lock_guard guard(m_module_lock);
std::scoped_lock guard(m_module_lock);

for (const auto& module : m_modules)
{
Expand Down Expand Up @@ -767,7 +769,7 @@ namespace big
}
}

std::lock_guard guard(m_module_lock);
std::scoped_lock guard(m_module_lock);
for (const auto& module : m_modules)
{
for (const auto& cb : module->m_data.m_on_all_mods_loaded_callbacks)
Expand All @@ -781,7 +783,7 @@ namespace big

void lua_manager::unload_all_modules()
{
std::lock_guard guard(m_module_lock);
std::scoped_lock guard(m_module_lock);

for (auto& module : m_modules)
{
Expand Down
2 changes: 1 addition & 1 deletion src/lua/lua_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace big

inline void for_each_module(auto func)
{
std::lock_guard guard(m_module_lock);
std::scoped_lock guard(m_module_lock);

for (auto& module : m_modules)
{
Expand Down
2 changes: 1 addition & 1 deletion src/memory/batch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ namespace memory
{
if (entry.m_on_signature_found)
{
std::lock_guard<std::mutex> lock(s_entry_mutex); // Acquire a lock on the mutex to synchronize access.
std::scoped_lock<std::mutex> lock(s_entry_mutex);

std::invoke(std::move(entry.m_on_signature_found), result.value());
LOG(INFO) << "Found '" << entry.m_name << "' Hades2.exe+"
Expand Down
4 changes: 2 additions & 2 deletions src/threads/thread_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace big
void thread_pool::destroy()
{
{
std::unique_lock lock(m_lock);
std::scoped_lock lock(m_lock);
m_accept_jobs = false;
}
m_data_condition.notify_all();
Expand All @@ -51,7 +51,7 @@ namespace big
if (func)
{
{
std::unique_lock lock(m_lock);
std::scoped_lock lock(m_lock);
m_job_stack.push({func, location});

if (m_allocated_thread_count < m_job_stack.size())
Expand Down

0 comments on commit 6d97562

Please sign in to comment.