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 <vector>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
namespace pugi {
|
||||
class xml_node;
|
||||
|
@ -57,6 +58,7 @@ class Book
|
|||
|
||||
private:
|
||||
mutable std::string data;
|
||||
mutable std::mutex mutex;
|
||||
};
|
||||
|
||||
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
|
||||
{
|
||||
if (data.empty() && !url.empty()) {
|
||||
try {
|
||||
data = download(url);
|
||||
} catch(...) {
|
||||
std::cerr << "Cannot download favicon from " << url;
|
||||
const std::lock_guard<std::mutex> l(mutex);
|
||||
if ( data.empty() ) {
|
||||
try {
|
||||
data = download(url);
|
||||
} catch(...) {
|
||||
std::cerr << "Cannot download favicon from " << url;
|
||||
}
|
||||
}
|
||||
}
|
||||
return data;
|
||||
|
|
Loading…
Reference in New Issue