Fix race condition b/w enqueue and dequeue events

Change-Id: I86b7e7424bebb212a6d951e0e2622350137e09b2
diff --git a/fm_hci/fm_hci.cpp b/fm_hci/fm_hci.cpp
index e19f962..18ffc19 100644
--- a/fm_hci/fm_hci.cpp
+++ b/fm_hci/fm_hci.cpp
@@ -101,10 +101,12 @@
     hci.rx_event_queue.push(hdr);
     hci.rx_queue_mtx.unlock();
 
-    if (hci.is_rx_processing == false) {
-        hci.rx_cond.notify_all();
-    }
-
+    ALOGI("%s: putting lock before notify", __func__);
+    hci.rx_cond_mtx.lock();
+    ALOGI("%s:before notify to waiting thred", __func__);
+    hci.rx_cond.notify_all();
+    ALOGI("%s:after notify to waiting thred", __func__);
+    hci.rx_cond_mtx.unlock();
     ALOGI("%s: FM-Event ENQUEUED SUCCESSFULLY", __func__);
 
     return FM_HC_STATUS_SUCCESS;
@@ -132,11 +134,9 @@
         hci.rx_queue_mtx.lock();
         if (hci.rx_event_queue.empty()) {
             ALOGI("No more FM Events are available in the RX Queue");
-            hci.is_rx_processing = false;
             hci.rx_queue_mtx.unlock();
             return;
         } else {
-            hci.is_rx_processing = true;
         }
 
         evt_buf = hci.rx_event_queue.front();
@@ -296,10 +296,13 @@
     ALOGI("%s: ##### starting hci_rx_thread Worker thread!!! #####", __func__);
     hci.is_rx_thread_running = true;
 
+    ALOGI("%s: constr unique_lock ", __func__);
+    Lock lk(hci.rx_cond_mtx);
     while (hci.state != FM_RADIO_DISABLING && hci.state != FM_RADIO_DISABLED) {
         //wait for rx event
-        Lock lk(hci.rx_cond_mtx);
+        ALOGI("%s:before wait", __func__);
         hci.rx_cond.wait(lk);
+        ALOGI("%s:after wait ", __func__);
         dequeue_fm_rx_event();
     }
 
@@ -398,9 +401,7 @@
 static void stop_rx_thread()
 {
     ALOGI("%s:stop_rx_thread ++", __func__);
-    if (hci.is_rx_processing == false) {
-        hci.rx_cond.notify_all();
-    }
+    hci.rx_cond.notify_all();
 
     hci.rx_thread_.join();
     ALOGI("%s:stop_rx_thread --", __func__);
@@ -619,7 +620,6 @@
     hci.cb = hci_hal->cb;
     hci.command_credits = 1;
     hci.is_tx_processing = false;
-    hci.is_rx_processing = false;
     hci.is_tx_thread_running = false;
     hci.is_rx_thread_running = false;
     hci.state = FM_RADIO_DISABLED;