BT: Changed implementation of ssr_cleanup for enable/disable timeout

Changed the ssr_cleanup method for the enable and disable timeout
cases. Since this can coincide with regular cleanup thread, so
added mutex to make critical section exclusive to avoid race
condition

Change-Id: I3e0af84d429a6e14cb95af2fdb7f7ea4279f94b4
CRs-Fixed: 997490
diff --git a/libbt-vendor/src/bt_vendor_qcom.c b/libbt-vendor/src/bt_vendor_qcom.c
index 09cd32c..1812d6c 100644
--- a/libbt-vendor/src/bt_vendor_qcom.c
+++ b/libbt-vendor/src/bt_vendor_qcom.c
@@ -87,6 +87,8 @@
 int readTrpState();
 void lpm_set_ar3k(uint8_t pio, uint8_t action, uint8_t polarity);
 
+pthread_mutex_t m_lock = PTHREAD_MUTEX_INITIALIZER;
+
 static const tUSERIAL_CFG userial_init_cfg =
 {
     (USERIAL_DATABITS_8 | USERIAL_PARITY_NONE | USERIAL_STOPBITS_1 |USERIAL_CTSRTS),
@@ -709,7 +711,10 @@
                     case BT_SOC_ROME:
                     case BT_SOC_AR3K:
                         /* BT Chipset Power Control through Device Tree Node */
-                        retval = bt_powerup(nState);
+                        if(!pthread_mutex_lock(&m_lock)) {
+                            retval = bt_powerup(nState);
+                            pthread_mutex_unlock(&m_lock);
+                        }
                     default:
                         break;
                 }
@@ -1000,11 +1005,14 @@
         case BT_VND_OP_ANT_USERIAL_CLOSE:
             {
                 ALOGI("bt-vendor : BT_VND_OP_ANT_USERIAL_CLOSE");
-                property_set("wc_transport.clean_up","1");
-                if (ant_fd != -1) {
-                    ALOGE("closing ant_fd");
-                    close(ant_fd);
-                    ant_fd = -1;
+                if(!pthread_mutex_lock(&m_lock)) {
+                    property_set("wc_transport.clean_up","1");
+                    if (ant_fd != -1) {
+                        ALOGE("closing ant_fd");
+                        close(ant_fd);
+                        ant_fd = -1;
+                    }
+                    pthread_mutex_unlock(&m_lock);
                 }
             }
             break;
@@ -1064,8 +1072,11 @@
                     case BT_SOC_ROME:
                     case BT_SOC_AR3K:
                     {
-                        property_set("wc_transport.clean_up","1");
-                        userial_vendor_close();
+                        if(!pthread_mutex_lock(&m_lock)) {
+                            property_set("wc_transport.clean_up","1");
+                            userial_vendor_close();
+                            pthread_mutex_unlock(&m_lock);
+                        }
                         break;
                     }
                     default:
@@ -1261,7 +1272,10 @@
 static void cleanup( void )
 {
     ALOGI("cleanup");
-    bt_vendor_cbacks = NULL;
+    if(!pthread_mutex_lock(&m_lock)) {
+        bt_vendor_cbacks = NULL;
+        pthread_mutex_unlock(&m_lock);
+    }
 
 #ifdef WIFI_BT_STATUS_SYNC
     isInit = 0;