summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;