summaryrefslogtreecommitdiffstats
path: root/services/surfaceflinger/SurfaceFlinger.h
diff options
context:
space:
mode:
authorMathias Agopian <mathias@google.com>2011-05-03 16:21:41 -0700
committerMathias Agopian <mathias@google.com>2011-05-03 16:21:41 -0700
commit4f113740180b6512b43723c4728f262882dc9b45 (patch)
treea0a71ffb48dbe6daee69d6c4e906be2103303b52 /services/surfaceflinger/SurfaceFlinger.h
parent1c52ae3b726efee0af2c4bc9ad9b2bbc8236de92 (diff)
downloadframeworks_native-4f113740180b6512b43723c4728f262882dc9b45.zip
frameworks_native-4f113740180b6512b43723c4728f262882dc9b45.tar.gz
frameworks_native-4f113740180b6512b43723c4728f262882dc9b45.tar.bz2
Fix a race-condtion in SurfaceFlinger that could lead to a crash.
Client::mLayers could be accessed from different threads. On one side from Client::attachLayer() which is currently called from a binder thread; on the other side from Client::detachLayer() which is always called from the main thread. This could lead to a corruption of Client::mLayers. We fix this issue by adding an internal lock to Client. Change-Id: Ib1317d7750ed5030e6f577efe34b69fc10198bd3
Diffstat (limited to 'services/surfaceflinger/SurfaceFlinger.h')
-rw-r--r--services/surfaceflinger/SurfaceFlinger.h12
1 files changed, 9 insertions, 3 deletions
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 1b36d1c..3eb4c11 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -65,7 +65,7 @@ public:
status_t initCheck() const;
// protected by SurfaceFlinger::mStateLock
- ssize_t attachLayer(const sp<LayerBaseClient>& layer);
+ size_t attachLayer(const sp<LayerBaseClient>& layer);
void detachLayer(const LayerBaseClient* layer);
sp<LayerBaseClient> getLayerUser(int32_t i) const;
@@ -81,9 +81,15 @@ private:
virtual status_t destroySurface(SurfaceID surfaceId);
virtual status_t setState(int32_t count, const layer_state_t* states);
- DefaultKeyedVector< size_t, wp<LayerBaseClient> > mLayers;
+ // constant
sp<SurfaceFlinger> mFlinger;
- int32_t mNameGenerator;
+
+ // protected by mLock
+ DefaultKeyedVector< size_t, wp<LayerBaseClient> > mLayers;
+ size_t mNameGenerator;
+
+ // thread-safe
+ mutable Mutex mLock;
};
class UserClient : public BnSurfaceComposerClient