mirror of https://github.com/kiwix/libkiwix.git
Thread-safe Book::Illustration::getData()
This commit is contained in:
parent
eb6a0d6456
commit
4a01081e83
|
@ -23,6 +23,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
namespace pugi {
|
namespace pugi {
|
||||||
class xml_node;
|
class xml_node;
|
||||||
|
@ -57,6 +58,7 @@ class Book
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable std::string data;
|
mutable std::string data;
|
||||||
|
mutable std::mutex mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<std::shared_ptr<const Illustration>> Illustrations;
|
typedef std::vector<std::shared_ptr<const Illustration>> Illustrations;
|
||||||
|
|
11
src/book.cpp
11
src/book.cpp
|
@ -227,10 +227,13 @@ const Book::Illustration& Book::getDefaultIllustration() const
|
||||||
const std::string& Book::Illustration::getData() const
|
const std::string& Book::Illustration::getData() const
|
||||||
{
|
{
|
||||||
if (data.empty() && !url.empty()) {
|
if (data.empty() && !url.empty()) {
|
||||||
try {
|
const std::lock_guard<std::mutex> l(mutex);
|
||||||
data = download(url);
|
if ( data.empty() ) {
|
||||||
} catch(...) {
|
try {
|
||||||
std::cerr << "Cannot download favicon from " << url;
|
data = download(url);
|
||||||
|
} catch(...) {
|
||||||
|
std::cerr << "Cannot download favicon from " << url;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
|
|
Loading…
Reference in New Issue