Accept binary_guard in crl::guard().

This commit is contained in:
John Preston 2019-02-17 15:52:57 +04:00
parent 4d987f7278
commit d208236994
8 changed files with 30 additions and 36 deletions

View File

@ -81,3 +81,21 @@ inline std::pair<binary_guard, binary_guard> make_binary_guard() {
} }
} // namespace base } // namespace base
namespace crl {
template <typename T, typename Enable>
struct guard_traits;
template <>
struct guard_traits<base::binary_guard, void> {
static base::binary_guard create(base::binary_guard value) {
return value;
}
static bool check(const base::binary_guard &guard) {
return guard.alive();
}
};
} // namespace crl

View File

@ -722,16 +722,12 @@ void BackgroundPreviewBox::checkLoadedDocument() {
: PrepareScaledNonPattern( : PrepareScaledNonPattern(
Data::PrepareBlurredBackground(image), Data::PrepareBlurredBackground(image),
Images::Option(0)); Images::Option(0));
crl::on_main([ crl::on_main(std::move(guard), [
this, this,
image = std::move(image), image = std::move(image),
scaled = std::move(scaled), scaled = std::move(scaled),
blurred = std::move(blurred), blurred = std::move(blurred)
guard = std::move(guard)
]() mutable { ]() mutable {
if (!guard) {
return;
}
_full = std::move(image); _full = std::move(image);
setScaledFromImage(std::move(scaled), std::move(blurred)); setScaledFromImage(std::move(scaled), std::move(blurred));
update(); update();

View File

@ -1624,14 +1624,10 @@ base::binary_guard ReadImageAsync(
if (postprocess) { if (postprocess) {
image = postprocess(std::move(image)); image = postprocess(std::move(image));
} }
crl::on_main([ crl::on_main(std::move(guard), [
guard = std::move(guard),
image = std::move(image), image = std::move(image),
callback = std::move(callback) callback = std::move(callback)
]() mutable { ]() mutable {
if (!guard) {
return;
}
callback(std::move(image)); callback(std::move(image));
}); });
}); });

View File

@ -107,15 +107,11 @@ void GoodThumbSource::ready(
QImage &&image, QImage &&image,
int bytesSize, int bytesSize,
QByteArray &&bytesForCache) { QByteArray &&bytesForCache) {
crl::on_main([ crl::on_main(std::move(guard), [
=, =,
guard = std::move(guard),
image = std::move(image), image = std::move(image),
bytes = std::move(bytesForCache) bytes = std::move(bytesForCache)
]() mutable { ]() mutable {
if (!guard) {
return;
}
if (image.isNull()) { if (image.isNull()) {
_empty = true; _empty = true;
return; return;

View File

@ -426,16 +426,12 @@ void FileLoader::loadLocal(const Storage::Cache::Key &key) {
QByteArray &&value, QByteArray &&value,
QImage &&image, QImage &&image,
QByteArray &&format) mutable { QByteArray &&format) mutable {
crl::on_main([ crl::on_main(std::move(guard), [
=, =,
value = std::move(value), value = std::move(value),
image = std::move(image), image = std::move(image),
format = std::move(format), format = std::move(format)
guard = std::move(guard)
]() mutable { ]() mutable {
if (!guard) {
return;
}
localLoaded( localLoaded(
StorageImageSaved(std::move(value)), StorageImageSaved(std::move(value)),
format, format,

View File

@ -92,10 +92,7 @@ void Databases::destroy(Cache::Database *database) {
kept.destroying = std::move(first); kept.destroying = std::move(first);
database->close(); database->close();
database->waitForCleaner([=, guard = std::move(second)]() mutable { database->waitForCleaner([=, guard = std::move(second)]() mutable {
crl::on_main([=, guard = std::move(guard)]{ crl::on_main(std::move(guard), [=] {
if (!guard) {
return;
}
_map.erase(path); _map.erase(path);
}); });
}); });

View File

@ -486,14 +486,10 @@ void Templates::load() {
crl::async([=, guard = std::move(right)]() mutable { crl::async([=, guard = std::move(right)]() mutable {
auto result = ReadFiles(cWorkingDir() + "TEMPLATES"); auto result = ReadFiles(cWorkingDir() + "TEMPLATES");
result.index = ComputeIndex(result.result); result.index = ComputeIndex(result.result);
crl::on_main([ crl::on_main(std::move(guard), [
=, =,
result = std::move(result), result = std::move(result)
guard = std::move(guard)
]() mutable { ]() mutable {
if (!guard) {
return;
}
setData(std::move(result.result)); setData(std::move(result.result));
_index = std::move(result.index); _index = std::move(result.index);
_errors.fire(std::move(result.errors)); _errors.fire(std::move(result.errors));

View File

@ -947,12 +947,11 @@ void Instance::generateCache() {
universal = Universal, universal = Universal,
guard = std::move(right) guard = std::move(right)
]() mutable { ]() mutable {
crl::on_main([ crl::on_main(std::move(guard), [
=, =,
image = universal->generate(size, index), image = universal->generate(size, index)
guard = std::move(guard)
]() mutable { ]() mutable {
if (!guard || universal != Universal) { if (universal != Universal) {
return; return;
} }
pushSprite(std::move(image)); pushSprite(std::move(image));