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

Side by Side Diff: device/generic_sensor/public/cpp/sensor_reading.h

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 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 #include "device/generic_sensor/public/interfaces/sensor.mojom.h"
10
11 namespace device {
12
13 // This class is guarantied to have a fixed size of 64 bits on every platform.
14 // It is introduce to simplify sensors shared buffer memory calculation.
15 template <typename Data>
16 class SensorReadingField {
17 public:
18 static_assert(sizeof(Data) <= sizeof(int64_t),
19 "The field size must be <= 64 bits.");
20 SensorReadingField() = default;
21 SensorReadingField(Data value) { storage_.value = value; }
22 SensorReadingField& operator=(Data value) {
23 storage_.value = value;
24 return *this;
25 }
26 Data& value() { return storage_.value; }
27 operator Data() const { return storage_.value; }
28
29 private:
30 union Storage {
31 int64_t unused;
32 Data value;
33 Storage() { new (&value) Data(); }
34 ~Storage() { value.~Data(); }
35 };
36 Storage storage_;
37 };
38
39 // This structure represents sensor reading data: timestamp and 3 values.
40 struct SensorReading {
41 SensorReading();
42 ~SensorReading();
43 SensorReading(const SensorReading& other);
44 SensorReadingField<double> timestamp;
45 SensorReadingField<double> values[3];
46 };
47
48 // This structure represents sensor reading buffer: sensor reading and seqlock
49 // for synchronization.
50 struct SensorReadingSharedBuffer {
51 SensorReadingSharedBuffer();
52 ~SensorReadingSharedBuffer();
53 SensorReadingField<OneWriterSeqLock> seqlock;
54 SensorReading reading;
55
56 // Gets the shared reading buffer offset for the given sensor type.
57 static uint64_t GetOffset(mojom::SensorType type);
58 };
59
60 } // namespace device
61
62 #endif // DEVICE_GENERIC_SENSOR_PUBLIC_CPP_SENSOR_READING_H_
OLDNEW
« no previous file with comments | « device/generic_sensor/public/cpp/BUILD.gn ('k') | device/generic_sensor/public/cpp/sensor_reading.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698