Replace base::mutex with std::mutex

* Removed base::mutex & base::scoped_lock
* We can use std::lock_guard with deduced template args (as we're
  using C++17 now)
This commit is contained in:
David Capello 2022-10-18 16:20:34 -03:00
parent 616f74ae2d
commit 17a5b3f3fc
16 changed files with 53 additions and 62 deletions

2
laf

@ -1 +1 @@
Subproject commit f14a6a5f33b77b9d5363075bde5ab328219cfd92
Subproject commit 6d7bb54ac5a5ee23acb400a0f6515f7132ed2b1e

View File

@ -57,7 +57,6 @@
#include "app/util/clipboard.h"
#include "base/exception.h"
#include "base/fs.h"
#include "base/scoped_lock.h"
#include "base/split_string.h"
#include "doc/sprite.h"
#include "fmt/format.h"

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2020 Igara Studio S.A.
// Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -14,7 +14,6 @@
#include "app/commands/filters/filter_manager_impl.h"
#include "app/ui/editor/editor.h"
#include "app/ui/editor/editor_render.h"
#include "base/scoped_lock.h"
#include "doc/layer.h"
#include "doc/sprite.h"
#include "ui/manager.h"
@ -60,7 +59,7 @@ void FilterPreview::setEnablePreview(bool state)
void FilterPreview::stop()
{
{
base::scoped_lock lock(m_filterMgrMutex);
std::scoped_lock lock(m_filterMgrMutex);
if (m_timer.isRunning()) {
ASSERT(m_filterMgr);
m_filterMgr->end();
@ -79,7 +78,7 @@ void FilterPreview::restartPreview()
{
stop();
base::scoped_lock lock(m_filterMgrMutex);
std::scoped_lock lock(m_filterMgrMutex);
m_filterMgr->beginForPreview();
m_filterIsDone = false;
@ -101,13 +100,13 @@ bool FilterPreview::onProcessMessage(Message* msg)
// Stop the preview timer.
{
base::scoped_lock lock(m_filterMgrMutex);
std::scoped_lock lock(m_filterMgrMutex);
m_timer.stop();
}
break;
case kTimerMessage: {
base::scoped_lock lock(m_filterMgrMutex);
std::scoped_lock lock(m_filterMgrMutex);
if (m_filterMgr) {
m_filterMgr->flush();
if (m_filterIsDone)
@ -126,7 +125,7 @@ void FilterPreview::onFilterThread()
bool running = true;
while (running) {
{
base::scoped_lock lock(m_filterMgrMutex);
std::scoped_lock lock(m_filterMgrMutex);
m_filterIsDone = !m_filterMgr->applyStep();
running = (!m_filterIsDone && m_timer.isRunning());
}

View File

@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -8,11 +9,12 @@
#define APP_COMMANDS_FILTERS_FILTER_PREVIEW_H_INCLUDED
#pragma once
#include "base/mutex.h"
#include "base/thread.h"
#include "ui/timer.h"
#include "ui/widget.h"
#include <mutex>
namespace app {
class FilterManagerImpl;
@ -36,7 +38,7 @@ namespace app {
FilterManagerImpl* m_filterMgr;
ui::Timer m_timer;
base::mutex m_filterMgrMutex;
std::mutex m_filterMgrMutex;
std::unique_ptr<base::thread> m_filterThread;
bool m_filterIsDone;
};

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -18,8 +18,6 @@
#include "app/modules/gui.h"
#include "app/ui/editor/editor.h"
#include "app/ui/status_bar.h"
#include "base/mutex.h"
#include "base/scoped_lock.h"
#include "base/thread.h"
#include "doc/sprite.h"
#include "ui/ui.h"
@ -27,6 +25,7 @@
#include <cstdlib>
#include <cstring>
#include <functional>
#include <mutex>
#include <thread>
namespace app {
@ -97,7 +96,7 @@ private:
#endif
FilterManagerImpl* m_filterMgr; // Effect to be applied.
base::mutex m_mutex; // Mutex to access to 'pos', 'done' and 'cancelled' fields in different threads.
std::mutex m_mutex; // Mutex to access to 'pos', 'done' and 'cancelled' fields in different threads.
float m_pos; // Current progress position
bool m_done; // Was the effect completely applied?
bool m_cancelled; // Was the effect cancelled by the user?
@ -153,7 +152,7 @@ void FilterWorker::run()
}
{
scoped_lock lock(m_mutex);
std::lock_guard lock(m_mutex);
if (m_done && m_filterMgr->isTransaction())
m_filterMgr->commitTransaction();
else
@ -182,7 +181,7 @@ void FilterWorker::run()
//
void FilterWorker::reportProgress(float progress)
{
scoped_lock lock(m_mutex);
std::lock_guard lock(m_mutex);
m_pos = progress;
}
@ -194,7 +193,7 @@ bool FilterWorker::isCancelled()
{
bool cancelled;
scoped_lock lock(m_mutex);
std::lock_guard lock(m_mutex);
cancelled = (m_cancelled || m_abort);
return cancelled;
@ -211,7 +210,7 @@ void FilterWorker::applyFilterInBackground()
m_filterMgr->applyToTarget();
// Mark the work as 'done'.
scoped_lock lock(m_mutex);
std::lock_guard lock(m_mutex);
m_done = true;
}
catch (std::exception& e) {
@ -226,7 +225,7 @@ void FilterWorker::applyFilterInBackground()
// every 100 milliseconds).
void FilterWorker::onMonitoringTick()
{
scoped_lock lock(m_mutex);
std::lock_guard lock(m_mutex);
if (m_alert) {
m_alert->setProgress(m_pos);

View File

@ -14,7 +14,6 @@
#include "app/file/format_options.h"
#include "app/transformation.h"
#include "base/disable_copying.h"
#include "base/mutex.h"
#include "base/rw_lock.h"
#include "doc/blend_mode.h"
#include "doc/color.h"

View File

@ -13,7 +13,6 @@
#include "app/doc.h"
#include "base/fs.h"
#include "base/mutex.h"
#include <algorithm>

View File

@ -31,8 +31,6 @@
#include "app/ui/optional_alert.h"
#include "app/ui/status_bar.h"
#include "base/fs.h"
#include "base/mutex.h"
#include "base/scoped_lock.h"
#include "base/string.h"
#include "dio/detect_format.h"
#include "doc/algorithm/resize_image.h"
@ -1051,13 +1049,13 @@ void FileOp::operate(IFileOpProgress* progress)
void FileOp::done()
{
// Finally done.
scoped_lock lock(m_mutex);
std::lock_guard lock(m_mutex);
m_done = true;
}
void FileOp::stop()
{
scoped_lock lock(m_mutex);
std::lock_guard lock(m_mutex);
if (!m_done)
m_stop = true;
}
@ -1338,7 +1336,7 @@ void FileOp::setError(const char *format, ...)
// Concatenate the new error
{
scoped_lock lock(m_mutex);
std::lock_guard lock(m_mutex);
// Add a newline char automatically if it's needed
if (!m_error.empty() && m_error.back() != '\n')
m_error.push_back('\n');
@ -1348,7 +1346,7 @@ void FileOp::setError(const char *format, ...)
void FileOp::setProgress(double progress)
{
scoped_lock lock(m_mutex);
std::lock_guard lock(m_mutex);
if (isSequence()) {
m_progress =
@ -1377,7 +1375,7 @@ double FileOp::progress() const
{
double progress;
{
scoped_lock lock(m_mutex);
std::lock_guard lock(m_mutex);
progress = m_progress;
}
return progress;
@ -1389,7 +1387,7 @@ bool FileOp::isDone() const
{
bool done;
{
scoped_lock lock(m_mutex);
std::lock_guard lock(m_mutex);
done = m_done;
}
return done;
@ -1399,7 +1397,7 @@ bool FileOp::isStop() const
{
bool stop;
{
scoped_lock lock(m_mutex);
std::scoped_lock lock(m_mutex);
stop = m_stop;
}
return stop;

View File

@ -14,7 +14,6 @@
#include "app/file/file_op_config.h"
#include "app/file/format_options.h"
#include "app/pref/preferences.h"
#include "base/mutex.h"
#include "base/paths.h"
#include "doc/frame.h"
#include "doc/image_ref.h"
@ -24,6 +23,7 @@
#include <cstdio>
#include <memory>
#include <mutex>
#include <string>
// Flags for FileOp::createLoadDocumentOperation()
@ -278,7 +278,7 @@ namespace app {
FileOpROI m_roi;
// Shared fields between threads.
mutable base::mutex m_mutex; // Mutex to access to the next two fields.
mutable std::mutex m_mutex; // Mutex to access to the next two fields.
double m_progress; // Progress (1.0 is ready).
IFileOpProgress* m_progressInterface;
std::string m_error; // Error string.

View File

@ -9,11 +9,11 @@
#define APP_FILE_SYSTEM_H_INCLUDED
#pragma once
#include "base/mutex.h"
#include "base/paths.h"
#include "obs/signal.h"
#include "os/surface.h"
#include <mutex>
#include <string>
#include <vector>
@ -47,7 +47,7 @@ namespace app {
obs::signal<void(IFileItem*)> ItemRemoved;
private:
base::mutex m_mutex;
std::mutex m_mutex;
};
class LockFS {

View File

@ -15,8 +15,6 @@
#include "app/console.h"
#include "app/context.h"
#include "app/i18n/strings.h"
#include "base/mutex.h"
#include "base/scoped_lock.h"
#include "fmt/format.h"
#include "ui/alert.h"
#include "ui/widget.h"

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2020 Igara Studio S.A.
// Copyright (C) 2019-2022 Igara Studio S.A.
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -29,7 +29,7 @@ Task::~Task()
void Task::run(base::task::func_t&& func)
{
std::lock_guard<std::mutex> lock(m_token_mutex);
std::lock_guard lock(m_token_mutex);
m_task.on_execute(std::move(func));
m_token = &m_task.start(tasks_pool);
}

View File

@ -34,7 +34,7 @@ namespace app {
}
bool canceled() const {
std::lock_guard<std::mutex> lock(m_token_mutex);
std::lock_guard lock(m_token_mutex);
if (m_token)
return m_token->canceled();
else
@ -42,7 +42,7 @@ namespace app {
}
float progress() const {
std::lock_guard<std::mutex> lock(m_token_mutex);
std::lock_guard lock(m_token_mutex);
if (m_token)
return m_token->progress();
else
@ -50,13 +50,13 @@ namespace app {
}
void cancel() {
std::lock_guard<std::mutex> lock(m_token_mutex);
std::lock_guard lock(m_token_mutex);
if (m_token)
m_token->cancel();
}
void set_progress(float progress) {
std::lock_guard<std::mutex> lock(m_token_mutex);
std::lock_guard lock(m_token_mutex);
if (m_token)
m_token->set_progress(progress);
}

View File

@ -49,7 +49,7 @@ public:
~Worker() {
{
std::lock_guard<std::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
if (m_fop)
m_fop->stop();
}
@ -57,7 +57,7 @@ public:
}
void stop() const {
std::lock_guard<std::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
if (m_fop)
m_fop->stop();
}
@ -67,7 +67,7 @@ public:
}
void updateProgress() {
std::lock_guard<std::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
if (m_item.fileitem && m_item.fop) {
double progress = m_item.fop->progress();
if (progress > m_item.fileitem->getThumbnailProgress())
@ -80,7 +80,7 @@ private:
ASSERT(!m_fop);
try {
{
std::lock_guard<std::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
m_fop = m_item.fop;
ASSERT(m_fop);
}
@ -167,7 +167,7 @@ private:
0, 0, 0, 0, thumbnailImage->width(), thumbnailImage->height());
{
std::lock_guard<std::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
m_item.fileitem->setThumbnail(thumbnail);
}
}
@ -191,13 +191,13 @@ private:
// Reset the m_item (first the fileitem so this worker is not
// associated to this fileitem anymore, and then the FileOp).
{
std::lock_guard<std::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
m_item.fileitem = nullptr;
}
m_fop->done();
{
std::lock_guard<std::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
m_item.fop = nullptr;
delete m_fop;
m_fop = nullptr;
@ -210,7 +210,7 @@ private:
bool success = true;
while (success) {
{
std::lock_guard<std::mutex> lock(m_mutex); // To access m_item
std::lock_guard lock(m_mutex); // To access m_item
success = m_queue.try_pop(m_item);
}
if (success)
@ -251,7 +251,7 @@ ThumbnailGenerator::ThumbnailGenerator()
bool ThumbnailGenerator::checkWorkers()
{
std::lock_guard<std::mutex> hold(m_workersAccess);
std::lock_guard lock(m_workersAccess);
bool doingWork = (!m_workers.empty());
for (WorkerList::iterator
@ -337,14 +337,14 @@ void ThumbnailGenerator::stopAllWorkers()
}
}
std::lock_guard<std::mutex> hold(m_workersAccess);
std::lock_guard lock(m_workersAccess);
for (const auto& worker : m_workers)
worker->stop();
}
void ThumbnailGenerator::startWorker()
{
std::lock_guard<std::mutex> hold(m_workersAccess);
std::lock_guard lock(m_workersAccess);
if (m_workers.size() < m_maxWorkers) {
m_workers.push_back(std::make_unique<Worker>(m_remainingItems));
}

View File

@ -25,7 +25,6 @@
#include "app/ui/timeline/timeline.h"
#include "app/ui/workspace.h"
#include "app/ui/workspace_tabs.h"
#include "base/mutex.h"
#include "doc/sprite.h"
#include "ui/system.h"

View File

@ -1,5 +1,5 @@
// Aseprite Document Library
// Copyright (C) 2019-2020 Igara Studio S.A.
// Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2001-2016 David Capello
//
// This file is released under the terms of the MIT license.
@ -12,14 +12,13 @@
#include "doc/object.h"
#include "base/debug.h"
#include "base/mutex.h"
#include "base/scoped_lock.h"
#include <map>
#include <mutex>
namespace doc {
static base::mutex mutex;
static std::mutex g_mutex;
static ObjectId newId = 0;
// TODO Profile this and see if an unordered_map is better
static std::map<ObjectId, Object*> objects;
@ -54,7 +53,7 @@ const ObjectId Object::id() const
// The first time the ID is request, we store the object in the
// "objects" hash table.
if (!m_id) {
base::scoped_lock hold(mutex);
std::lock_guard lock(g_mutex);
m_id = ++newId;
objects.insert(std::make_pair(m_id, const_cast<Object*>(this)));
}
@ -63,7 +62,7 @@ const ObjectId Object::id() const
void Object::setId(ObjectId id)
{
base::scoped_lock hold(mutex);
std::lock_guard lock(g_mutex);
if (m_id) {
auto it = objects.find(m_id);
@ -102,7 +101,7 @@ void Object::setVersion(ObjectVersion version)
Object* get_object(ObjectId id)
{
base::scoped_lock hold(mutex);
std::lock_guard lock(g_mutex);
auto it = objects.find(id);
if (it != objects.end())
return it->second;