mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-03 00:26:22 +01:00
refactor(sonar): use std::scoped_lock instead of std::lock_guard (cpp:S5997)
This commit is contained in:
@@ -363,7 +363,7 @@ void python_taskqueue::exit()
|
|||||||
// document intent. clearing the deque also actually releases the tasks,
|
// document intent. clearing the deque also actually releases the tasks,
|
||||||
// which the previous code did not do (cancel() is a no-op stub).
|
// which the previous code did not do (cancel() is a no-op stub).
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(m_tasks.mutex);
|
std::scoped_lock lock(m_tasks.mutex);
|
||||||
for (auto &task : m_tasks.data)
|
for (auto &task : m_tasks.data)
|
||||||
{
|
{
|
||||||
task->cancel();
|
task->cancel();
|
||||||
@@ -371,7 +371,7 @@ void python_taskqueue::exit()
|
|||||||
m_tasks.data.clear();
|
m_tasks.data.clear();
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(m_uploadtasks.mutex);
|
std::scoped_lock lock(m_uploadtasks.mutex);
|
||||||
m_uploadtasks.data.clear();
|
m_uploadtasks.data.clear();
|
||||||
}
|
}
|
||||||
// reclaim cached python objects while the interpreter is still alive,
|
// reclaim cached python objects while the interpreter is still alive,
|
||||||
@@ -410,7 +410,7 @@ auto python_taskqueue::insert(task_request const &Task) -> bool
|
|||||||
bool newtaskinserted{false};
|
bool newtaskinserted{false};
|
||||||
// acquire a lock on the task queue and add the new task
|
// acquire a lock on the task queue and add the new task
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(m_tasks.mutex);
|
std::scoped_lock lock(m_tasks.mutex);
|
||||||
// check the task list for a pending request with the same target
|
// check the task list for a pending request with the same target
|
||||||
for (auto &task : m_tasks.data)
|
for (auto &task : m_tasks.data)
|
||||||
{
|
{
|
||||||
@@ -555,7 +555,7 @@ void python_taskqueue::run(GLFWwindow *Context, rendertask_sequence &Tasks, uplo
|
|||||||
task = nullptr;
|
task = nullptr;
|
||||||
// acquire a lock on the task queue and potentially grab a task from it
|
// acquire a lock on the task queue and potentially grab a task from it
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(Tasks.mutex);
|
std::scoped_lock lock(Tasks.mutex);
|
||||||
if (false == Tasks.data.empty())
|
if (false == Tasks.data.empty())
|
||||||
{
|
{
|
||||||
// fifo
|
// fifo
|
||||||
@@ -574,7 +574,7 @@ void python_taskqueue::run(GLFWwindow *Context, rendertask_sequence &Tasks, uplo
|
|||||||
task->upload();
|
task->upload();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(Upload_Tasks.mutex);
|
std::scoped_lock lock(Upload_Tasks.mutex);
|
||||||
Upload_Tasks.data.push_back(task);
|
Upload_Tasks.data.push_back(task);
|
||||||
}
|
}
|
||||||
if (PyErr_Occurred() != nullptr)
|
if (PyErr_Occurred() != nullptr)
|
||||||
@@ -609,7 +609,7 @@ void python_taskqueue::run(GLFWwindow *Context, rendertask_sequence &Tasks, uplo
|
|||||||
|
|
||||||
void python_taskqueue::update()
|
void python_taskqueue::update()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(m_uploadtasks.mutex);
|
std::scoped_lock lock(m_uploadtasks.mutex);
|
||||||
|
|
||||||
for (auto &task : m_uploadtasks.data)
|
for (auto &task : m_uploadtasks.data)
|
||||||
task->upload();
|
task->upload();
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ void python_screen_viewer::threadfunc()
|
|||||||
int height;
|
int height;
|
||||||
|
|
||||||
if (!Global.python_sharectx) {
|
if (!Global.python_sharectx) {
|
||||||
std::lock_guard<std::mutex> guard(m_rt->mutex);
|
std::scoped_lock guard(m_rt->mutex);
|
||||||
|
|
||||||
if (window->timestamp == m_rt->timestamp)
|
if (window->timestamp == m_rt->timestamp)
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ void WriteLog(std::string_view str, logtype type, bool isError)
|
|||||||
|
|
||||||
const auto message = FormatLogMessage(str);
|
const auto message = FormatLogMessage(str);
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(logMutex);
|
std::scoped_lock lock(logMutex);
|
||||||
InfoStack.push_back({message, isError});
|
InfoStack.push_back({message, isError});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,7 +185,7 @@ void ErrorLog(std::string_view str, logtype type)
|
|||||||
|
|
||||||
const auto message = FormatLogMessage(str);
|
const auto message = FormatLogMessage(str);
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(logMutex);
|
std::scoped_lock lock(logMutex);
|
||||||
ErrorStack.push_back(message);
|
ErrorStack.push_back(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -447,7 +447,7 @@ class condition_variable
|
|||||||
}
|
}
|
||||||
void spurious(bool const Spurious)
|
void spurious(bool const Spurious)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(m_mutex);
|
std::scoped_lock lock(m_mutex);
|
||||||
m_spurious = Spurious;
|
m_spurious = Spurious;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ void ui::cameraview_panel::render_contents()
|
|||||||
texture->bind(0);
|
texture->bind(0);
|
||||||
|
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mutex);
|
std::scoped_lock lock(mutex);
|
||||||
if (image_ptr) {
|
if (image_ptr) {
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
@@ -142,7 +142,7 @@ void ui::cameraview_panel::capture_func()
|
|||||||
|
|
||||||
bufpos = 0;
|
bufpos = 0;
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(mutex);
|
std::scoped_lock lock(mutex);
|
||||||
image_ptr = read_buffer;
|
image_ptr = read_buffer;
|
||||||
read_buffer = active_buffer;
|
read_buffer = active_buffer;
|
||||||
active_buffer = image_ptr;
|
active_buffer = image_ptr;
|
||||||
@@ -151,7 +151,7 @@ void ui::cameraview_panel::capture_func()
|
|||||||
notify_var.notify_one();
|
notify_var.notify_one();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(mutex);
|
std::scoped_lock lock(mutex);
|
||||||
image_ptr = nullptr;
|
image_ptr = nullptr;
|
||||||
delete[] read_buffer;
|
delete[] read_buffer;
|
||||||
delete[] active_buffer;
|
delete[] active_buffer;
|
||||||
|
|||||||
Reference in New Issue
Block a user