mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-11-28 05:39:35 +08:00
Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
parent
62eae84fea
commit
d8500adcf4
@ -24,7 +24,6 @@
|
||||
#include "imagedata.h"
|
||||
|
||||
#include <cinttypes> // for PRId64
|
||||
#include <thread> // for std::thread
|
||||
|
||||
#include "allheaders.h" // for pixDestroy, pixGetHeight, pixGetWidth, lept_...
|
||||
#include "boxread.h" // for ReadMemBoxes
|
||||
@ -396,6 +395,9 @@ DocumentData::DocumentData(const STRING& name)
|
||||
reader_(nullptr) {}
|
||||
|
||||
DocumentData::~DocumentData() {
|
||||
if (thread.joinable()) {
|
||||
thread.join();
|
||||
}
|
||||
std::lock_guard<std::mutex> lock_p(pages_mutex_);
|
||||
std::lock_guard<std::mutex> lock_g(general_mutex_);
|
||||
}
|
||||
@ -454,8 +456,10 @@ void DocumentData::LoadPageInBackground(int index) {
|
||||
if (pages_offset_ == index) return;
|
||||
pages_offset_ = index;
|
||||
pages_.clear();
|
||||
std::thread t(&tesseract::DocumentData::ReCachePages, this);
|
||||
t.detach();
|
||||
if (thread.joinable()) {
|
||||
thread.join();
|
||||
}
|
||||
thread = std::thread(&tesseract::DocumentData::ReCachePages, this);
|
||||
}
|
||||
|
||||
// Returns a pointer to the page with the given index, modulo the total
|
||||
|
@ -20,9 +20,10 @@
|
||||
#define TESSERACT_IMAGE_IMAGEDATA_H_
|
||||
|
||||
#include <mutex> // for std::mutex
|
||||
#include <thread> // for std::thread
|
||||
#include <tesseract/genericvector.h> // for GenericVector, PointerVector, FileReader
|
||||
#include "points.h" // for FCOORD
|
||||
#include <tesseract/strngs.h> // for STRING
|
||||
#include <tesseract/strngs.h> // for STRING
|
||||
|
||||
class ScrollView;
|
||||
class TBOX;
|
||||
@ -313,6 +314,9 @@ class DocumentData {
|
||||
// Mutex that protects other data members that callers want to access without
|
||||
// waiting for a load operation.
|
||||
mutable std::mutex general_mutex_;
|
||||
|
||||
// Thread which loads document.
|
||||
std::thread thread;
|
||||
};
|
||||
|
||||
// A collection of DocumentData that knows roughly how much memory it is using.
|
||||
|
Loading…
Reference in New Issue
Block a user