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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef DEVICE_GENERIC_SENSOR_PUBLIC_CPP_SENSOR_READING_H_
6 #define DEVICE_GENERIC_SENSOR_PUBLIC_CPP_SENSOR_READING_H_
7
8 #include "device/base/synchronization/one_writer_seqlock.h"
9
10 namespace device {
11
12 // This class is guarantied to have a fixed size of 64 bits on every platform.
13 // It is introduce to simplify sensors shared buffer memory calculation.
14 template <typename Data>
15 class SensorReadingField {
16 public:
17 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.
18 SensorReadingField() = default;
19 SensorReadingField(Data value) { storage.value = value; }
20 SensorReadingField& operator=(Data value) {
21 storage.value = value;
22 return *this;
23 }
24 Data& value() { return storage.value; }
25 operator Data() const { return storage.value; }
26
27 private:
28 union Storage {
29 int64_t unused;
30 Data value;
31 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!
32 };
33 Storage storage;
34 };
35
36 // This structure represents sensor reading data: timestamp and 3 values.
37 struct SensorReading {
38 SensorReading();
39 SensorReading(const SensorReading& other);
40 SensorReadingField<double> timestamp;
41 SensorReadingField<double> values[3];
42 };
43
44 // This structure represents sensor reading buffer: sensor reading and seqlock
45 // for synchronization.
46 struct SensorReadingSharedBuffer {
47 SensorReadingSharedBuffer();
48 SensorReadingField<OneWriterSeqLock> seqlock;
49 SensorReading reading;
50 };
51
52 } // namespace device
53
54 #endif // DEVICE_GENERIC_SENSOR_PUBLIC_CPP_SENSOR_READING_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698