OSDN Git Service

Lock when obtaining the current monitor name.
authorMichael Wright <michaelwr@google.com>
Mon, 1 Apr 2013 23:36:05 +0000 (16:36 -0700)
committerMichael Wright <michaelwr@google.com>
Mon, 1 Apr 2013 23:46:36 +0000 (16:46 -0700)
Also, remove some dead code.

Change-Id: I0e65671f9ca43addd8fc44dcd878bcff2f588e42

services/java/com/android/server/Watchdog.java

index 1663106..167e7af 100644 (file)
@@ -88,7 +88,6 @@ public class Watchdog extends Thread {
     AlarmManagerService mAlarm;
     ActivityManagerService mActivity;
     boolean mCompleted;
-    boolean mForceKillSystem;
     Monitor mCurrentMonitor;
 
     int mPhonePid;
@@ -135,7 +134,9 @@ public class Watchdog extends Thread {
 
                     final int size = mMonitors.size();
                     for (int i = 0 ; i < size ; i++) {
-                        mCurrentMonitor = mMonitors.get(i);
+                        synchronized (Watchdog.this) {
+                            mCurrentMonitor = mMonitors.get(i);
+                        }
                         mCurrentMonitor.monitor();
                     }
 
@@ -388,6 +389,8 @@ public class Watchdog extends Thread {
             mCompleted = false;
             mHandler.sendEmptyMessage(MONITOR);
 
+
+            final String name;
             synchronized (this) {
                 long timeout = TIME_TO_WAIT;
 
@@ -396,16 +399,16 @@ public class Watchdog extends Thread {
                 // to timeout on is asleep as well and won't have a chance to run, causing a false
                 // positive on when to kill things.
                 long start = SystemClock.uptimeMillis();
-                while (timeout > 0 && !mForceKillSystem) {
+                while (timeout > 0) {
                     try {
-                        wait(timeout);  // notifyAll() is called when mForceKillSystem is set
+                        wait(timeout);
                     } catch (InterruptedException e) {
                         Log.wtf(TAG, e);
                     }
                     timeout = TIME_TO_WAIT - (SystemClock.uptimeMillis() - start);
                 }
 
-                if (mCompleted && !mForceKillSystem) {
+                if (mCompleted) {
                     // The monitors have returned.
                     waitedHalf = false;
                     continue;
@@ -421,14 +424,14 @@ public class Watchdog extends Thread {
                     waitedHalf = true;
                     continue;
                 }
+
+                name = (mCurrentMonitor != null) ?
+                    mCurrentMonitor.getClass().getName() : "null";
             }
 
             // If we got here, that means that the system is most likely hung.
             // First collect stack traces from all threads of the system process.
             // Then kill this process so that the system will restart.
-
-            final String name = (mCurrentMonitor != null) ?
-                    mCurrentMonitor.getClass().getName() : "null";
             EventLog.writeEvent(EventLogTags.WATCHDOG, name);
 
             ArrayList<Integer> pids = new ArrayList<Integer>();