00001 /* -*- mode: c++; c-basic-offset: 4; -*- */ 00002 #ifndef SENDS_SEGMENT_HH 00003 #define SENDS_SEGMENT_HH 00004 00005 #include "chan_list.hh" 00006 #include "gmutex.hh" 00007 #include <string> 00008 00009 namespace sends { 00010 00011 class buffer; 00012 class pool_mgr; 00013 00021 class segment { 00022 public: 00025 typedef unsigned long gps_type; 00026 00029 typedef unsigned long count_type; 00030 00034 typedef chan_list::chan_index chan_index; 00035 public: 00039 segment(void); 00040 00044 ~segment(void); 00045 00054 bool canUse(int bufclass) const; 00055 00061 chan_index chan(void) const; 00062 00068 unsigned long dataIndex(gps_type gps) const; 00069 00075 std::ostream& dump(std::ostream& out) const; 00076 00082 static std::ostream& dump_header(std::ostream& out); 00083 00088 bool empty(void) const; 00089 00096 void extend(const void* data, count_type inx, count_type length); 00097 00105 void fill_lock(void); 00106 00110 void fill_unlock(void); 00111 00116 bool full(void) const; 00117 00124 int getBufClass(void) const; 00125 00130 gps_type getEndGPS(void) const; 00131 00136 gps_type getMaxGPS(void) const; 00137 00142 gps_type getReserveGPS(void) const; 00143 00148 gps_type getStartGPS(void) const; 00149 00157 count_type getUseCount(void) const; 00158 00165 bool in_segment(gps_type gps) const; 00166 00172 bool inUse(void) const; 00173 00181 bool operator<(const segment& seg) const; 00182 00187 double rate(void) const; 00188 00195 const char* refData(gps_type gps) const; 00196 00203 char* refData(gps_type gps); 00204 00208 void release(void); 00209 00216 bool reserve(gps_type start, gps_type stop); 00217 00225 void set_buffer(buffer* bufpt, int btype); 00226 00235 void set_segment(chan_index chan, double rate, int len, gps_type start); 00236 00240 void use(void); 00241 00245 void unuse(void); 00246 private: 00247 thread::mutex mFillMutex; 00248 thread::mutex mUseMutex; 00249 int mBufClass; 00250 chan_index mChannel; 00251 gps_type mStart; 00252 gps_type mStop; 00253 gps_type mReserved; 00254 gps_type mTMax; 00255 double mRate; 00256 int mWordSize; 00257 count_type mUseCount; 00258 buffer* mData; 00259 }; 00260 00261 //================================== Inline methods 00262 inline bool 00263 segment::canUse(int bufclass) const { 00264 return !mUseCount && mBufClass == bufclass; 00265 } 00266 00267 inline segment::chan_index 00268 segment::chan(void) const { 00269 return mChannel; 00270 } 00271 00272 inline bool 00273 segment::empty(void) const { 00274 return mStop == mStart; 00275 } 00276 00277 inline bool 00278 segment::full(void) const { 00279 return mStop == mTMax; 00280 } 00281 00282 inline int 00283 segment::getBufClass(void) const { 00284 return mBufClass; 00285 } 00286 00287 inline segment::gps_type 00288 segment::getEndGPS(void) const { 00289 return mStop; 00290 } 00291 00292 inline segment::gps_type 00293 segment::getMaxGPS(void) const { 00294 return mTMax; 00295 } 00296 00297 inline segment::gps_type 00298 segment::getReserveGPS(void) const { 00299 return mReserved; 00300 } 00301 00302 inline segment::gps_type 00303 segment::getStartGPS(void) const { 00304 return mStart; 00305 } 00306 00307 inline segment::count_type 00308 segment::getUseCount(void) const { 00309 return mUseCount; 00310 } 00311 00312 inline bool 00313 segment::in_segment(gps_type gps) const { 00314 return gps>=mStart && gps<mStop; 00315 } 00316 00317 inline bool 00318 segment::inUse(void) const { 00319 return mUseCount; 00320 } 00321 00322 inline bool 00323 segment::operator<(const segment& seg) const { 00324 return mStop <= seg.mStart; 00325 } 00326 00327 inline double 00328 segment::rate(void) const { 00329 return mRate; 00330 } 00331 00332 } // namespace sends 00333 00334 #endif // !defined(SENDS_SEGMENT_HH)
1.5.5