1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 10:19:33 +02:00

native calls sync; this should fix big library scanning issues

This commit is contained in:
Nikolay Pultsin 2015-06-27 22:27:10 +01:00
parent b0ace4712a
commit 6ac1e00232
2 changed files with 32 additions and 13 deletions

View file

@ -354,7 +354,7 @@ JNIEXPORT jint JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin
} }
extern "C" extern "C"
JNIEXPORT jstring JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readAnnotationInternal(JNIEnv* env, jobject thiz, jobject file) { JNIEXPORT jstring JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readAnnotationNative(JNIEnv* env, jobject thiz, jobject file) {
shared_ptr<FormatPlugin> plugin = findCppPlugin(thiz); shared_ptr<FormatPlugin> plugin = findCppPlugin(thiz);
if (plugin.isNull()) { if (plugin.isNull()) {
return 0; return 0;
@ -365,7 +365,7 @@ JNIEXPORT jstring JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlu
} }
extern "C" extern "C"
JNIEXPORT void JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readCoverInternal(JNIEnv* env, jobject thiz, jobject file, jobjectArray box) { JNIEXPORT void JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readCoverNative(JNIEnv* env, jobject thiz, jobject file, jobjectArray box) {
shared_ptr<FormatPlugin> plugin = findCppPlugin(thiz); shared_ptr<FormatPlugin> plugin = findCppPlugin(thiz);
if (plugin.isNull()) { if (plugin.isNull()) {
return; return;

View file

@ -35,6 +35,8 @@ import org.geometerplus.fbreader.formats.fb2.FB2NativePlugin;
import org.geometerplus.fbreader.formats.oeb.OEBNativePlugin; import org.geometerplus.fbreader.formats.oeb.OEBNativePlugin;
public class NativeFormatPlugin extends BuiltinFormatPlugin { public class NativeFormatPlugin extends BuiltinFormatPlugin {
private static final Object ourNativeLock = new Object();
public static NativeFormatPlugin create(String fileType) { public static NativeFormatPlugin create(String fileType) {
if ("fb2".equals(fileType)) { if ("fb2".equals(fileType)) {
return new FB2NativePlugin(); return new FB2NativePlugin();
@ -51,7 +53,10 @@ public class NativeFormatPlugin extends BuiltinFormatPlugin {
@Override @Override
synchronized public void readMetainfo(AbstractBook book) throws BookReadingException { synchronized public void readMetainfo(AbstractBook book) throws BookReadingException {
final int code = readMetainfoNative(book); final int code;
synchronized (ourNativeLock) {
code = readMetainfoNative(book);
}
if (code != 0) { if (code != 0) {
throw new BookReadingException( throw new BookReadingException(
"nativeCodeFailure", "nativeCodeFailure",
@ -65,7 +70,10 @@ public class NativeFormatPlugin extends BuiltinFormatPlugin {
@Override @Override
public List<FileEncryptionInfo> readEncryptionInfos(AbstractBook book) { public List<FileEncryptionInfo> readEncryptionInfos(AbstractBook book) {
final FileEncryptionInfo[] infos = readEncryptionInfosNative(book); final FileEncryptionInfo[] infos;
synchronized (ourNativeLock) {
infos = readEncryptionInfosNative(book);
}
return infos != null return infos != null
? Arrays.<FileEncryptionInfo>asList(infos) ? Arrays.<FileEncryptionInfo>asList(infos)
: Collections.<FileEncryptionInfo>emptyList(); : Collections.<FileEncryptionInfo>emptyList();
@ -75,7 +83,9 @@ public class NativeFormatPlugin extends BuiltinFormatPlugin {
@Override @Override
synchronized public void readUids(AbstractBook book) throws BookReadingException { synchronized public void readUids(AbstractBook book) throws BookReadingException {
readUidsNative(book); synchronized (ourNativeLock) {
readUidsNative(book);
}
if (book.uids().isEmpty()) { if (book.uids().isEmpty()) {
book.addUid(BookUtil.createUid(book, "SHA-256")); book.addUid(BookUtil.createUid(book, "SHA-256"));
} }
@ -85,15 +95,20 @@ public class NativeFormatPlugin extends BuiltinFormatPlugin {
@Override @Override
public void detectLanguageAndEncoding(AbstractBook book) { public void detectLanguageAndEncoding(AbstractBook book) {
detectLanguageAndEncodingNative(book); synchronized (ourNativeLock) {
detectLanguageAndEncodingNative(book);
}
} }
public native void detectLanguageAndEncodingNative(AbstractBook book); private native void detectLanguageAndEncodingNative(AbstractBook book);
@Override @Override
synchronized public void readModel(BookModel model) throws BookReadingException { synchronized public void readModel(BookModel model) throws BookReadingException {
//android.os.Debug.startMethodTracing("ep.trace", 32 * 1024 * 1024); //android.os.Debug.startMethodTracing("ep.trace", 32 * 1024 * 1024);
final int code = readModelNative(model); final int code;
synchronized (ourNativeLock) {
code = readModelNative(model);
}
//android.os.Debug.stopMethodTracing(); //android.os.Debug.stopMethodTracing();
switch (code) { switch (code) {
case 0: case 0:
@ -112,25 +127,29 @@ public class NativeFormatPlugin extends BuiltinFormatPlugin {
private native int readModelNative(BookModel model); private native int readModelNative(BookModel model);
@Override @Override
public ZLFileImageProxy readCover(ZLFile file) { public final ZLFileImageProxy readCover(ZLFile file) {
return new ZLFileImageProxy(file) { return new ZLFileImageProxy(file) {
@Override @Override
protected ZLFileImage retrieveRealImage() { protected ZLFileImage retrieveRealImage() {
final ZLFileImage[] box = new ZLFileImage[1]; final ZLFileImage[] box = new ZLFileImage[1];
readCoverInternal(File, box); synchronized (ourNativeLock) {
readCoverNative(File, box);
}
return box[0]; return box[0];
} }
}; };
} }
protected native void readCoverInternal(ZLFile file, ZLFileImage[] box); private native void readCoverNative(ZLFile file, ZLFileImage[] box);
@Override @Override
public String readAnnotation(ZLFile file) { public String readAnnotation(ZLFile file) {
return readAnnotationInternal(file); synchronized (ourNativeLock) {
return readAnnotationNative(file);
}
} }
protected native String readAnnotationInternal(ZLFile file); private native String readAnnotationNative(ZLFile file);
@Override @Override
public int priority() { public int priority() {