char queue for WiFi communication

Revision:
2:8f54ba4d961f
Parent:
1:f9e6627f1f59
--- a/objectQueue.cpp	Wed Aug 09 01:12:08 2017 +0000
+++ b/objectQueue.cpp	Wed Aug 23 02:10:23 2017 +0000
@@ -2,6 +2,7 @@
 
 StrQueue::StrQueue() {
     chars = (char*)malloc(sizeof(char[1]));
+    lock = new Mutex();
     size = 1;
     front = 0;
     back = 0;
@@ -23,7 +24,7 @@
 }
 
 int StrQueue::put(const char* message, int length) {
-    lock.lock();
+    lock->lock();
     int i;
     if (length == 0) {
         for (i = 0; empty||(front != (back+i)%size); i++) {
@@ -33,19 +34,19 @@
                 if (front == back) {
                     full = true;   
                 }
-                lock.unlock();
+                lock->unlock();
                 return(i);
             }
         }
         if (front == back) {
             full = true;   
         }
-        lock.unlock();
+        lock->unlock();
         return(0);
     }
     else {
         if ((back - front)%size <= length) {
-            lock.unlock();
+            lock->unlock();
             return(0);
         }
         for (i = 0; empty||(i <= length); i++) {
@@ -56,16 +57,16 @@
         if (front == back) {
             full = true;   
         }
-        lock.unlock();
+        lock->unlock();
         return(i);
     }
 }
 
 int StrQueue::get(char* out, int length) {
-    lock.lock();
+    lock->lock();
     int i = 0;
     if (empty) {
-        lock.unlock();
+        lock->unlock();
         return(0);   
     }
     for (i = 0;; i++) {
@@ -81,21 +82,21 @@
     if (front == back) {
         empty = true;
     }
-    lock.unlock();
+    lock->unlock();
     
     return(i);
 }
  
 int StrQueue::getChars(char* buffer, int size) {
     int ret = 0, total = 0;
-    lock.lock();
+    lock->lock();
     if (empty) {return(0);}
     while ((ret = get(buffer + ret, size - total)) > 0) {
         buffer += ret;
         total++;
         ret = 0;
     }
-    lock.unlock();
+    lock->unlock();
     return(total);
 }