Changeset 1671 in Sophya
- Timestamp:
- Oct 6, 2001, 1:46:35 AM (24 years ago)
- Location:
- trunk/ArchTOIPipe/Kernel
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ArchTOIPipe/Kernel/toisegment.cc
r1670 r1671 1 1 #include "toisegment.h" 2 3 4 /******* BufferSegment *********/ 5 TOISegmented::BufferSegment::BufferSegment(int sz) { 6 status = NEW; 7 bufferSize = sz; 8 sn0 = -1; 9 10 refcount = 0; 11 12 data = new double[sz]; 13 flags = new uint_8[sz]; 14 15 pthread_mutex_init(&refcount_mutex, NULL); 16 } 17 18 TOISegmented::BufferSegment::~BufferSegment() { 19 if (refcount > 0) { 20 throw(ForbiddenError("TOISegment : delete Buffer with refcount>0")); 21 } 22 delete[] data; 23 delete[] flags; 24 pthread_mutex_destroy(&refcount_mutex); 25 } 26 27 28 void TOISegmented::BufferSegment::putData(int sn, double d, uint_8 f) { 29 if (status == NEW) { 30 status = WRITE; 31 sn0 = sn; 32 } 33 if (status == COMMITTED) { 34 throw(ForbiddenError("TOISegment : putData in committed buffer")); 35 } 36 checkInRange(sn); 37 data[sn-sn0] = d; 38 flags[sn-sn0] = f; 39 } 40 41 void TOISegmented::BufferSegment::incRefCount() { 42 pthread_mutex_lock(&refcount_mutex); 43 refcount++; 44 pthread_mutex_unlock(&refcount_mutex); 45 } 46 47 void TOISegmented::BufferSegment::decRefCount() { 48 pthread_mutex_lock(&refcount_mutex); 49 int nrc = --refcount; 50 pthread_mutex_unlock(&refcount_mutex); 51 if (nrc<0) 52 throw(ForbiddenError("TOISegment : buffer refcount < 0")); 53 } 54 55 int TOISegmented::BufferSegment::getRefCount() { 56 pthread_mutex_lock(&refcount_mutex); 57 int rc = refcount; 58 pthread_mutex_unlock(&refcount_mutex); 59 return rc; 60 } 61 -
trunk/ArchTOIPipe/Kernel/toisegment.h
r1670 r1671 2 2 #ifndef TOISEGMENT_H 3 3 #define TOISEGMENT_H 4 5 #include <vector> 6 #include <set> 4 7 5 8 #include "toi.h" … … 21 24 22 25 protected: 26 class BufferSegment; 27 class BufferView; 28 class MasterView; 29 30 23 31 class BufferSegment { 24 32 public: … … 26 34 ~BufferSegment(); 27 35 static const int NEW = 0; 28 static const int WRITE = 1; 29 static const int COMMITTED = 2; 36 static const int WRITE = 1; // single-thread write access 37 static const int COMMITTED = 2; // multiple read without lock are ok 30 38 31 39 int getStatus() {return status;} 32 33 40 void incRefCount(); 41 void decRefCount(); 42 int getRefCount(); 43 34 44 void putData(int sn, double data, uint_8 flag); 35 45 inline double getData(int sn); 36 46 inline uint_8 getFlag(int sn); 47 48 bool isPastEnd(int sn) { 49 return sn >= sn+bufferSize; 50 } 37 51 38 52 private: … … 59 73 }; 60 74 61 // Master view, gere le lock ...75 // Master view, gere le lock, et l'ecriture 62 76 class MasterView { 63 77 public: 64 MasterView( );78 MasterView(int bufsz=256, int maxseg=20); 65 79 ~MasterView(); 66 80 81 void putData(int sn, double data, uint_8 flag); 82 void addToWaitList(BufferView* bv); 83 84 BufferView* getView(); // thread-specific 85 67 86 protected: 68 int s0; 87 friend class BufferView; 88 void signalWaitingViews(); 89 void nextSegment(); 90 BufferView* createView(); 91 void updateView(BufferView*); // called on reader thread of the view 92 93 BufferSegment* currentSegment; 94 95 int maxSegments; 96 int bufferSize; 97 int sn0; // First sn in first buffer 98 vector<BufferSegment*> segments; // Committed 69 99 70 100 pthread_mutex_t mutex; // lock for master buffer list access 71 pthread_cond_t condv; // waiting for new buffer 101 pthread_cond_t condv; // waiting (read or write) 102 103 static const int NO_WAIT = 0; 104 static const int WAIT_READ = 1; 105 static const int WAIT_WRITE= 2; 106 int waitStatus; 107 108 set<BufferView*> waitingBuffers; 72 109 }; 73 110 … … 76 113 class BufferView { 77 114 public: 115 BufferView(); 116 ~BufferView(); 78 117 79 void sync(); 118 void sync(); // recupere les nouveaux segments, resync avec master 119 void wait(); // Passe en attente d'un nouveau segment 80 120 protected: 81 MasterView master; 121 friend class MasterView; 122 MasterView* master; 123 vector<BufferSegment*> segments; // Committed 124 pthread_mutex_t mutex; // lock pour attente de segments 125 pthread_cond_t condv; // attente de segments 82 126 }; 127 128 129 83 130 }; 84 131
Note:
See TracChangeset
for help on using the changeset viewer.