summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortimvolodine@chromium.org <timvolodine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-05 16:42:40 +0000
committertimvolodine@chromium.org <timvolodine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-05 16:42:40 +0000
commit0537b91236eaa8f4d4f5975647db0ecb627c3e5d (patch)
tree1da3defa0c8962fb2a219df869f4b458e241de9c
parent396cc643e6f57a0e8d222986c7105c42bf0d613e (diff)
downloadchromium_src-0537b91236eaa8f4d4f5975647db0ecb627c3e5d.zip
chromium_src-0537b91236eaa8f4d4f5975647db0ecb627c3e5d.tar.gz
chromium_src-0537b91236eaa8f4d4f5975647db0ecb627c3e5d.tar.bz2
Merge: Fix concurrency issue in DataFetcherImplAndroid.
This is a partial merge from https://codereview.chromium.org/55143008/. This patch adds a lock to protect device_motion_buffer_ from concurrent modification by 2 separate threads. We don't need a lock for device_orientation_buffer_ because in M31 Device Orientation API still uses the old implementation without shared memory and therefore does not require locking. BUG=313457 NOTRY=true R=mvanouwerkerk@chromium.org Review URL: https://codereview.chromium.org/59733002 git-svn-id: svn://svn.chromium.org/chrome/branches/1650/src@233004 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/browser/device_orientation/data_fetcher_impl_android.cc36
-rw-r--r--content/browser/device_orientation/data_fetcher_impl_android.h2
2 files changed, 32 insertions, 6 deletions
diff --git a/content/browser/device_orientation/data_fetcher_impl_android.cc b/content/browser/device_orientation/data_fetcher_impl_android.cc
index d2f6016..8d4919c 100644
--- a/content/browser/device_orientation/data_fetcher_impl_android.cc
+++ b/content/browser/device_orientation/data_fetcher_impl_android.cc
@@ -98,6 +98,11 @@ void DataFetcherImplAndroid::GotOrientation(
void DataFetcherImplAndroid::GotAcceleration(
JNIEnv*, jobject, double x, double y, double z) {
+ base::AutoLock autolock(motion_buffer_lock_);
+
+ if (!device_motion_buffer_)
+ return;
+
device_motion_buffer_->seqlock.WriteBegin();
device_motion_buffer_->data.accelerationX = x;
device_motion_buffer_->data.hasAccelerationX = true;
@@ -115,6 +120,11 @@ void DataFetcherImplAndroid::GotAcceleration(
void DataFetcherImplAndroid::GotAccelerationIncludingGravity(
JNIEnv*, jobject, double x, double y, double z) {
+ base::AutoLock autolock(motion_buffer_lock_);
+
+ if (!device_motion_buffer_)
+ return;
+
device_motion_buffer_->seqlock.WriteBegin();
device_motion_buffer_->data.accelerationIncludingGravityX = x;
device_motion_buffer_->data.hasAccelerationIncludingGravityX = true;
@@ -132,6 +142,11 @@ void DataFetcherImplAndroid::GotAccelerationIncludingGravity(
void DataFetcherImplAndroid::GotRotationRate(
JNIEnv*, jobject, double alpha, double beta, double gamma) {
+ base::AutoLock autolock(motion_buffer_lock_);
+
+ if (!device_motion_buffer_)
+ return;
+
device_motion_buffer_->seqlock.WriteBegin();
device_motion_buffer_->data.rotationRateAlpha = alpha;
device_motion_buffer_->data.hasRotationRateAlpha = true;
@@ -176,23 +191,32 @@ int DataFetcherImplAndroid::GetNumberActiveDeviceMotionSensors() {
bool DataFetcherImplAndroid::StartFetchingDeviceMotionData(
DeviceMotionHardwareBuffer* buffer) {
DCHECK(buffer);
- device_motion_buffer_ = buffer;
- ClearInternalMotionBuffers();
+ {
+ base::AutoLock autolock(motion_buffer_lock_);
+ device_motion_buffer_ = buffer;
+ ClearInternalMotionBuffers();
+ }
bool success = Start(DeviceData::kTypeMotion);
// If no motion data can ever be provided, the number of active device motion
// sensors will be zero. In that case flag the shared memory buffer
// as ready to read, as it will not change anyway.
number_active_device_motion_sensors_ = GetNumberActiveDeviceMotionSensors();
- CheckMotionBufferReadyToRead();
+ {
+ base::AutoLock autolock(motion_buffer_lock_);
+ CheckMotionBufferReadyToRead();
+ }
return success;
}
void DataFetcherImplAndroid::StopFetchingDeviceMotionData() {
Stop(DeviceData::kTypeMotion);
- if (device_motion_buffer_) {
- ClearInternalMotionBuffers();
- device_motion_buffer_ = NULL;
+ {
+ base::AutoLock autolock(motion_buffer_lock_);
+ if (device_motion_buffer_) {
+ ClearInternalMotionBuffers();
+ device_motion_buffer_ = NULL;
+ }
}
}
diff --git a/content/browser/device_orientation/data_fetcher_impl_android.h b/content/browser/device_orientation/data_fetcher_impl_android.h
index 35ed1c7..f348e1d 100644
--- a/content/browser/device_orientation/data_fetcher_impl_android.h
+++ b/content/browser/device_orientation/data_fetcher_impl_android.h
@@ -99,6 +99,8 @@ class CONTENT_EXPORT DataFetcherImplAndroid {
bool is_motion_buffer_ready_;
bool is_orientation_buffer_ready_;
+ base::Lock motion_buffer_lock_;
+
DISALLOW_COPY_AND_ASSIGN(DataFetcherImplAndroid);
};