#ifndef _BUFFER_H_ #define _BUFFER_H_ #define __STDC_FORMAT_MACROS #include #include #include #include #include #include template class DataBuffer { public: DataBuffer( const size_t& size ); ~DataBuffer(); std::vector* getWritePtr() const { return writePtr; }; std::vector* getReadPtr() const { return readPtr; }; size_t size() const { return mySize; }; void doneWriting(); void doneReading(); bool isReadReady() const { return !readDone; }; bool isWriteReady() const { return !writeDone; }; std::condition_variable* getCondVar() { return &condVar; }; std::mutex* getMutex() { return &mut; }; private: size_t mySize; std::vector buf0; std::vector buf1; std::vector* writePtr; std::vector* readPtr; bool writeDone; bool readDone; int writeCnt; int readCnt; std::mutex mut; std::condition_variable condVar; void tryToRotate(); }; #endif