diff options
author | Brad Fitzpatrick <bradfitz@android.com> | 2010-03-22 12:08:26 -0700 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@android.com> | 2010-03-22 12:08:26 -0700 |
commit | 90dd21eff5f4799dd770a6e1a0390ac68734429a (patch) | |
tree | 2088f0389afe3a38e42a6b715e2645fc558f1c79 /wifi | |
parent | ac96fa575f17d4a65e65eddebe805c904fb29c19 (diff) | |
download | frameworks_base-90dd21eff5f4799dd770a6e1a0390ac68734429a.zip frameworks_base-90dd21eff5f4799dd770a6e1a0390ac68734429a.tar.gz frameworks_base-90dd21eff5f4799dd770a6e1a0390ac68734429a.tar.bz2 |
Make getting wifi state lockless.
Previous it was synchronized on the same lock that was held while
transitioning wifi states, effectively making it impossible to ever
find out about such states, and worse: making calls during transitions
block.
This manifested itself in a really laggy power control widget, which
I'm working on fixing in general in a separate change.
Change-Id: Ia34af98c73d7f5662e41360a213df87f6adaf130
Diffstat (limited to 'wifi')
-rw-r--r-- | wifi/java/android/net/wifi/WifiStateTracker.java | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/wifi/java/android/net/wifi/WifiStateTracker.java b/wifi/java/android/net/wifi/WifiStateTracker.java index abae65d..73ed6ed 100644 --- a/wifi/java/android/net/wifi/WifiStateTracker.java +++ b/wifi/java/android/net/wifi/WifiStateTracker.java @@ -54,10 +54,11 @@ import android.content.Context; import android.database.ContentObserver; import com.android.internal.app.IBatteryStats; -import java.util.List; +import java.net.UnknownHostException; import java.util.ArrayList; +import java.util.List; import java.util.Set; -import java.net.UnknownHostException; +import java.util.concurrent.atomic.AtomicInteger; /** * Track the state of Wifi connectivity. All event handling is done here, @@ -284,6 +285,13 @@ public class WifiStateTracker extends NetworkStateTracker { * {@link WifiManager#WIFI_STATE_UNKNOWN} */ private int mWifiState; + + /** + * For getWifiState(), to make sure it's always fast, even when the + * instance lock is held on other slow operations. + */ + private final AtomicInteger mWifiStateAtomic = new AtomicInteger(WIFI_STATE_UNKNOWN); + // Wi-Fi run states: private static final int RUN_STATE_STARTING = 1; private static final int RUN_STATE_RUNNING = 2; @@ -1504,11 +1512,12 @@ public class WifiStateTracker extends NetworkStateTracker { return true; } - public synchronized int getWifiState() { - return mWifiState; + public int getWifiState() { + return mWifiStateAtomic.get(); } public synchronized void setWifiState(int wifiState) { + mWifiStateAtomic.set(wifiState); mWifiState = wifiState; } |