Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(791)

Unified Diff: third_party/WebKit/Source/modules/sensor/SensorProxy.cpp

Issue 2395853003: [Sensors] Improvements in shared buffer managing (Closed)
Patch Set: Test compilation fix + comment from Ken Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/sensor/SensorProxy.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/sensor/SensorProxy.cpp
diff --git a/third_party/WebKit/Source/modules/sensor/SensorProxy.cpp b/third_party/WebKit/Source/modules/sensor/SensorProxy.cpp
index 0e2b58ad38addbb8c7aab354e551476276ce5c0a..483e98fe05b69730cf2f3fc19ca29e54cb093adb 100644
--- a/third_party/WebKit/Source/modules/sensor/SensorProxy.cpp
+++ b/third_party/WebKit/Source/modules/sensor/SensorProxy.cpp
@@ -99,8 +99,14 @@ const device::mojom::blink::SensorConfiguration* SensorProxy::defaultConfig()
void SensorProxy::updateInternalReading() {
DCHECK(isInitialized());
- Reading* reading = static_cast<Reading*>(m_sharedBuffer.get());
- m_reading = *reading;
+ int readAttempts = 0;
+ const int kMaxReadAttemptsCount = 10;
+ while (!tryReadFromBuffer()) {
+ if (++readAttempts == kMaxReadAttemptsCount) {
+ handleSensorError();
+ return;
+ }
+ }
}
void SensorProxy::RaiseError() {
@@ -133,8 +139,9 @@ void SensorProxy::onSensorCreated(SensorInitParamsPtr params,
handleSensorError(NotFoundError, "Sensor is not present on the platform.");
return;
}
+ const size_t kReadBufferSize = sizeof(ReadingBuffer);
- DCHECK_EQ(0u, params->buffer_offset % SensorInitParams::kReadBufferSize);
+ DCHECK_EQ(0u, params->buffer_offset % kReadBufferSize);
m_mode = params->mode;
m_defaultConfig = std::move(params->default_configuration);
@@ -148,8 +155,8 @@ void SensorProxy::onSensorCreated(SensorInitParamsPtr params,
m_sharedBufferHandle = std::move(params->memory);
DCHECK(!m_sharedBuffer);
- m_sharedBuffer = m_sharedBufferHandle->MapAtOffset(
- SensorInitParams::kReadBufferSize, params->buffer_offset);
+ m_sharedBuffer =
+ m_sharedBufferHandle->MapAtOffset(kReadBufferSize, params->buffer_offset);
if (!m_sharedBuffer) {
handleSensorError();
@@ -167,4 +174,16 @@ void SensorProxy::onSensorCreated(SensorInitParamsPtr params,
observer->onSensorInitialized();
}
+bool SensorProxy::tryReadFromBuffer() {
+ DCHECK(isInitialized());
+ ReadingBuffer* buffer = static_cast<ReadingBuffer*>(m_sharedBuffer.get());
+ device::OneWriterSeqLock& seqlock = buffer->seqlock.value();
+ auto version = seqlock.ReadBegin();
+ auto reading = buffer->reading;
+ if (seqlock.ReadRetry(version))
+ return false;
+ m_reading = reading;
+ return true;
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/modules/sensor/SensorProxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698