summaryrefslogtreecommitdiff
path: root/6515
diff options
context:
space:
mode:
authorNick Vaccaro <nvaccaro@google.com>2014-10-22 11:01:09 -0700
committerNick Vaccaro <nvaccaro@google.com>2014-10-22 13:36:15 -0700
commitdda0105984d0d83ffbdc3644d7d4735a86b88867 (patch)
treebf912f3ff26c250e130823aaf72fe2c5da2503fa /6515
parente7bd2580e55c618e98fd95619f2e4e44a9d6a332 (diff)
downloadinvensense-dda0105984d0d83ffbdc3644d7d4735a86b88867.tar.gz
Wakelock code should only ever hold wakelock across a single return and re-entry into poll(). Remove unneccesary SMD mutex Change-Id: I9774152f2326137259ceecb85a0430ffdc964124
Diffstat (limited to '6515')
-rwxr-xr-x6515/libsensors_iio/sensors_mpl.cpp23
1 files changed, 7 insertions, 16 deletions
diff --git a/6515/libsensors_iio/sensors_mpl.cpp b/6515/libsensors_iio/sensors_mpl.cpp
index c2a36f4..df0a97f 100755
--- a/6515/libsensors_iio/sensors_mpl.cpp
+++ b/6515/libsensors_iio/sensors_mpl.cpp
@@ -63,7 +63,6 @@ struct simplehead *headp;
static pthread_mutex_t flush_handles_mutex = PTHREAD_MUTEX_INITIALIZER;
static const char *smdWakelockStr = "significant motion";
-static pthread_mutex_t mSMDWakelockMutex = PTHREAD_MUTEX_INITIALIZER;
static struct sensor_t sSensorList[LOCAL_SENSORS];
static int sensors = (sizeof(sSensorList) / sizeof(sensor_t));
@@ -127,7 +126,7 @@ private:
CompassSensor *mCompassSensor;
/* Significant Motion wakelock support */
- unsigned long mSMDEventsPending;
+ bool mSMDWakelockHeld;
};
@@ -141,7 +140,7 @@ sensors_poll_context_t::sensors_poll_context_t() {
MPLSensor *mplSensor = new MPLSensor(mCompassSensor);
/* No significant motion events pending yet */
- mSMDEventsPending = 0;
+ mSMDWakelockHeld = false;
/* For Vendor-defined Accel Calibration File Load
* Use the Following Constructor and Pass Your Load Cal File Function
@@ -208,15 +207,10 @@ int sensors_poll_context_t::pollEvents(sensors_event_t *data, int count)
int nbEvents = 0;
int nb, polltime = -1;
-
- pthread_mutex_lock(&mSMDWakelockMutex);
- if (mSMDEventsPending) {
- mSMDEventsPending--;
- /* If there are no more events pending, release our wakelock */
- if (!mSMDEventsPending)
- release_wake_lock(smdWakelockStr);
+ if (mSMDWakelockHeld) {
+ mSMDWakelockHeld = false;
+ release_wake_lock(smdWakelockStr);
}
- pthread_mutex_unlock(&mSMDWakelockMutex);
struct handle_entry *handle_element;
pthread_mutex_lock(&flush_handles_mutex);
@@ -265,15 +259,12 @@ int sensors_poll_context_t::pollEvents(sensors_event_t *data, int count)
readDmpSignificantMotionEvents(data, count);
mPollFds[i].revents = 0;
if (nb) {
- pthread_mutex_lock(&mSMDWakelockMutex);
- /* if mSMDEventsPending != 0, the wakelock is already held */
- if (!mSMDEventsPending) {
+ if (!mSMDWakelockHeld) {
/* Hold wakelock until Sensor Services reads event */
acquire_wake_lock(PARTIAL_WAKE_LOCK, smdWakelockStr);
LOGI_IF(1, "HAL: grabbed %s wakelock", smdWakelockStr);
+ mSMDWakelockHeld = true;
}
- mSMDEventsPending++;
- pthread_mutex_unlock(&mSMDWakelockMutex);
count -= nb;
nbEvents += nb;