A simple character FIFO I wrote for my Rocket project.

Dependents:   Rocket

Committer:
danjulio
Date:
Sun Jun 11 04:06:39 2017 +0000
Revision:
0:093546398fcd
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
danjulio 0:093546398fcd 1 /*
danjulio 0:093546398fcd 2 * StringFifo: A simple FIFO class for passing strings between threads.
danjulio 0:093546398fcd 3 * Includes a mutex on the load end to allow different threads to
danjulio 0:093546398fcd 4 * push strings. Strings are delimited by null characters, both as they
danjulio 0:093546398fcd 5 * are pushed into the FIFO and as they are stored internally. Execution
danjulio 0:093546398fcd 6 * yields for a pushing thread if there is not room or if another thread
danjulio 0:093546398fcd 7 * is currently pushing data. Execution blocks for a reading thread until
danjulio 0:093546398fcd 8 * there is data to read.
danjulio 0:093546398fcd 9 *
danjulio 0:093546398fcd 10 */
danjulio 0:093546398fcd 11 #ifndef STRING_FIFO_H
danjulio 0:093546398fcd 12 #define STRING_FIFO_H
danjulio 0:093546398fcd 13
danjulio 0:093546398fcd 14 #include "mbed.h"
danjulio 0:093546398fcd 15
danjulio 0:093546398fcd 16 class StringFifo {
danjulio 0:093546398fcd 17 public:
danjulio 0:093546398fcd 18 StringFifo(int size = 1024);
danjulio 0:093546398fcd 19 ~StringFifo();
danjulio 0:093546398fcd 20
danjulio 0:093546398fcd 21 void PushString(char* s);
danjulio 0:093546398fcd 22 inline bool IsEmpty() {return pushI == popI;}
danjulio 0:093546398fcd 23 void PopString(char* s);
danjulio 0:093546398fcd 24
danjulio 0:093546398fcd 25 private:
danjulio 0:093546398fcd 26 // Methods
danjulio 0:093546398fcd 27 int Remaining();
danjulio 0:093546398fcd 28
danjulio 0:093546398fcd 29 // Variables
danjulio 0:093546398fcd 30 char* sP;
danjulio 0:093546398fcd 31 int len;
danjulio 0:093546398fcd 32 int pushI;
danjulio 0:093546398fcd 33 int popI;
danjulio 0:093546398fcd 34 Mutex push_mutex;
danjulio 0:093546398fcd 35 };
danjulio 0:093546398fcd 36
danjulio 0:093546398fcd 37 #endif