Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit af16d0b3 authored by Mike Lockwood's avatar Mike Lockwood
Browse files

Remove unnecessary locking from MediaScanner JNI code



There is nothing in this file that requires a global lock.
Furthermore, the lock can cause timeouts in native_finalize if one instance
is being garbage collected while another is busy in processDirectory

Bug: 5002520

Change-Id: I8717f8edeb932200d9f76b3d98915cfbe18b6ec6
Signed-off-by: default avatarMike Lockwood <lockwood@android.com>
parent b7440a14
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -101,6 +101,8 @@ import java.util.Iterator;
 * Java MyMediaScanner handleStringTag.
 * Once MediaScanner processFile returns, an entry is inserted in to the database.
 *
 * The MediaScanner class is not thread-safe, so it should only be used in a single threaded manner.
 *
 * {@hide}
 */
public class MediaScanner
+0 −7
Original line number Diff line number Diff line
@@ -45,7 +45,6 @@ struct fields_t {
    jfieldID    context;
};
static fields_t fields;
static Mutex sLock;

class MyMediaScannerClient : public MediaScannerClient
{
@@ -159,13 +158,11 @@ static bool ExceptionCheck(void* env)
    return ((JNIEnv *)env)->ExceptionCheck();
}

// Call this method with sLock hold
static MediaScanner *getNativeScanner_l(JNIEnv* env, jobject thiz)
{
    return (MediaScanner *) env->GetIntField(thiz, fields.context);
}

// Call this method with sLock hold
static void setNativeScanner_l(JNIEnv* env, jobject thiz, MediaScanner *s)
{
    env->SetIntField(thiz, fields.context, (int)s);
@@ -176,7 +173,6 @@ android_media_MediaScanner_processDirectory(
        JNIEnv *env, jobject thiz, jstring path, jobject client)
{
    LOGV("processDirectory");
    Mutex::Autolock l(sLock);
    MediaScanner *mp = getNativeScanner_l(env, thiz);
    if (mp == NULL) {
        jniThrowException(env, kRunTimeException, "No scanner available");
@@ -243,7 +239,6 @@ android_media_MediaScanner_setLocale(
        JNIEnv *env, jobject thiz, jstring locale)
{
    LOGV("setLocale");
    Mutex::Autolock l(sLock);
    MediaScanner *mp = getNativeScanner_l(env, thiz);
    if (mp == NULL) {
        jniThrowException(env, kRunTimeException, "No scanner available");
@@ -268,7 +263,6 @@ android_media_MediaScanner_extractAlbumArt(
        JNIEnv *env, jobject thiz, jobject fileDescriptor)
{
    LOGV("extractAlbumArt");
    Mutex::Autolock l(sLock);
    MediaScanner *mp = getNativeScanner_l(env, thiz);
    if (mp == NULL) {
        jniThrowException(env, kRunTimeException, "No scanner available");
@@ -339,7 +333,6 @@ static void
android_media_MediaScanner_native_finalize(JNIEnv *env, jobject thiz)
{
    LOGV("native_finalize");
    Mutex::Autolock l(sLock);
    MediaScanner *mp = getNativeScanner_l(env, thiz);
    if (mp == 0) {
        return;