diff options
author | Andrew Rossignol <aarossig@google.com> | 2017-01-31 13:37:11 -0800 |
---|---|---|
committer | Andrew Rossignol <aarossig@google.com> | 2017-01-31 13:38:36 -0800 |
commit | c9878baf251f62f9887a6ec8a735ae5d0a3fc89e (patch) | |
tree | 72aa2611992ae7c83818ef6e3ae6f865cf57754d | |
parent | feed2e1b10e99fc1d2705a9bee1b143b72c42f9e (diff) | |
download | contexthub-c9878baf251f62f9887a6ec8a735ae5d0a3fc89e.tar.gz |
Adds a lock to the flush() method of the AR HAL
Bug: 34801522
Change-Id: I38abc33202719767b5ab18c5a68d4b3cbcbe4877
-rw-r--r-- | sensorhal/activity.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/sensorhal/activity.cpp b/sensorhal/activity.cpp index 6f9fbd16..df7ea042 100644 --- a/sensorhal/activity.cpp +++ b/sensorhal/activity.cpp @@ -329,8 +329,16 @@ int ActivityContext::disableActivityEvent(uint32_t activity_handle, } int ActivityContext::flush() { - mOutstandingFlushEvents += - (COMMS_SENSOR_ACTIVITY_LAST - COMMS_SENSOR_ACTIVITY_FIRST) + 1; + { + // Aquire a lock for the mOutstandingFlushEvents shared state. OnFlush + // modifies this value as flush results are returned. Nested scope is + // used here to control the lifecycle of the lock as OnFlush may be + // invoked before this method returns. + Mutex::Autolock autoLock(mCallbackLock); + + mOutstandingFlushEvents += + (COMMS_SENSOR_ACTIVITY_LAST - COMMS_SENSOR_ACTIVITY_FIRST) + 1; + } // Flush all activity sensors. for (int i = COMMS_SENSOR_ACTIVITY_FIRST; |