diff options
author | Matt Holgate <matt@emobix.co.uk> | 2014-06-23 16:51:16 +0100 |
---|---|---|
committer | Matt Holgate <matt@emobix.co.uk> | 2014-06-23 16:51:16 +0100 |
commit | 38ae8629788b21ae653943f8ef4f02f9bbd74b96 (patch) | |
tree | df7cd4e53b71d87ec52fc53c768720bf41311010 /platform | |
parent | 6b39f7991bf1330fc75a7dd869bc46a7f8f10078 (diff) | |
download | mupdf-38ae8629788b21ae653943f8ef4f02f9bbd74b96.tar.xz |
Prevent the creation/destruction of the fz_cookies from trampling the env/clazz pointers in globals.
The env/clazz pointers are stashed in the globals structure so that they can
be accessed by callback functions in mupdf.c (such as bufferStreamSeek()).
The intention is that only one thread (i.e. the AsyncTask background thread)
reads/writes these stashed pointers. Because cookies are created/destroyed
in the main thread, we add a new version of get_globals() which doesn't trample
these pointers.
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/jni/mupdf.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/platform/android/jni/mupdf.c b/platform/android/jni/mupdf.c index 01a8db9b..574a9d6f 100644 --- a/platform/android/jni/mupdf.c +++ b/platform/android/jni/mupdf.c @@ -249,6 +249,7 @@ static void alerts_fin(globals *glo) glo->alerts_initialised = 0; } +// Should only be called from the single background AsyncTask thread static globals *get_globals(JNIEnv *env, jobject thiz) { globals *glo = (globals *)(void *)((*env)->GetLongField(env, thiz, global_fid)); @@ -260,6 +261,13 @@ static globals *get_globals(JNIEnv *env, jobject thiz) return glo; } +// May be called from any thread, provided the values of glo->env and glo->thiz +// are not used. +static globals *get_globals_any_thread(JNIEnv *env, jobject thiz) +{ + return (globals *)(void *)((*env)->GetLongField(env, thiz, global_fid)); +} + JNIEXPORT jlong JNICALL JNI_FN(MuPDFCore_openFile)(JNIEnv * env, jobject thiz, jstring jfilename) { @@ -2594,7 +2602,7 @@ JNI_FN(MuPDFCore_dumpMemoryInternal)(JNIEnv * env, jobject thiz) JNIEXPORT jlong JNICALL JNI_FN(MuPDFCore_createCookie)(JNIEnv * env, jobject thiz) { - globals *glo = get_globals(env, thiz); + globals *glo = get_globals_any_thread(env, thiz); if (glo == NULL) return 0; fz_context *ctx = glo->ctx; @@ -2606,7 +2614,7 @@ JNIEXPORT void JNICALL JNI_FN(MuPDFCore_destroyCookie)(JNIEnv * env, jobject thiz, jlong cookiePtr) { fz_cookie *cookie = (fz_cookie *) (unsigned int) cookiePtr; - globals *glo = get_globals(env, thiz); + globals *glo = get_globals_any_thread(env, thiz); if (glo == NULL) return; fz_context *ctx = glo->ctx; |