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

Unified Diff: device/generic_sensor/public/cpp/sensor_reading.h

Issue 2395853003: [Sensors] Improvements in shared buffer managing (Closed)
Patch Set: Pass task runner to PlatformSensor constructor 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
Index: device/generic_sensor/public/cpp/sensor_reading.h
diff --git a/device/generic_sensor/public/cpp/sensor_reading.h b/device/generic_sensor/public/cpp/sensor_reading.h
new file mode 100644
index 0000000000000000000000000000000000000000..30c2e58fa4899c6f84ebcbfb2b4437ac109eb8c1
--- /dev/null
+++ b/device/generic_sensor/public/cpp/sensor_reading.h
@@ -0,0 +1,54 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef DEVICE_GENERIC_SENSOR_PUBLIC_CPP_SENSOR_READING_H_
+#define DEVICE_GENERIC_SENSOR_PUBLIC_CPP_SENSOR_READING_H_
+
+#include "device/base/synchronization/one_writer_seqlock.h"
+
+namespace device {
+
+// This class is guarantied to have a fixed size of 64 bits on every platform.
+// It is introduce to simplify sensors shared buffer memory calculation.
+template <typename Data>
+class SensorReadingField {
+ public:
+ static_assert(sizeof(Data) <= sizeof(int64_t), "The field must be 64 bits.");
Ken Rockot(use gerrit already) 2016/10/10 16:02:08 nit: Assertion is really that the field size must
Mikhail 2016/10/10 18:29:20 Done.
+ SensorReadingField() = default;
+ SensorReadingField(Data value) { storage.value = value; }
+ SensorReadingField& operator=(Data value) {
+ storage.value = value;
+ return *this;
+ }
+ Data& value() { return storage.value; }
+ operator Data() const { return storage.value; }
+
+ private:
+ union Storage {
+ int64_t unused;
+ Data value;
+ Storage() { new (&value) Data(); }
Ken Rockot(use gerrit already) 2016/10/10 16:02:08 This is subtly broken if Data has a non-trivial de
Mikhail 2016/10/10 18:29:20 Done. Thanks for catching this!
+ };
+ Storage storage;
+};
+
+// This structure represents sensor reading data: timestamp and 3 values.
+struct SensorReading {
+ SensorReading();
+ SensorReading(const SensorReading& other);
+ SensorReadingField<double> timestamp;
+ SensorReadingField<double> values[3];
+};
+
+// This structure represents sensor reading buffer: sensor reading and seqlock
+// for synchronization.
+struct SensorReadingSharedBuffer {
+ SensorReadingSharedBuffer();
+ SensorReadingField<OneWriterSeqLock> seqlock;
+ SensorReading reading;
+};
+
+} // namespace device
+
+#endif // DEVICE_GENERIC_SENSOR_PUBLIC_CPP_SENSOR_READING_H_

Powered by Google App Engine
This is Rietveld 408576698