diff options
author | Matthew Bouyack <mbouyack@google.com> | 2018-05-21 16:18:10 -0700 |
---|---|---|
committer | Ben Fennema <fennema@google.com> | 2018-06-01 09:30:00 -0700 |
commit | 76b18390990156fa09a204cf51fc67aee3a6886d (patch) | |
tree | 671ab0dd9ad10d8cc15c7da63d5d12356f83f86f /sensorhal | |
parent | 0de12d480ad03ab5f1146f5b20f708d5a7b69d94 (diff) | |
download | contexthub-76b18390990156fa09a204cf51fc67aee3a6886d.tar.gz |
Protect accesses to mFlushesPending.
Previously we weren't taking 'mLock' before accessing mFlushesPending
introducing a possible race condition.
Bug: 79994899
Change-Id: I382e0aa5879b8804718f0c41cf648910d88dee53
Merged-In: I9753d4ffc55c81716a80aefc2e8368f9b727484c
Diffstat (limited to 'sensorhal')
-rw-r--r-- | sensorhal/hubconnection.cpp | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/sensorhal/hubconnection.cpp b/sensorhal/hubconnection.cpp index c283a817..96297036 100644 --- a/sensorhal/hubconnection.cpp +++ b/sensorhal/hubconnection.cpp @@ -1414,25 +1414,33 @@ ssize_t HubConnection::processBuf(uint8_t *buf, size_t len) if (isActivitySensor(sensor) && mActivityEventHandler != NULL) { mActivityEventHandler->OnFlush(); } else { - struct Flush& flush = mFlushesPending[primary].front(); - memset(&ev, 0x00, sizeof(sensors_event_t)); - ev.version = META_DATA_VERSION; - ev.timestamp = 0; - ev.type = SENSOR_TYPE_META_DATA; - ev.sensor = 0; - ev.meta_data.what = META_DATA_FLUSH_COMPLETE; - ev.meta_data.sensor = flush.handle; - - if (flush.internal) { - if (flush.handle == COMMS_SENSOR_ACCEL_WRIST_AWARE) - mLefty.accel = !mLefty.accel; - else if (flush.handle == COMMS_SENSOR_GYRO_WRIST_AWARE) - mLefty.gyro = !mLefty.gyro; - } else - write(&ev, 1); + bool internal = false; + + { + Mutex::Autolock autoLock(mLock); + struct Flush& flush = mFlushesPending[primary].front(); + memset(&ev, 0x00, sizeof(sensors_event_t)); + ev.version = META_DATA_VERSION; + ev.timestamp = 0; + ev.type = SENSOR_TYPE_META_DATA; + ev.sensor = 0; + ev.meta_data.what = META_DATA_FLUSH_COMPLETE; + ev.meta_data.sensor = flush.handle; + + if (flush.internal) { + internal = true; + if (flush.handle == COMMS_SENSOR_ACCEL_WRIST_AWARE) + mLefty.accel = !mLefty.accel; + else if (flush.handle == COMMS_SENSOR_GYRO_WRIST_AWARE) + mLefty.gyro = !mLefty.gyro; + } - if (--flush.count == 0) - mFlushesPending[primary].pop_front(); + if (--flush.count == 0) + mFlushesPending[primary].pop_front(); + } + + if (!internal) + write(&ev, 1); ALOGV("flushing %d", ev.meta_data.sensor); } |