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

Side by Side Diff: device/generic_sensor/platform_sensor_provider_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_PUBLIC_PLATFORM_SENSOR_PROVIDER_LINUX_H_ 5 #ifndef DEVICE_GENERIC_SENSOR_PUBLIC_PLATFORM_SENSOR_PROVIDER_LINUX_H_
6 #define DEVICE_GENERIC_SENSOR_PUBLIC_PLATFORM_SENSOR_PROVIDER_LINUX_H_ 6 #define DEVICE_GENERIC_SENSOR_PUBLIC_PLATFORM_SENSOR_PROVIDER_LINUX_H_
7 7
8 #include "device/generic_sensor/platform_sensor_provider.h" 8 #include "device/generic_sensor/platform_sensor_provider.h"
9 9
10 #include "device/generic_sensor/linux/sensor_device_manager.h" 10 #include "device/generic_sensor/linux/sensor_device_manager.h"
11 11
12 namespace base { 12 namespace base {
13 template <typename T> 13 template <typename T>
14 struct DefaultSingletonTraits; 14 struct DefaultSingletonTraits;
15 class Thread; 15 class Thread;
16 } 16 }
17 17
18 namespace device { 18 namespace device {
19 19
20 class SensorReader;
20 struct SensorInfoLinux; 21 struct SensorInfoLinux;
21 22
22 class DEVICE_GENERIC_SENSOR_EXPORT PlatformSensorProviderLinux 23 class DEVICE_GENERIC_SENSOR_EXPORT PlatformSensorProviderLinux
23 : public PlatformSensorProvider, 24 : public PlatformSensorProvider,
24 public SensorDeviceManager::Delegate { 25 public SensorDeviceManager::Delegate {
25 public: 26 public:
26 static PlatformSensorProviderLinux* GetInstance(); 27 static PlatformSensorProviderLinux* GetInstance();
27 28
28 // Sets another service provided by tests. 29 // Sets another service provided by tests.
29 void SetSensorDeviceManagerForTesting( 30 void SetSensorDeviceManagerForTesting(
(...skipping 16 matching lines...) Expand all
46 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) override; 47 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) override;
47 48
48 private: 49 private:
49 friend struct base::DefaultSingletonTraits<PlatformSensorProviderLinux>; 50 friend struct base::DefaultSingletonTraits<PlatformSensorProviderLinux>;
50 51
51 using SensorDeviceMap = 52 using SensorDeviceMap =
52 std::unordered_map<mojom::SensorType, std::unique_ptr<SensorInfoLinux>>; 53 std::unordered_map<mojom::SensorType, std::unique_ptr<SensorInfoLinux>>;
53 54
54 PlatformSensorProviderLinux(); 55 PlatformSensorProviderLinux();
55 56
56 void SensorDeviceFound( 57 // Creates a platform sensor using a sensor reader created on a different
58 // thread.
Reilly Grant (use Gerrit) 2016/12/14 18:56:08 *created on |polling_thread_|.
maksims (do not use this acc) 2016/12/16 08:39:22 comment removed
59 void SensorReaderCreated(
57 mojom::SensorType type, 60 mojom::SensorType type,
58 mojo::ScopedSharedBufferMapping mapping, 61 mojo::ScopedSharedBufferMapping mapping,
59 const PlatformSensorProviderBase::CreateSensorCallback& callback, 62 const PlatformSensorProviderBase::CreateSensorCallback& callback,
60 SensorInfoLinux* sensor_device); 63 SensorInfoLinux* const sensor_device,
Reilly Grant (use Gerrit) 2016/12/14 18:56:08 You mean const SensorInfoLinux*.
maksims (do not use this acc) 2016/12/16 08:39:22 Done.
64 std::unique_ptr<SensorReader> sensor_reader);
61 65
62 bool StartPollingThread(); 66 bool StartPollingThread();
63 67
64 // Stops a polling thread if there are no sensors left. Must be called on 68 // Stops a polling thread if there are no sensors left. Must be called on
65 // a different than the polling thread which allows I/O. 69 // a different than the polling thread which allows I/O.
66 void StopPollingThread(); 70 void StopPollingThread();
67 71
68 // Shuts down a service that tracks events from iio subsystem. 72 // Shuts down a service that tracks events from iio subsystem.
69 void Shutdown(); 73 void Shutdown();
70 74
71 // Returns SensorInfoLinux structure of a requested type. 75 // Returns SensorInfoLinux structure of a requested type.
72 // If a request cannot be processed immediately, returns nullptr and 76 // If a request cannot be processed immediately, returns nullptr and
73 // all the requests stored in |requests_map_| are processed after 77 // all the requests stored in |requests_map_| are processed after
74 // enumeration is ready. 78 // enumeration is ready.
75 SensorInfoLinux* GetSensorDevice(mojom::SensorType type); 79 SensorInfoLinux* GetSensorDevice(mojom::SensorType type);
76 80
77 // Returns all found iio devices. Currently not implemented. 81 // Returns all found iio devices. Currently not implemented.
78 void GetAllSensorDevices(); 82 void GetAllSensorDevices();
79 83
80 // Processed stored requests in |request_map_|. 84 // Processed stored requests in |request_map_|.
81 void ProcessStoredRequests(); 85 void ProcessStoredRequests();
82 86
83 // Called when sensors are created asynchronously after enumeration is done.
84 void CreateSensorAndNotify(mojom::SensorType type,
85 SensorInfoLinux* sensor_device);
86
87 // SensorDeviceManager::Delegate implements: 87 // SensorDeviceManager::Delegate implements:
88 void OnSensorNodesEnumerated() override; 88 void OnSensorNodesEnumerated() override;
89 void OnDeviceAdded(mojom::SensorType type, 89 void OnDeviceAdded(mojom::SensorType type,
90 std::unique_ptr<SensorInfoLinux> sensor_device) override; 90 std::unique_ptr<SensorInfoLinux> sensor_device) override;
91 void OnDeviceRemoved(mojom::SensorType type, 91 void OnDeviceRemoved(mojom::SensorType type,
92 const std::string& device_node) override; 92 const std::string& device_node) override;
93 93
94 // Set to true when enumeration is ready. 94 // Set to true when enumeration is ready.
95 bool sensor_nodes_enumerated_; 95 bool sensor_nodes_enumerated_;
96 96
(...skipping 14 matching lines...) Expand all
111 // provider to stop a polling thread and passed to a manager that 111 // provider to stop a polling thread and passed to a manager that
112 // runs a linux device monitor service on this task runner. 112 // runs a linux device monitor service on this task runner.
113 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; 113 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
114 114
115 DISALLOW_COPY_AND_ASSIGN(PlatformSensorProviderLinux); 115 DISALLOW_COPY_AND_ASSIGN(PlatformSensorProviderLinux);
116 }; 116 };
117 117
118 } // namespace device 118 } // namespace device
119 119
120 #endif // DEVICE_GENERIC_SENSOR_PUBLIC_PLATFORM_SENSOR_PROVIDER_LINUX_H_ 120 #endif // DEVICE_GENERIC_SENSOR_PUBLIC_PLATFORM_SENSOR_PROVIDER_LINUX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698