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

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: change threading model. SensorReader now belongs to a polling thread 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 except SetPlatformSensorLinux
23 // are not safe and must be called on the same thread which this reader belongs
24 // to.
23 class SensorReader { 25 class SensorReader {
24 public: 26 public:
25 // Creates a new instance of SensorReader. At the moment, only polling 27 // Creates a new instance of SensorReader. At the moment, only polling
26 // reader is supported. 28 // reader is supported.
27 static std::unique_ptr<SensorReader> Create( 29 static std::unique_ptr<SensorReader> Create(
28 const SensorInfoLinux* sensor_device, 30 const SensorInfoLinux* sensor_device,
29 PlatformSensorLinux* sensor, 31 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
30 scoped_refptr<base::SingleThreadTaskRunner> polling_thread_task_runner);
31 32
32 virtual ~SensorReader(); 33 virtual ~SensorReader();
33 34
34 // Starts fetching data based on strategy this reader has chosen. 35 // Starts fetching data based on strategy this reader has chosen.
35 // Only polling strategy is supported at the moment. Thread safe. 36 // Only polling strategy is supported at the moment. Thread safe.
36 virtual bool StartFetchingData( 37 virtual void StartFetchingData(
37 const PlatformSensorConfiguration& configuration) = 0; 38 const PlatformSensorConfiguration& configuration) = 0;
38 39
39 // Stops fetching data. Thread safe. 40 // Stops fetching data. Thread safe.
40 virtual void StopFetchingData() = 0; 41 virtual void StopFetchingData() = 0;
41 42
43 // Sets sensor that this reader reports to. Must be called only once.
44 // Thread safe.
gab 2016/12/14 14:52:21 From the implementation this isn't "thread-safe",
45 void SetPlatformSensorLinux(PlatformSensorLinux* sensor);
46
42 protected: 47 protected:
43 SensorReader(PlatformSensorLinux* sensor, 48 SensorReader(scoped_refptr<base::SingleThreadTaskRunner> task_runner);
44 scoped_refptr<base::SingleThreadTaskRunner> polling_task_runner);
45 49
46 // Notifies |sensor_| about an error. 50 // Notifies |sensor_| about an error.
47 void NotifyReadError(); 51 void NotifyReadError();
48 52
49 // Non-owned pointer to a sensor that created this reader. 53 // Non-owned pointer to a sensor that created this reader.
50 PlatformSensorLinux* sensor_; 54 PlatformSensorLinux* sensor_;
51 55
52 // A task runner that is used to poll data. 56 // A task runner that is used to poll data.
53 scoped_refptr<base::SingleThreadTaskRunner> polling_task_runner_; 57 scoped_refptr<base::SingleThreadTaskRunner> polling_task_runner_;
54 58
55 // A task runner that belongs to a thread this reader is created on. 59 // A task runner that belongs to a thread this reader is created on.
56 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 60 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
57 61
58 // Indicates if reading is active. 62 // Indicates if reading is active.
59 bool is_reading_active_; 63 bool is_reading_active_;
60 64
61 DISALLOW_COPY_AND_ASSIGN(SensorReader); 65 DISALLOW_COPY_AND_ASSIGN(SensorReader);
62 }; 66 };
63 67
64 } // namespace device 68 } // namespace device
65 69
66 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_READER_LINUX_H_ 70 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_READER_LINUX_H_
OLDNEW
« no previous file with comments | « device/generic_sensor/platform_sensor_provider_linux.cc ('k') | device/generic_sensor/platform_sensor_reader_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698