Syncronize pdfium initialization between users.
Only initalize pdfium once per process and only destroy it once all users are gone. Bug: 28387883, 28370309, 28388184 Change-Id: I41e8f6da247a7cfab5fb9d159c047293719192c3
This commit is contained in:
@@ -51,22 +51,22 @@ static struct {
|
||||
jfieldID bottom;
|
||||
} gRectClassInfo;
|
||||
|
||||
static Mutex sLock;
|
||||
|
||||
static int sUnmatchedInitRequestCount = 0;
|
||||
// Also used in PdfRenderer.cpp
|
||||
Mutex sPdfiumLock;
|
||||
int sUnmatchedPdfiumInitRequestCount = 0;
|
||||
|
||||
static void initializeLibraryIfNeeded() {
|
||||
Mutex::Autolock _l(sLock);
|
||||
if (sUnmatchedInitRequestCount == 0) {
|
||||
Mutex::Autolock _l(sPdfiumLock);
|
||||
if (sUnmatchedPdfiumInitRequestCount == 0) {
|
||||
FPDF_InitLibrary();
|
||||
}
|
||||
sUnmatchedInitRequestCount++;
|
||||
sUnmatchedPdfiumInitRequestCount++;
|
||||
}
|
||||
|
||||
static void destroyLibraryIfNeeded() {
|
||||
Mutex::Autolock _l(sLock);
|
||||
sUnmatchedInitRequestCount--;
|
||||
if (sUnmatchedInitRequestCount == 0) {
|
||||
Mutex::Autolock _l(sPdfiumLock);
|
||||
sUnmatchedPdfiumInitRequestCount--;
|
||||
if (sUnmatchedPdfiumInitRequestCount == 0) {
|
||||
FPDF_DestroyLibrary();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,22 +43,22 @@ static struct {
|
||||
jfieldID y;
|
||||
} gPointClassInfo;
|
||||
|
||||
static Mutex sLock;
|
||||
|
||||
static int sUnmatchedInitRequestCount = 0;
|
||||
// See PdfEditor.cpp
|
||||
extern Mutex sPdfiumLock;
|
||||
extern int sUnmatchedPdfiumInitRequestCount;
|
||||
|
||||
static void initializeLibraryIfNeeded() {
|
||||
Mutex::Autolock _l(sLock);
|
||||
if (sUnmatchedInitRequestCount == 0) {
|
||||
Mutex::Autolock _l(sPdfiumLock);
|
||||
if (sUnmatchedPdfiumInitRequestCount == 0) {
|
||||
FPDF_InitLibrary();
|
||||
}
|
||||
sUnmatchedInitRequestCount++;
|
||||
sUnmatchedPdfiumInitRequestCount++;
|
||||
}
|
||||
|
||||
static void destroyLibraryIfNeeded() {
|
||||
Mutex::Autolock _l(sLock);
|
||||
sUnmatchedInitRequestCount--;
|
||||
if (sUnmatchedInitRequestCount == 0) {
|
||||
Mutex::Autolock _l(sPdfiumLock);
|
||||
sUnmatchedPdfiumInitRequestCount--;
|
||||
if (sUnmatchedPdfiumInitRequestCount == 0) {
|
||||
FPDF_DestroyLibrary();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user