Introduced Library::getBookByIdThreadSafe()

This commit is contained in:
Veloman Yunkan 2021-11-28 19:49:31 +04:00
parent 02b9e32d18
commit 473d2d2a69
2 changed files with 8 additions and 0 deletions

View File

@ -220,6 +220,8 @@ class Library : private LibraryBase
// XXX: This is a non-thread-safe operation // XXX: This is a non-thread-safe operation
const Book& getBookByPath(const std::string& path) const; const Book& getBookByPath(const std::string& path) const;
Book getBookByIdThreadSafe(const std::string& id) const;
std::shared_ptr<Reader> getReaderById(const std::string& id); std::shared_ptr<Reader> getReaderById(const std::string& id);
std::shared_ptr<zim::Archive> getArchiveById(const std::string& id); std::shared_ptr<zim::Archive> getArchiveById(const std::string& id);

View File

@ -156,6 +156,12 @@ const Book& Library::getBookById(const std::string& id) const
return m_books.at(id); return m_books.at(id);
} }
Book Library::getBookByIdThreadSafe(const std::string& id) const
{
std::lock_guard<std::mutex> lock(m_mutex);
return getBookById(id);
}
const Book& Library::getBookByPath(const std::string& path) const const Book& Library::getBookByPath(const std::string& path) const
{ {
// XXX: Doesn't make sense to lock this operation since it cannot // XXX: Doesn't make sense to lock this operation since it cannot