buffer.h

00001 #ifndef _SUCS_BUFFER_H
00002 #define _SUCS_BUFFER_H
00003 
00004 #include <iostream>
00005 #include <cassert>
00006 using namespace std;
00007 
00008 #include <qthread.h>
00009 #include <qmutex.h>
00010 #include <qvaluelist.h>
00011 #include <qptrlist.h>
00012 
00013 #ifdef __GEDDEI_BUILD
00014 #include "qfastwaitcondition.h"
00015 #include "bufferdata.h"
00016 #include "signaltype.h"
00017 #else
00018 #include <qtextra/qfastwaitcondition.h>
00019 #include <geddei/bufferdata.h>
00020 #include <geddei/signaltype.h>
00021 #endif
00022 using namespace Geddei;
00023 
00024 namespace Geddei
00025 {
00026 
00027 class BufferReader;
00028 class Processor;
00029 
00034 class Buffer: public ScratchOwner
00035 {
00036  friend class BufferReader;
00037 
00038  mutable QFastWaitCondition theDataIn, theDataOut;
00039  mutable QMutex theDataFlux;
00040 
00041  float *theData;
00042  uint theLogSize, theSize, theMask, theUsed;
00043  uint readPos, writePos;
00044  BufferInfo *lastScratch;
00045  SignalType *theType;
00046  QValueVector<const Processor *> theTrapdoors;
00047  QValueList<uint> thePlungers;
00048  QPtrList<BufferReader> theReaders;
00049 
00050  friend ostream &operator<<(ostream &out, Buffer &me);
00051 
00059  void updateUNSAFE();
00060 
00061  const bool trapdoorUNSAFE() const;
00062  const uint waitForUNSAFE(const uint elements) const;
00063  const uint waitForUNSAFE(const uint elements, const BufferReader *reader) const;
00064  const uint waitForIgnorePlungersUNSAFE(const uint elements, const BufferReader *reader) const;
00065  void waitForFreeUNSAFE(const uint elements) const;
00066 
00071  void discardNextPlungerUNSAFE();
00072 
00079  const int nextPlungerUNSAFE() const;
00080 
00087  const int nextPlungerUNSAFE(const uint pos, const uint ignore) const;
00088 
00089 public:
00090  // USE THIS FROM processor on stop() - dont forget to reinitialise
00091  void openTrapdoor(const Processor *processor);
00092  void closeTrapdoor(const Processor *processor);
00093 
00099  void discardNextPlunger();
00100 
00106  const uint elementsFree() const;
00107 
00117  void waitForFreeElements(const uint elements) const;
00118 
00124  BufferData makeScratchElements(const uint elements, bool autoPush = false);
00125 
00132  void forgetScratch(const BufferData &data);
00133 
00140  void pushScratch(const BufferData &data);
00141 
00147  void pushData(const BufferData &data);
00148 
00155  void push(const BufferData &data);
00156 
00162  void appendPlunger();
00163 
00168  void clear();
00169 
00174  void resize(const uint size);
00175 
00179  void setType(const SignalType *type);
00180 
00184  const uint size() const { return theSize; }
00185 
00189  const SignalType *type() const { return theType; }
00190 
00194  Buffer &operator<<(const BufferData &data) { push(data); return *this; }
00195 
00196  void debug();
00197 
00198  Buffer(const uint size, const SignalType *type = 0);
00199  virtual ~Buffer();
00200 };
00201 
00202 }
00203 
00204 #endif

Generated on Fri Nov 10 21:58:26 2006 for Exscalibar by  doxygen 1.5.1