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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: device/generic_sensor/platform_sensor_reader_linux.h
diff --git a/device/generic_sensor/platform_sensor_reader_linux.h b/device/generic_sensor/platform_sensor_reader_linux.h
index 755ad2671af5f80937cd470d8f3ac8851d64f733..23a978c6fdc7f8fb714c5f9b26aa7e657f7e47aa 100644
--- a/device/generic_sensor/platform_sensor_reader_linux.h
+++ b/device/generic_sensor/platform_sensor_reader_linux.h
@@ -19,29 +19,32 @@ class PlatformSensorConfiguration;
struct SensorInfoLinux;
// A generic reader class that can be implemented with two different strategies:
-// polling and on trigger.
+// polling and on trigger. All methods are not thread-safe.
class SensorReader {
public:
// Creates a new instance of SensorReader. At the moment, only polling
// reader is supported.
static std::unique_ptr<SensorReader> Create(
const SensorInfoLinux* sensor_device,
- PlatformSensorLinux* sensor,
- scoped_refptr<base::SingleThreadTaskRunner> polling_thread_task_runner);
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner);
virtual ~SensorReader();
// Starts fetching data based on strategy this reader has chosen.
- // Only polling strategy is supported at the moment. Thread safe.
- virtual bool StartFetchingData(
+ // Only polling strategy is supported at the moment.
+ virtual void StartFetchingData(
const PlatformSensorConfiguration& configuration) = 0;
- // Stops fetching data. Thread safe.
+ // Stops fetching data.
virtual void StopFetchingData() = 0;
+ // Sets sensor that this reader reports to. Must Must be called after the
+ // SensorReader is constructed, before tasks are posted to it from another
+ // sequence.
+ void SetPlatformSensorLinux(PlatformSensorLinux* sensor);
+
protected:
- SensorReader(PlatformSensorLinux* sensor,
- scoped_refptr<base::SingleThreadTaskRunner> polling_task_runner);
+ SensorReader(scoped_refptr<base::SingleThreadTaskRunner> task_runner);
// Notifies |sensor_| about an error.
void NotifyReadError();
@@ -49,10 +52,10 @@ class SensorReader {
// Non-owned pointer to a sensor that created this reader.
PlatformSensorLinux* sensor_;
- // A task runner that is used to poll data.
+ // A task runner that belongs to a thread this reader is created on.
scoped_refptr<base::SingleThreadTaskRunner> polling_task_runner_;
- // A task runner that belongs to a thread this reader is created on.
+ // A task runner that is used to report reading updates and errors
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
// Indicates if reading is active.

Powered by Google App Engine
This is Rietveld 408576698