char queue for WiFi communication

Files at this revision

API Documentation at this revision

Comitter:
williampeers
Date:
Wed Aug 23 02:10:23 2017 +0000
Parent:
1:f9e6627f1f59
Commit message:

Changed in this revision

objectQueue.cpp Show annotated file Show diff for this revision Revisions of this file
objectQueue.h Show annotated file Show diff for this revision Revisions of this file
diff -r f9e6627f1f59 -r 8f54ba4d961f objectQueue.cpp
--- 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);
 }
 
diff -r f9e6627f1f59 -r 8f54ba4d961f objectQueue.h
--- a/objectQueue.h	Wed Aug 09 01:12:08 2017 +0000
+++ b/objectQueue.h	Wed Aug 23 02:10:23 2017 +0000
@@ -16,7 +16,7 @@
     bool isEmpty();
     
 private:
-    Mutex lock;
+    Mutex* lock;
     bool empty, full;
     int front, back;
     int size;