diff options
author | Nick Vaccaro <nvaccaro@google.com> | 2014-10-22 11:01:09 -0700 |
---|---|---|
committer | Nick Vaccaro <nvaccaro@google.com> | 2014-10-22 13:36:15 -0700 |
commit | dda0105984d0d83ffbdc3644d7d4735a86b88867 (patch) | |
tree | bf912f3ff26c250e130823aaf72fe2c5da2503fa | |
parent | e7bd2580e55c618e98fd95619f2e4e44a9d6a332 (diff) | |
download | invensense-dda0105984d0d83ffbdc3644d7d4735a86b88867.tar.gz |
sensors: mpu6515: dont reference count SMD eventsandroid-5.1.1_r7android-5.1.0_r5android-5.1.0_r4android-5.1.0_r3android-5.1.0_r1lollipop-mr1-dev
Wakelock code should only ever hold wakelock across a single
return and re-entry into poll().
Remove unneccesary SMD mutex
Change-Id: I9774152f2326137259ceecb85a0430ffdc964124
-rwxr-xr-x | 6515/libsensors_iio/sensors_mpl.cpp | 23 |
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; |