//////////////////////////////////////////////////////////////////////// // class CBuffer // // $Log: buffer.h,v $ // Revision 1.2 1997/07/23 18:27:14 nettleto // Add code to clear buffer so that all variables are // initialized. // // Revision 1.1 1997/06/13 18:10:34 nettleto // Initial revision // // #ifndef BUFFER_H #define BUFFER_H #include "mutex.h" #include "cond.h" #define SIZE 64 // CBuffer is a traditional cyclic buffer with a single mutex for the // input and output sides, and two signal mechanisms, one to indicate the // buffer may contain data, and one to indicate that it may no longer be // full. class CBuffer { protected: // Mutex to protect the attributes CMutex m; // attributes char Buf [SIZE]; int N; // Number of elements in the buffer int Inp, Outp; // Index of next empty/full slot CCond Inc, Outc; // Input and output conds public: CBuffer () { for (int i = 0; i < SIZE; i++) Buf [i] = 0; N = 0; Inp = Outp = 0; } void Put (int c); void Get (int &c); }; #endif // BUFFER_H