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

Side by Side Diff: device/generic_sensor/platform_sensor_reader_linux.h

Issue 2569763004: [sensors](Linux) Fix tsan data race in sensor reader (Closed)
Patch Set: modify code comments Created 4 years 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_READER_LINUX_H_ 5 #ifndef DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_READER_LINUX_H_
6 #define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_READER_LINUX_H_ 6 #define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_READER_LINUX_H_
7 7
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "device/generic_sensor/generic_sensor_export.h" 9 #include "device/generic_sensor/generic_sensor_export.h"
10 10
11 namespace base { 11 namespace base {
12 class SingleThreadTaskRunner; 12 class SingleThreadTaskRunner;
13 } 13 }
14 14
15 namespace device { 15 namespace device {
16 16
17 class PlatformSensorLinux; 17 class PlatformSensorLinux;
18 class PlatformSensorConfiguration; 18 class PlatformSensorConfiguration;
19 struct SensorInfoLinux; 19 struct SensorInfoLinux;
20 20
21 // A generic reader class that can be implemented with two different strategies: 21 // A generic reader class that can be implemented with two different strategies:
22 // polling and on trigger. 22 // polling and on trigger. All methods are not thread-safe.
23 class SensorReader { 23 class SensorReader {
24 public: 24 public:
25 // Creates a new instance of SensorReader. At the moment, only polling 25 // Creates a new instance of SensorReader. At the moment, only polling
26 // reader is supported. 26 // reader is supported.
27 static std::unique_ptr<SensorReader> Create( 27 static std::unique_ptr<SensorReader> Create(
28 const SensorInfoLinux* sensor_device, 28 const SensorInfoLinux* sensor_device,
29 PlatformSensorLinux* sensor, 29 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
30 scoped_refptr<base::SingleThreadTaskRunner> polling_thread_task_runner);
31 30
32 virtual ~SensorReader(); 31 virtual ~SensorReader();
33 32
34 // Starts fetching data based on strategy this reader has chosen. 33 // Starts fetching data based on strategy this reader has chosen.
35 // Only polling strategy is supported at the moment. Thread safe. 34 // Only polling strategy is supported at the moment.
36 virtual bool StartFetchingData( 35 virtual void StartFetchingData(
37 const PlatformSensorConfiguration& configuration) = 0; 36 const PlatformSensorConfiguration& configuration) = 0;
38 37
39 // Stops fetching data. Thread safe. 38 // Stops fetching data.
40 virtual void StopFetchingData() = 0; 39 virtual void StopFetchingData() = 0;
41 40
41 // Sets sensor that this reader reports to. Must Must be called after the
42 // SensorReader is constructed, before tasks are posted to it from another
43 // sequence.
44 void SetPlatformSensorLinux(PlatformSensorLinux* sensor);
45
42 protected: 46 protected:
43 SensorReader(PlatformSensorLinux* sensor, 47 SensorReader(scoped_refptr<base::SingleThreadTaskRunner> task_runner);
44 scoped_refptr<base::SingleThreadTaskRunner> polling_task_runner);
45 48
46 // Notifies |sensor_| about an error. 49 // Notifies |sensor_| about an error.
47 void NotifyReadError(); 50 void NotifyReadError();
48 51
49 // Non-owned pointer to a sensor that created this reader. 52 // Non-owned pointer to a sensor that created this reader.
50 PlatformSensorLinux* sensor_; 53 PlatformSensorLinux* sensor_;
51 54
52 // A task runner that is used to poll data. 55 // A task runner that belongs to a thread this reader is created on.
53 scoped_refptr<base::SingleThreadTaskRunner> polling_task_runner_; 56 scoped_refptr<base::SingleThreadTaskRunner> polling_task_runner_;
54 57
55 // A task runner that belongs to a thread this reader is created on. 58 // A task runner that is used to report reading updates and errors
56 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 59 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
57 60
58 // Indicates if reading is active. 61 // Indicates if reading is active.
59 bool is_reading_active_; 62 bool is_reading_active_;
60 63
61 DISALLOW_COPY_AND_ASSIGN(SensorReader); 64 DISALLOW_COPY_AND_ASSIGN(SensorReader);
62 }; 65 };
63 66
64 } // namespace device 67 } // namespace device
65 68
66 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_READER_LINUX_H_ 69 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_READER_LINUX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698