libqdutils: Add synchronization to idle invalidator

Protect invalidator data from accessing multiple threads
asynchronously. Composition thread and idle invalidator
threads could access at same time. Add locking to protect
invalidator class  member variables.

Change-Id: I568ec367958c88f70f7aa4e6917abd53830adfd3
diff --git a/libqdutils/idle_invalidator.cpp b/libqdutils/idle_invalidator.cpp
index 4f03968..97176a4 100644
--- a/libqdutils/idle_invalidator.cpp
+++ b/libqdutils/idle_invalidator.cpp
@@ -45,6 +45,7 @@
                           unsigned int idleSleepTime) {
     ALOGD_IF(II_DEBUG, "%s", __func__);
 
+    Locker::Autolock _l(mLock);
     /* store registered handler */
     mHandler = reg_handler;
     mHwcContext = user_data;
@@ -55,6 +56,8 @@
 bool IdleInvalidator::threadLoop() {
     ALOGD_IF(II_DEBUG, "%s", __func__);
     usleep(mSleepTime * 500);
+
+    Locker::Autolock _l(mLock);
     if(mSleepAgain) {
         //We need to sleep again!
         mSleepAgain = false;
@@ -75,6 +78,7 @@
 }
 
 void IdleInvalidator::markForSleep() {
+    Locker::Autolock _l(mLock);
     mSleepAgain = true;
     //Triggers the threadLoop to run, if not already running.
     run(threadName, android::PRIORITY_AUDIO);
diff --git a/libqdutils/idle_invalidator.h b/libqdutils/idle_invalidator.h
index 82b1ac0..abd9b29 100644
--- a/libqdutils/idle_invalidator.h
+++ b/libqdutils/idle_invalidator.h
@@ -32,6 +32,7 @@
 
 #include <cutils/log.h>
 #include <utils/threads.h>
+#include <gr.h>
 
 typedef void (*InvalidatorHandler)(void*);
 
@@ -41,6 +42,7 @@
     unsigned int mSleepTime;
     static InvalidatorHandler mHandler;
     static android::sp<IdleInvalidator> sInstance;
+    mutable Locker mLock;
 
     public:
     IdleInvalidator();